Updates on numass msp
This commit is contained in:
parent
e99fe84053
commit
d032c48ef4
@ -233,7 +233,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
|
|||||||
private fun startUpdateTask(delay: Long = DEFAULT_DELAY.toLong()) {
|
private fun startUpdateTask(delay: Long = DEFAULT_DELAY.toLong()) {
|
||||||
assert(delay > 0)
|
assert(delay > 0)
|
||||||
stopUpdateTask()
|
stopUpdateTask()
|
||||||
updateTask = repeat(Duration.ofMillis(delay)) {
|
updateTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
|
||||||
try {
|
try {
|
||||||
val measuredI = current.readBlocking().doubleValue()
|
val measuredI = current.readBlocking().doubleValue()
|
||||||
val targetI = target.doubleValue
|
val targetI = target.doubleValue
|
||||||
@ -295,7 +295,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A
|
|||||||
assert(delay >= 1000)
|
assert(delay >= 1000)
|
||||||
stopMonitorTask()
|
stopMonitorTask()
|
||||||
|
|
||||||
monitorTask = repeat(Duration.ofMillis(delay)) {
|
monitorTask = repeatOnDeviceThread(Duration.ofMillis(delay)) {
|
||||||
try {
|
try {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
voltage.read()
|
voltage.read()
|
||||||
|
@ -66,20 +66,19 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
|
|
||||||
//val selected: Boolean by valueState("selected").booleanDelegate
|
//val selected: Boolean by valueState("selected").booleanDelegate
|
||||||
|
|
||||||
var controlled = valueState(CONTROLLED_STATE) { _, value ->
|
val controlled = valueState(CONTROLLED_STATE) { value ->
|
||||||
control(value.booleanValue())
|
runOnDeviceThread {
|
||||||
|
val res = control(value.booleanValue())
|
||||||
|
updateState(CONTROLLED_STATE, res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var filament by valueState("filament") { old, value ->
|
val filament = valueState("filament") { value ->
|
||||||
if (old != value) {
|
selectFilament(value.intValue())
|
||||||
selectFilament(value.intValue())
|
}
|
||||||
}
|
|
||||||
}.intDelegate
|
|
||||||
|
|
||||||
var filamentOn = valueState("filamentOn") { old, value ->
|
val filamentOn = valueState("filamentOn") { value ->
|
||||||
if (old != value) {
|
setFilamentOn(value.booleanValue())
|
||||||
setFilamentOn(value.booleanValue())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
|
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
|
||||||
@ -130,46 +129,44 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
* @throws hep.dataforge.exceptions.ControlException
|
* @throws hep.dataforge.exceptions.ControlException
|
||||||
*/
|
*/
|
||||||
private fun control(on: Boolean): Boolean {
|
private fun control(on: Boolean): Boolean {
|
||||||
synchronized(this) {
|
logger.info("Starting initialization sequence")
|
||||||
logger.info("Starting initialization sequence")
|
if (on != this.controlled.booleanValue) {
|
||||||
if (on != this.controlled.booleanValue) {
|
val sensorName: String
|
||||||
val sensorName: String
|
if (on) {
|
||||||
if (on) {
|
//ensure device is connected
|
||||||
//ensure device is connected
|
connected.setAndWait(true)
|
||||||
connected.setAndWait(true)
|
var response = commandAndWait("Sensors")
|
||||||
var response = commandAndWait("Sensors")
|
if (response.isOK) {
|
||||||
if (response.isOK) {
|
sensorName = response[2, 1]
|
||||||
sensorName = response[2, 1]
|
|
||||||
} else {
|
|
||||||
notifyError(response.errorDescription, null)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
//PENDING определеить в конфиге номер прибора
|
|
||||||
|
|
||||||
response = commandAndWait("Select", sensorName)
|
|
||||||
if (response.isOK) {
|
|
||||||
updateState("selected", true)
|
|
||||||
} else {
|
|
||||||
notifyError(response.errorDescription, null)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
response = commandAndWait("Control", "inr.numass.msp", "1.1")
|
|
||||||
if (response.isOK) {
|
|
||||||
controlled.update(true)
|
|
||||||
} else {
|
|
||||||
notifyError(response.errorDescription, null)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// connected = true;
|
|
||||||
updateState(PortSensor.CONNECTED_STATE, true)
|
|
||||||
return true
|
|
||||||
} else {
|
} else {
|
||||||
return !commandAndWait("Release").isOK
|
notifyError(response.errorDescription, null)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
//PENDING определеить в конфиге номер прибора
|
||||||
|
|
||||||
|
response = commandAndWait("Select", sensorName)
|
||||||
|
if (response.isOK) {
|
||||||
|
updateState("selected", true)
|
||||||
|
} else {
|
||||||
|
notifyError(response.errorDescription, null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
response = commandAndWait("Control", "inr.numass.msp", "1.1")
|
||||||
|
if (response.isOK) {
|
||||||
|
controlled.update(true)
|
||||||
|
} else {
|
||||||
|
notifyError(response.errorDescription, null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// connected = true;
|
||||||
|
updateState(PortSensor.CONNECTED_STATE, true)
|
||||||
|
return true
|
||||||
} else {
|
} else {
|
||||||
return on
|
return !commandAndWait("Release").isOK
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,11 +222,13 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
|
|
||||||
@Throws(PortException::class)
|
@Throws(PortException::class)
|
||||||
private fun selectFilament(filament: Int) {
|
private fun selectFilament(filament: Int) {
|
||||||
val response = commandAndWait("FilamentSelect", filament)
|
runOnDeviceThread {
|
||||||
if (response.isOK) {
|
val response = commandAndWait("FilamentSelect", filament)
|
||||||
updateState("filament", response[1, 1])
|
if (response.isOK) {
|
||||||
} else {
|
this.filament.update(response[1, 1])
|
||||||
logger.error("Failed to set filament with error: {}", response.errorDescription)
|
} else {
|
||||||
|
logger.error("Failed to set filament with error: {}", response.errorDescription)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +298,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
|
|
||||||
override fun stopMeasurement() {
|
override fun stopMeasurement() {
|
||||||
super.stopMeasurement()
|
super.stopMeasurement()
|
||||||
execute {
|
runOnDeviceThread {
|
||||||
stopPeakJump()
|
stopPeakJump()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +308,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
stopMeasurement()
|
stopMeasurement()
|
||||||
}
|
}
|
||||||
if (newMeta.getString("type", "peakJump") == "peakJump") {
|
if (newMeta.getString("type", "peakJump") == "peakJump") {
|
||||||
execute {
|
runOnDeviceThread {
|
||||||
startPeakJump(newMeta)
|
startPeakJump(newMeta)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +117,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
|
|||||||
addListener { _, oldValue, newValue ->
|
addListener { _, oldValue, newValue ->
|
||||||
if (newValue != oldValue) {
|
if (newValue != oldValue) {
|
||||||
runAsync {
|
runAsync {
|
||||||
device.filament = newValue
|
device.filament.set(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user