Updates to control using coroutines

This commit is contained in:
Alexander Nozik 2018-03-30 09:52:38 +03:00
parent f2d292b853
commit 30f1805513
7 changed files with 33 additions and 33 deletions

View File

@ -123,7 +123,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
logger.info("Setting dynamic range to " + it.intValue())
val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' }
if (response.contains("=")) {
updateLogicalState(PGA, Integer.parseInt(response.substring(4)))
updateState(PGA, Integer.parseInt(response.substring(4)))
} else {
logger.error("Setting pga failed with message: $response")
}
@ -166,7 +166,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
}
if (response.contains("=")) {
updateLogicalState(ABUF, Integer.parseInt(response.substring(14)))
updateState(ABUF, Integer.parseInt(response.substring(14)))
// getLogger().info("successfully set buffer size to {}", this.abuf);
} else {
logger.error("Setting averaging buffer failed with message: $response")
@ -230,13 +230,13 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
}
private fun notifyChannelResult(designation: String, rawValue: Double) {
updateLogicalState("raw.$designation", rawValue)
updateState("raw.$designation", rawValue)
val channel = channels[designation]
val temperature = channel?.let {
val temp = it.getTemperature(rawValue)
updateLogicalState("temp.$designation", temp)
updateState("temp.$designation", temp)
collector.put(it.name, temp)
temp
}
@ -305,7 +305,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
}
if (response.contains("=")) {
updateLogicalState(SPS, Integer.parseInt(response.substring(4)))
updateState(SPS, Integer.parseInt(response.substring(4)))
} else {
logger.error("Setting sps failed with message: $response")
}

View File

