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()) logger.info("Setting dynamic range to " + it.intValue())
val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' } val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' }
if (response.contains("=")) { if (response.contains("=")) {
updateLogicalState(PGA, Integer.parseInt(response.substring(4))) updateState(PGA, Integer.parseInt(response.substring(4)))
} else { } else {
logger.error("Setting pga failed with message: $response") logger.error("Setting pga failed with message: $response")
} }
@ -166,7 +166,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
} }
if (response.contains("=")) { 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); // getLogger().info("successfully set buffer size to {}", this.abuf);
} else { } else {
logger.error("Setting averaging buffer failed with message: $response") 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) { private fun notifyChannelResult(designation: String, rawValue: Double) {
updateLogicalState("raw.$designation", rawValue) updateState("raw.$designation", rawValue)
val channel = channels[designation] val channel = channels[designation]
val temperature = channel?.let { val temperature = channel?.let {
val temp = it.getTemperature(rawValue) val temp = it.getTemperature(rawValue)
updateLogicalState("temp.$designation", temp) updateState("temp.$designation", temp)
collector.put(it.name, temp) collector.put(it.name, temp)
temp temp
} }
@ -305,7 +305,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
} }
if (response.contains("=")) { if (response.contains("=")) {
updateLogicalState(SPS, Integer.parseInt(response.substring(4))) updateState(SPS, Integer.parseInt(response.substring(4)))
} else { } else {
logger.error("Setting sps failed with message: $response") 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 out: Boolean = "ON" == talk("OUT?")
// //
// val measuredCurrent = s2d(getParameter("MC")) // val measuredCurrent = s2d(getParameter("MC"))
// updateLogicalState("current", measuredCurrent) // updateState("current", measuredCurrent)
// val setCurrent = s2d(getParameter("PC")) // val setCurrent = s2d(getParameter("PC"))
// val measuredVoltage = s2d(getParameter("MV")) // val measuredVoltage = s2d(getParameter("MV"))
// val setVoltage = s2d(getParameter("PV")) // 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) { private fun update(key: String, value: String) {
when (key) { when (key) {
"OUT" -> updateLogicalState("output", value == "ON") "OUT" -> updateState("output", value == "ON")
"MC" -> updateLogicalState("current", s2d(value)) "MC" -> updateState("current", s2d(value))
"PC" -> updateLogicalState("targetCurrent", s2d(value)) "PC" -> updateState("targetCurrent", s2d(value))
"MV" -> updateLogicalState("voltage", s2d(value)) "MV" -> updateState("voltage", s2d(value))
"PV" -> updateLogicalState("targetVoltage", 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) updateTask = scheduler.scheduleWithFixedDelay(call, 0, delay.toLong(), TimeUnit.MILLISECONDS)
listener?.updateTaskStateChanged(getName(), true) listener?.updateTaskStateChanged(getName(), true)
updateLogicalState("updating", Value.of(true)) updateState("updating", Value.of(true))
} }
@Throws(PortException::class) @Throws(PortException::class)
@ -339,7 +339,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
listener?.monitorTaskStateChanged(getName(), false) listener?.monitorTaskStateChanged(getName(), false)
monitorTask = null monitorTask = null
} }
updateLogicalState("output", Value.of(false)) updateState("output", Value.of(false))
} }
override fun getName(): String { 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) { it.weakOnPhrase({ it.startsWith("FilamentStatus") }, this) {
val response = MspResponse(it) val response = MspResponse(it)
val status = response[0, 2] val status = response[0, 2]
updateLogicalState("filamentOn", status == "ON") updateState("filamentOn", status == "ON")
updateLogicalState("filamentStatus", status) updateState("filamentStatus", status)
} }
logger.info("Connected to MKS mass-spectrometer on {}", it.port) 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) response = commandAndWait("Select", sensorName)
if (response.isOK) { if (response.isOK) {
updateLogicalState("selected", true) updateState("selected", true)
} else { } else {
notifyError(response.errorDescription, null) notifyError(response.errorDescription, null)
return false return false
@ -162,13 +162,13 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
response = commandAndWait("Control", "inr.numass.msp", "1.1") response = commandAndWait("Control", "inr.numass.msp", "1.1")
if (response.isOK) { if (response.isOK) {
updateLogicalState("controlled", true) updateState("controlled", true)
} else { } else {
notifyError(response.errorDescription, null) notifyError(response.errorDescription, null)
return false return false
} }
// connected = true; // connected = true;
updateLogicalState(PortSensor.CONNECTED_STATE, true) updateState(PortSensor.CONNECTED_STATE, true)
return true return true
} else { } else {
return !commandAndWait("Release").isOK return !commandAndWait("Release").isOK
@ -224,7 +224,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
private fun selectFilament(filament: Int) { private fun selectFilament(filament: Int) {
val response = commandAndWait("FilamentSelect", filament) val response = commandAndWait("FilamentSelect", filament)
if (response.isOK) { if (response.isOK) {
updateLogicalState("filament", response[1, 1]) updateState("filament", response[1, 1])
} else { } else {
logger.error("Failed to set filament with error: {}", response.errorDescription) 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) } forEachConnection(Roles.VIEW_ROLE, NamedValueListener::class.java) { listener -> listener.pushValue(massName, value) }
} }
"ZeroReading" -> { "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" -> { "StartingScan" -> {
val numScans = Integer.parseInt(response[0, 3]) 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") val answer = sendAndWait("MES R PM 1\r\n")
return if (answer.isEmpty()) { return if (answer.isEmpty()) {
updateLogicalState(PortSensor.CONNECTED_STATE, false) updateState(PortSensor.CONNECTED_STATE, false)
produceError("No signal") produceError("No signal")
} else if (!answer.contains("PM1:mbar")) { } else if (!answer.contains("PM1:mbar")) {
updateLogicalState(PortSensor.CONNECTED_STATE, false) updateState(PortSensor.CONNECTED_STATE, false)
produceError("Wrong answer: $answer") produceError("Wrong answer: $answer")
} else if (answer.substring(14, 17) == "OFF") { } else if (answer.substring(14, 17) == "OFF") {
updateLogicalState(PortSensor.CONNECTED_STATE, true) updateState(PortSensor.CONNECTED_STATE, true)
produceError("Off") produceError("Off")
} else { } else {
updateLogicalState(PortSensor.CONNECTED_STATE, true) updateState(PortSensor.CONNECTED_STATE, true)
produceResult(answer.substring(14, 17) + answer.substring(19, 23)) 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") val answer = sendAndWait("AV$channel\r")
if (answer.isEmpty()) { if (answer.isEmpty()) {
// invalidateState("connection"); // invalidateState("connection");
updateLogicalState(PortSensor.CONNECTED_STATE, false) updateState(PortSensor.CONNECTED_STATE, false)
return produceError("No connection") return produceError("No connection")
} else { } else {
updateLogicalState(PortSensor.CONNECTED_STATE, true) updateState(PortSensor.CONNECTED_STATE, true)
} }
val res = java.lang.Double.parseDouble(answer) val res = java.lang.Double.parseDouble(answer)
return if (res <= 0) { return if (res <= 0) {

View File

@ -93,14 +93,14 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
// } // }
val ans = talk("FP!ON") val ans = talk("FP!ON")
if (ans == "ON") { if (ans == "ON") {
updateLogicalState("power", true) updateState("power", true)
} else { } else {
this.notifyError("Failed to set power state") this.notifyError("Failed to set power state")
} }
} else { } else {
val ans = talk("FP!OFF") val ans = talk("FP!OFF")
if (ans == "OFF") { if (ans == "OFF") {
updateLogicalState("power", false) updateState("power", false)
} else { } else {
this.notifyError("Failed to set power state") 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 channel = meta.getInt("channel", 5)
val answer = talk("PR$channel?") val answer = talk("PR$channel?")
if (answer == null || answer.isEmpty()) { if (answer == null || answer.isEmpty()) {
updateLogicalState(PortSensor.CONNECTED_STATE, false) updateState(PortSensor.CONNECTED_STATE, false)
return produceError("No connection") return produceError("No connection")
} }
val res = parseDouble(answer) val res = parseDouble(answer)
return if (res <= 0) { return if (res <= 0) {
updateLogicalState("power", false) updateState("power", false)
produceError("No power") produceError("No power")
} else { } else {
this.updateMessage("OK") 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) } val answer = sendAndWait(query) { phrase -> phrase.startsWith(requestBase) }
if (answer.isEmpty()) { if (answer.isEmpty()) {
updateLogicalState(PortSensor.CONNECTED_STATE, false) updateState(PortSensor.CONNECTED_STATE, false)
return produceError("No signal") return produceError("No signal")
} else { } else {
val match = response.matcher(answer) 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())) var res = BigDecimal.valueOf(base * Math.pow(10.0, exp.toDouble()))
res = res.setScale(4, RoundingMode.CEILING) res = res.setScale(4, RoundingMode.CEILING)
updateLogicalState(PortSensor.CONNECTED_STATE, true) updateState(PortSensor.CONNECTED_STATE, true)
produceResult(res) produceResult(res)
} else { } else {
updateLogicalState(PortSensor.CONNECTED_STATE, false) updateState(PortSensor.CONNECTED_STATE, false)
produceError("Wrong answer: $answer") produceError("Wrong answer: $answer")
} }
} }