Updates on numass msp

This commit is contained in:
Alexander Nozik 2018-04-12 13:33:54 +03:00
parent e99fe84053
commit d032c48ef4
3 changed files with 56 additions and 57 deletions

View File

@ -233,7 +233,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
private fun startUpdateTask(delay: Long = DEFAULT_DELAY.toLong()) {
assert(delay > 0)
stopUpdateTask()
updateTask = repeat(Duration.ofMillis(delay)) {
updateTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
try {
val measuredI = current.readBlocking().doubleValue()
val targetI = target.doubleValue
@ -295,7 +295,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
assert(delay >= 1000)
stopMonitorTask()
monitorTask = repeat(Duration.ofMillis(delay)) {
monitorTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
try {
runBlocking {
voltage.read()

View File

@ -66,21 +66,20 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
//val selected: Boolean by valueState("selected").booleanDelegate
var controlled = valueState(CONTROLLED_STATE) { _, value ->
control(value.booleanValue())
val controlled = valueState(CONTROLLED_STATE) { value ->
runOnDeviceThread {
val res = control(value.booleanValue())
updateState(CONTROLLED_STATE, res)
}
}
var filament by valueState("filament") { old, value ->
if (old != value) {
val filament = valueState("filament") { value ->
selectFilament(value.intValue())
}
}.intDelegate
var filamentOn = valueState("filamentOn") { old, value ->
if (old != value) {
val filamentOn = valueState("filamentOn") { value ->
setFilamentOn(value.booleanValue())
}
}
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
@ -130,7 +129,6 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
* @throws hep.dataforge.exceptions.ControlException
*/
private fun control(on: Boolean): Boolean {
synchronized(this) {
logger.info("Starting initialization sequence")
if (on != this.controlled.booleanValue) {
val sensorName: String
@ -171,7 +169,6 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
return on
}
}
}
/**
* Send request to the msp
@ -225,13 +222,15 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
@Throws(PortException::class)
private fun selectFilament(filament: Int) {
runOnDeviceThread {
val response = commandAndWait("FilamentSelect", filament)
if (response.isOK) {
updateState("filament", response[1, 1])
this.filament.update(response[1, 1])
} else {
logger.error("Failed to set filament with error: {}", response.errorDescription)
}
}
}
/**
* Turn filament on or off
@ -299,7 +298,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
override fun stopMeasurement() {
super.stopMeasurement()
execute {
runOnDeviceThread {
stopPeakJump()
}
}
@ -309,7 +308,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
stopMeasurement()
}
if (newMeta.getString("type", "peakJump") == "peakJump") {
execute {
runOnDeviceThread {
startPeakJump(newMeta)
}
} else {

View File

@ -117,7 +117,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
addListener { _, oldValue, newValue ->
if (newValue != oldValue) {
runAsync {
device.filament = newValue
device.filament.set(newValue)
}
}
}