@ -163,7 +163,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
// val out: Boolean = "ON" == talk("OUT?")
//
// val measuredCurrent = s2d(getParameter("MC"))
// updateLogicalState("current", measuredCurrent)
// updateState("current", measuredCurrent)
// val setCurrent = s2d(getParameter("PC"))
// val measuredVoltage = s2d(getParameter("MV"))
// val setVoltage = s2d(getParameter("PV"))
@ -216,11 +216,11 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
private fun update(key: String, value: String) {
when (key) {
"OUT" -> updateLogicalState("output", value == "ON")
"MC" -> updateLogicalState("current", s2d(value))
"PC" -> updateLogicalState("targetCurrent", s2d(value))
"MV" -> updateLogicalState("voltage", s2d(value))
"PV" -> updateLogicalState("targetVoltage", s2d(value))
"OUT" -> updateState("output", value == "ON")
"MC" -> updateState("current", s2d(value))
"PC" -> updateState("targetCurrent", s2d(value))
"MV" -> updateState("voltage", s2d(value))
"PV" -> updateState("targetVoltage", s2d(value))
}
}
@ -287,7 +287,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
updateTask = scheduler.scheduleWithFixedDelay(call, 0, delay.toLong(), TimeUnit.MILLISECONDS)
listener?.updateTaskStateChanged(getName(), true)
updateLogicalState("updating", Value.of(true))
updateState("updating", Value.of(true))
}
@Throws(PortException::class)
@ -339,7 +339,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
listener?.monitorTaskStateChanged(getName(), false)
monitorTask = null
}
updateLogicalState("output", Value.of(false))
updateState("output", Value.of(false))
}
override fun getName(): String {

View File

@ -91,8 +91,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
it.weakOnPhrase({ it.startsWith("FilamentStatus") }, this) {
val response = MspResponse(it)
val status = response[0, 2]
updateLogicalState("filamentOn", status == "ON")
updateLogicalState("filamentStatus", status)
updateState("filamentOn", status == "ON")
updateState("filamentStatus", status)
}
logger.info("Connected to MKS mass-spectrometer on {}", it.port)
}
@ -153,7 +153,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
response = commandAndWait("Select", sensorName)
if (response.isOK) {
updateLogicalState("selected", true)
updateState("selected", true)
} else {
notifyError(response.errorDescription, null)
return false
@ -162,13 +162,13 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
response = commandAndWait("Control", "inr.numass.msp", "1.1")
if (response.isOK) {
updateLogicalState("controlled", true)
updateState("controlled", true)
} else {
notifyError(response.errorDescription, null)
return false
}
// connected = true;
updateLogicalState(PortSensor.CONNECTED_STATE, true)
updateState(PortSensor.CONNECTED_STATE, true)
return true
} else {
return !commandAndWait("Release").isOK
@ -224,7 +224,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
private fun selectFilament(filament: Int) {
val response = commandAndWait("FilamentSelect", filament)
if (response.isOK) {
updateLogicalState("filament", response[1, 1])
updateState("filament", response[1, 1])
} else {
logger.error("Failed to set filament with error: {}", response.errorDescription)
}
@ -366,7 +366,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
forEachConnection(Roles.VIEW_ROLE, NamedValueListener::class.java) { listener -> listener.pushValue(massName, value) }
}
"ZeroReading" -> {
updateLogicalState("peakJump.zero", java.lang.Double.parseDouble(response[0, 2]) / 100.0)
updateState("peakJump.zero", java.lang.Double.parseDouble(response[0, 2]) / 100.0)
}
"StartingScan" -> {
val numScans = Integer.parseInt(response[0, 3])

View File

@ -42,16 +42,16 @@ class CM32Device(context: Context, meta: Meta) : PortSensor(context, meta) {
val answer = sendAndWait("MES R PM 1\r\n")
return if (answer.isEmpty()) {
updateLogicalState(PortSensor.CONNECTED_STATE, false)
updateState(PortSensor.CONNECTED_STATE, false)
produceError("No signal")
} else if (!answer.contains("PM1:mbar")) {
updateLogicalState(PortSensor.CONNECTED_STATE, false)
updateState(PortSensor.CONNECTED_STATE, false)
produceError("Wrong answer: $answer")
} else if (answer.substring(14, 17) == "OFF") {
updateLogicalState(PortSensor.CONNECTED_STATE, true)
updateState(PortSensor.CONNECTED_STATE, true)
produceError("Off")
} else {
updateLogicalState(PortSensor.CONNECTED_STATE, true)
updateState(PortSensor.CONNECTED_STATE, true)
produceResult(answer.substring(14, 17) + answer.substring(19, 23))
}
}

View File

@ -47,10 +47,10 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(context, meta
val answer = sendAndWait("AV$channel\r")
if (answer.isEmpty()) {
// invalidateState("connection");
updateLogicalState(PortSensor.CONNECTED_STATE, false)
updateState(PortSensor.CONNECTED_STATE, false)
return produceError("No connection")
} else {
updateLogicalState(PortSensor.CONNECTED_STATE, true)
updateState(PortSensor.CONNECTED_STATE, true)
}
val res = java.lang.Double.parseDouble(answer)
return if (res <= 0) {

View File

@ -93,14 +93,14 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
// }
val ans = talk("FP!ON")
if (ans == "ON") {
updateLogicalState("power", true)
updateState("power", true)
} else {
this.notifyError("Failed to set power state")
}
} else {
val ans = talk("FP!OFF")
if (ans == "OFF") {
updateLogicalState("power", false)
updateState("power", false)
} else {
this.notifyError("Failed to set power state")
}
@ -121,12 +121,12 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
val channel = meta.getInt("channel", 5)
val answer = talk("PR$channel?")
if (answer == null || answer.isEmpty()) {
updateLogicalState(PortSensor.CONNECTED_STATE, false)
updateState(PortSensor.CONNECTED_STATE, false)
return produceError("No connection")
}
val res = parseDouble(answer)
return if (res <= 0) {
updateLogicalState("power", false)
updateState("power", false)
produceError("No power")
} else {
this.updateMessage("OK")

View File

@ -55,7 +55,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(context, meta)
val answer = sendAndWait(query) { phrase -> phrase.startsWith(requestBase) }
if (answer.isEmpty()) {
updateLogicalState(PortSensor.CONNECTED_STATE, false)
updateState(PortSensor.CONNECTED_STATE, false)
return produceError("No signal")
} else {
val match = response.matcher(answer)
@ -68,10 +68,10 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(context, meta)
}
var res = BigDecimal.valueOf(base * Math.pow(10.0, exp.toDouble()))
res = res.setScale(4, RoundingMode.CEILING)
updateLogicalState(PortSensor.CONNECTED_STATE, true)
updateState(PortSensor.CONNECTED_STATE, true)
produceResult(res)
} else {
updateLogicalState(PortSensor.CONNECTED_STATE, false)
updateState(PortSensor.CONNECTED_STATE, false)
produceError("Wrong answer: $answer")
}
}