diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt index eba1bff8..33799997 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt @@ -26,6 +26,7 @@ import hep.dataforge.control.devices.Sensor import hep.dataforge.control.devices.StateDef import hep.dataforge.control.measurements.AbstractMeasurement import hep.dataforge.control.measurements.Measurement +import hep.dataforge.control.ports.GenericPortController import hep.dataforge.control.ports.Port import hep.dataforge.description.ValueDef import hep.dataforge.exceptions.ControlException @@ -43,6 +44,7 @@ import inr.numass.control.DeviceView import inr.numass.control.StorageHelper import java.time.Duration import java.util.* +import java.util.function.BiConsumer /** @@ -62,7 +64,6 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, * The key is the letter (a,b,c,d...) as in measurements */ val channels = LinkedHashMap() - private var collector: RegularPointCollector? = null private var storageHelper: StorageHelper? = null /** @@ -71,8 +72,8 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, //private var format: TableFormat? = null - private// Building data format - val tableFormat: TableFormat by lazy { + // Building data format + private val tableFormat: TableFormat by lazy { val tableFormatBuilder = TableFormatBuilder() .addTime("timestamp") @@ -91,13 +92,14 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, val abuf: String get() = getState(ABUF).stringValue() + private val duration = Duration.parse(meta().getString("averagingDuration", "PT30S")) + private fun buildLoader(connection: StorageConnection): TableLoader { val storage = connection.storage val suffix = DateTimeUtils.fileSuffix() try { - return LoaderFactory.buildPointLoder(storage, - "cryotemp_" + suffix, "", "timestamp", tableFormat) + return LoaderFactory.buildPointLoder(storage, "cryotemp_" + suffix, "", "timestamp", tableFormat) } catch (e: StorageException) { throw RuntimeException("Failed to builder loader from storage", e) } @@ -124,44 +126,39 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, super.init() //update parameters from meta - if (meta().hasValue("pga")) { - logger.info("Setting dynamic range to " + meta().getInt("pga")!!) - val response = sendAndWait("g" + meta().getInt("pga")!!, TIMEOUT).trim { it <= ' ' } + meta.optValue("pga").ifPresent { + logger.info("Setting dynamic range to " + it.intValue()) + val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' } if (response.contains("=")) { updateState(PGA, Integer.parseInt(response.substring(4))) } else { - logger.error("Setting pga failsed with message: " + response) + logger.error("Setting pga failed with message: " + response) } } - setSPS(meta().getInt("sps", 0)!!) - setBUF(meta().getInt("abuf", 100)!!) + + setSPS(meta().getInt("sps", 0)) + setBUF(meta().getInt("abuf", 100)) // setting up the collector storageHelper = StorageHelper(this) { connection: StorageConnection -> this.buildLoader(connection) } - val duration = Duration.parse(meta().getString("averagingDuration", "PT30S")) - collector = RegularPointCollector(duration, this.channels.values.map { it.name }) { dp: Values -> - logger.debug("Point measurement complete. Pushing...") - storageHelper?.push(dp) - } } @Throws(ControlException::class) override fun shutdown() { + measurement?.stop(true) storageHelper?.close() - collector?.stop() - collector = null super.shutdown() } @Throws(ControlException::class) - override fun buildHandler(portName: String): Port { + override fun buildPort(portName: String): Port { //setup connection val handler: Port = if ("virtual" == portName) { logger.info("Starting {} using virtual debug port", name) PKT8VirtualPort("PKT8", meta().getMetaOrEmpty("debug")) } else { - super.buildHandler(portName) + super.buildPort(portName) } handler.setDelimiter("\n") @@ -172,7 +169,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, logger.info("Setting avaraging buffer size to " + buf) var response: String try { - response = sendAndWait("b" + buf, Duration.ofMillis(400)).trim { it <= ' ' } + response = sendAndWait("b" + buf).trim { it <= ' ' } } catch (ex: Exception) { response = ex.message ?: "" } @@ -239,7 +236,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, private fun setSPS(sps: Int) { logger.info("Setting sampling rate to " + spsToStr(sps)) val response: String = try { - sendAndWait("v" + sps, TIMEOUT).trim { it <= ' ' } + sendAndWait("v" + sps).trim { it <= ' ' } } catch (ex: Exception) { ex.message ?: "" } @@ -257,11 +254,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, this.measurement } else { try { - if (port.isLocked) { - logger.error("Breaking hold on handler because it is locked") - port.breakHold() - } - PKT8Measurement(port) + PKT8Measurement(connection) } catch (e: ControlException) { throw MeasurementException(e) } @@ -274,7 +267,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, //clearing PKT queue try { send("p") - sendAndWait("p", TIMEOUT) + sendAndWait("p") } catch (e: ControlException) { logger.error("Failed to clear PKT8 port") // throw new MeasurementException(e); @@ -284,10 +277,19 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, } - inner class PKT8Measurement(private val handler: Port) : AbstractMeasurement(), Port.PortController { + inner class PKT8Measurement(private val controller: GenericPortController) : AbstractMeasurement() { override fun getDevice(): Device = this@PKT8Device + private var collector: RegularPointCollector = RegularPointCollector(duration, channels.values.map { it.name }) { dp: Values -> + logger.debug("Point measurement complete. Pushing...") + storageHelper?.push(dp) + } + + var errorListener: BiConsumer? = null + var stopListener: GenericPortController.PhraseListener? = null; + var valueListener: GenericPortController.PhraseListener? = null; + override fun start() { if (isStarted) { logger.warn("Trying to start measurement which is already started") @@ -295,11 +297,37 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, try { logger.info("Starting measurement") - handler.holdBy(this) - handler.send(this, "s") + //add weak error listener + errorListener = controller.onError(this::onError) + + //add weak stop listener + stopListener = controller.onPhrase("[Ss]topped\\s*") { + afterPause() + updateState(Sensor.MEASURING_STATE, false) + } + + //add weak measurement listener + valueListener = controller.onPhrase("[a-f].*") { + val trimmed = it.trim() + val designation = trimmed.substring(0, 1) + val rawValue = java.lang.Double.parseDouble(trimmed.substring(1)) / 100 + + val channel = this@PKT8Device.channels[designation] + + if (channel != null) { + result(channel.evaluate(rawValue)) + collector.put(channel.name, channel.getTemperature(rawValue)) + } else { + result(PKT8Result(designation, rawValue, -1.0)) + } + } + + //send start signal + controller.send("s") + afterStart() } catch (ex: ControlException) { - portError("Failed to start measurement", ex) + onError("Failed to start measurement", ex) } } @@ -308,56 +336,31 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, override fun stop(force: Boolean): Boolean { if (isFinished) { logger.warn("Trying to stop measurement which is already stopped") - } + return true + } else { - try { - logger.info("Stopping measurement") - val response = sendAndWait("p", TIMEOUT).trim { it <= ' ' } - // Должно быть именно с большой буквы!!! - return "Stopped" == response || "stopped" == response - } catch (ex: Exception) { - error(ex) - return false - } finally { - collector?.clear() - logger.debug("Removing port lock") - handler.releaseBy(this) - } - } - - - override fun acceptPhrase(message: String) { - val trimmed = message.trim { it <= ' ' } - - if (isStarted) { - if (trimmed == "Stopped" || trimmed == "stopped") { - afterPause() - updateState(Sensor.MEASURING_STATE, false) - // getLogger().info("Measurement stopped"); - } else { - val designation = trimmed.substring(0, 1) - val rawValue = java.lang.Double.parseDouble(trimmed.substring(1)) / 100 - - val channel = this@PKT8Device.channels[designation] - - if (channel != null) { - result(channel.evaluate(rawValue)) - collector?.put(channel.name, channel.getTemperature(rawValue)) - } else { - result(PKT8Result(designation, rawValue, -1.0)) - } + try { + logger.info("Stopping measurement") + val response = sendAndWait("p").trim() + // Должно быть именно с большой буквы!!! + return "Stopped" == response || "stopped" == response + } catch (ex: Exception) { + onError("Failed to stop measurement", ex) + return false + } finally { + afterStop() + errorListener?.let { controller.removeErrorListener(it) } + stopListener?.let { controller.removePhraseListener(it) } + valueListener?.let { controller.removePhraseListener(it) } + collector.stop() + logger.debug("Collector stopped") } } } - - override fun portError(errorMessage: String, error: Throwable) { - super.error(error) - } } companion object { val PKT8_DEVICE_TYPE = "numass.pkt8" - private val TIMEOUT = Duration.ofMillis(400) val PGA = "pga" val SPS = "sps" diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt index 69bb4742..769d4493 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt @@ -18,12 +18,12 @@ import java.util.function.Supplier /** * @author Alexander Nozik */ -class PKT8VirtualPort(portName: String, meta: Meta) : VirtualPort(), Metoid { +class PKT8VirtualPort(portName: String, meta: Meta) : VirtualPort(meta), Metoid { private val generator = Random() init { - super.configure(meta).configureValue("id", portName) + super.configureValue("id", portName) } @Synchronized override fun evaluateRequest(request: String) { diff --git a/numass-control/magnet/src/main/java/inr/numass/control/magnet/VirtualLambdaPort.java b/numass-control/magnet/src/main/java/inr/numass/control/magnet/VirtualLambdaPort.java index ec6e5d10..8846285c 100644 --- a/numass-control/magnet/src/main/java/inr/numass/control/magnet/VirtualLambdaPort.java +++ b/numass-control/magnet/src/main/java/inr/numass/control/magnet/VirtualLambdaPort.java @@ -51,7 +51,7 @@ public class VirtualLambdaPort extends VirtualPort { } @Override - public String getPortId() { + public String toString() { return virtualPortName; } diff --git a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt index b2c53eb3..205dbff9 100644 --- a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt +++ b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt @@ -21,13 +21,13 @@ import hep.dataforge.control.RoleDef import hep.dataforge.control.RoleDefs import hep.dataforge.control.collectors.RegularPointCollector import hep.dataforge.control.connections.Roles -import hep.dataforge.control.devices.* +import hep.dataforge.control.devices.Device +import hep.dataforge.control.devices.PortSensor +import hep.dataforge.control.devices.StateDef +import hep.dataforge.control.devices.StateDefs import hep.dataforge.control.measurements.AbstractMeasurement -import hep.dataforge.control.ports.GenericPortController import hep.dataforge.control.ports.Port -import hep.dataforge.control.ports.TcpPort import hep.dataforge.description.ValueDef -import hep.dataforge.events.EventBuilder import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.MeasurementException import hep.dataforge.exceptions.PortException @@ -61,15 +61,10 @@ import java.util.function.Consumer StateDef(ValueDef(name = "filamentStatus", info = "Filament status")) ) @DeviceView(MspDisplay::class) -class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), Port.PortController { +class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { - private var handler: TcpPort? = null - private val controller = GenericPortController(this) private var measurementDelegate: Consumer? = null - val isConnected: Boolean - get() = getState(PortSensor.CONNECTED_STATE).booleanValue() - val isSelected: Boolean get() = getState("selected").booleanValue() @@ -79,22 +74,60 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P val isFilamentOn: Boolean get() = getState("filamentOn").booleanValue() - private val averagingDuration: Duration - get() = Duration.parse(meta().getString("averagingDuration", "PT30S")) + private val averagingDuration: Duration = Duration.parse(meta().getString("averagingDuration", "PT30S")) - // public MspDevice(String name, Context context, Meta config) { - // super(name, context, config); - // } @Throws(ControlException::class) override fun init() { super.init() - val ip = meta().getString("connection.ip", "127.0.0.1") - val port = meta().getInt("connection.port", 10014)!! - logger.info("Connection to MKS mass-spectrometer on {}:{}...", ip, port) - handler = TcpPort(ip, port) - handler!!.setDelimiter("\r\r") + connection.weakOnError(this::notifyError) + onResponse("FilamentStatus"){ + val status = it[0, 2] + updateState("filamentOn", status == "ON") + updateState("filamentStatus", status) + } + logger.info("Connected to MKS mass-spectrometer on {}", connection.port); } + /** + * Add reaction on specific response + */ + private fun onResponse(command: String, action: (MspResponse) -> Unit) { + connection.weakOnPhrase({it.startsWith(command)}){ + action(MspResponse(it)) + } + } + + /* + + override fun acceptPhrase(message: String) { + dispatchEvent( + EventBuilder + .make("msp") + .setMetaValue("response", message.trim { it <= ' ' }).build() + ) + val response = MspResponse(message) + + when (response.commandName) { + // all possible async messages + "FilamentStatus" -> { + val status = response[0, 2] + updateState("filamentOn", status == "ON") + updateState("filamentStatus", status) + } + } + if (measurementDelegate != null) { + measurementDelegate!!.accept(response) + } + } + + override fun portError(errorMessage: String?, error: Throwable?) { + notifyError(errorMessage, error) + } + + */ + + override fun buildPort(portName: String?): Port = super.buildPort(portName).apply { setDelimiter("\r\r") } + @Throws(ControlException::class) override fun shutdown() { super.stopMeasurement(true) @@ -102,15 +135,9 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P setFilamentOn(false) setConnected(false) } - getHandler().close() super.shutdown() } - // @Override - // protected Meta getMeasurementMeta() { - // return meta().getMeta("peakJump"); - // } - @Throws(MeasurementException::class) override fun createMeasurement(): PeakJumpMeasurement { val measurementMeta = meta().getMeta("peakJump") @@ -125,20 +152,16 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P } @Throws(ControlException::class) - override fun computeState(stateName: String): Any { - when (stateName) { - "connected" -> return false - "filament" -> return 1 - "filamentOn" -> return false//Always return false on first request - "filamentStatus" -> return "UNKNOWN" - "storing" -> return false - else -> return super.computeState(stateName) - } + override fun computeState(stateName: String): Any = when (stateName) { + "connected" -> false + "filament" -> 1 + "filamentOn" -> false//Always return false on first request + "filamentStatus" -> "UNKNOWN" + "storing" -> false + else -> super.computeState(stateName) } - override fun getType(): String { - return "MKS E-Vision" - } + override fun getType(): String = MSP_DEVICE_TYPE @Throws(ControlException::class) override fun requestStateChange(stateName: String, value: Value) { @@ -162,40 +185,40 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P val sensorName: String if (isConnected != connected) { if (connected) { - getHandler().holdBy(controller) - var response = sendAndWait("Sensors") + connection.open() + var response = commandAndWait("Sensors") if (response.isOK) { sensorName = response[2, 1] } else { - portError(response.errorDescription(), null) + notifyError(response.errorDescription(), null) return false } //PENDING определеить в конфиге номер прибора - response = sendAndWait("Select", sensorName) + response = commandAndWait("Select", sensorName) if (response.isOK) { updateState("selected", true) // selected = true; } else { - portError(response.errorDescription(), null) + notifyError(response.errorDescription(), null) return false } - response = sendAndWait("Control", "inr.numass.msp", "1.0") + response = commandAndWait("Control", "inr.numass.msp", "1.0") if (response.isOK) { // controlled = true; // invalidateState("controlled"); updateState("controlled", true) } else { - portError(response.errorDescription(), null) + notifyError(response.errorDescription(), null) return false } // connected = true; updateState(PortSensor.CONNECTED_STATE, true) return true } else { - getHandler().releaseBy(controller) - return !sendAndWait("Release").isOK + connection.close() + return !commandAndWait("Release").isOK } } else { @@ -211,15 +234,8 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P * @throws PortException */ @Throws(PortException::class) - private fun send(command: String, vararg parameters: Any) { - val request = buildCommand(command, *parameters) - dispatchEvent( - EventBuilder - .make("msp") - .setMetaValue("request", request) - .build() - ) - getHandler().send(request) + private fun command(command: String, vararg parameters: Any) { + send(buildCommand(command, *parameters)) } /** @@ -248,25 +264,15 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P * @throws PortException */ @Throws(PortException::class) - private fun sendAndWait(commandName: String, vararg parameters: Any): MspResponse { - - val request = buildCommand(commandName, *parameters) - dispatchEvent( - EventBuilder - .make("msp") - .setMetaValue("request", request) - .build() - ) - - - getHandler().send(controller, request) - val response = controller.waitFor(TIMEOUT) { str: String -> str.trim { it <= ' ' }.startsWith(commandName) } + private fun commandAndWait(commandName: String, vararg parameters: Any): MspResponse { + send(buildCommand(commandName, *parameters)) + val response = connection.waitFor(timeout) { str: String -> str.trim { it <= ' ' }.startsWith(commandName) } return MspResponse(response) } @Throws(PortException::class) - fun selectFilament(filament: Int) { - val response = sendAndWait("FilamentSelect", filament) + private fun selectFilament(filament: Int) { + val response = commandAndWait("FilamentSelect", filament) if (response.isOK) { updateState("filament", response[1, 1]) } else { @@ -282,51 +288,22 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P * @throws hep.dataforge.exceptions.PortException */ @Throws(PortException::class) - fun setFilamentOn(filamentOn: Boolean): Boolean { + private fun setFilamentOn(filamentOn: Boolean): Boolean { return if (filamentOn) { - sendAndWait("FilamentControl", "On").isOK + commandAndWait("FilamentControl", "On").isOK } else { - sendAndWait("FilamentControl", "Off").isOK + commandAndWait("FilamentControl", "Off").isOK } } - - /** - * Evaluate general async messages - * - * @param response - */ - private fun evaluateResponse(response: MspResponse) { - - } - - override fun acceptPhrase(message: String) { - dispatchEvent( - EventBuilder - .make("msp") - .setMetaValue("response", message.trim { it <= ' ' }).build() - ) - val response = MspResponse(message) - - when (response.commandName) { - // all possible async messages - "FilamentStatus" -> { - val status = response[0, 2] - updateState("filamentOn", status == "ON") - updateState("filamentStatus", status) - } - } - if (measurementDelegate != null) { - measurementDelegate!!.accept(response) - } - } - - override fun portError(errorMessage: String?, error: Throwable?) { - notifyError(errorMessage, error) - } - - private fun getHandler(): TcpPort { - return handler ?: throw RuntimeException("Device not initialized") - } +// +// /** +// * Evaluate general async messages +// * +// * @param response +// */ +// private fun evaluateResponse(response: MspResponse) { +// +// } /** * The MKS response as two-dimensional array of strings @@ -372,9 +349,7 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P } } - operator fun get(lineNo: Int, columnNo: Int): String { - return data[lineNo][columnNo] - } + operator fun get(lineNo: Int, columnNo: Int): String = data[lineNo][columnNo] } inner class PeakJumpMeasurement(private val meta: Meta) : AbstractMeasurement(), Consumer { @@ -398,9 +373,7 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P } - override fun getDevice(): Device { - return this@MspDevice - } + override fun getDevice(): Device = this@MspDevice override fun start() { try { @@ -409,11 +382,11 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P val accuracy = meta.getInt("accuracy", 5)!! //PENDING вставить остальные параметры? sendAndWait("MeasurementRemoveAll") - if (sendAndWait("AddPeakJump", measurementName, filterMode, accuracy, 0, 0, 0).isOK) { + if (commandAndWait("AddPeakJump", measurementName, filterMode, accuracy, 0, 0, 0).isOK) { peakMap.clear() for (peak in meta.getMetaList("peak")) { peakMap.put(peak.getInt("mass"), peak.getString("name", peak.getString("mass"))) - if (!sendAndWait("MeasurementAddMass", peak.getString("mass")).isOK) { + if (!commandAndWait("MeasurementAddMass", peak.getString("mass")).isOK) { throw ControlException("Can't add mass to measurement measurement for msp") } } @@ -424,11 +397,11 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P if (!isFilamentOn) { this.error("Can't start measurement. Filament is not turned on.", null) } - if (!sendAndWait("ScanAdd", measurementName).isOK) { + if (!commandAndWait("ScanAdd", measurementName).isOK) { this.error("Failed to add scan", null) } - if (!sendAndWait("ScanStart", 2).isOK) { + if (!commandAndWait("ScanStart", 2).isOK) { this.error("Failed to start scan", null) } } catch (ex: ControlException) { @@ -442,7 +415,7 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P override fun stop(force: Boolean): Boolean { try { collector.stop() - val stop = sendAndWait("ScanStop").isOK + val stop = commandAndWait("ScanStop").isOK afterStop() helper.close() return stop @@ -466,9 +439,6 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P } override fun accept(response: MspResponse) { - - //Evaluating device state change - evaluateResponse(response) //Evaluating measurement information when (response.commandName) { "MassReading" -> { @@ -484,7 +454,7 @@ class MspDevice(context: Context, meta: Meta) : Sensor(context, meta), P if (numScans == 0) { try { - send("ScanResume", 10) + command("ScanResume", 10) //FIXME обработать ошибку связи } catch (ex: PortException) { error(null, ex) diff --git a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt index f9daac48..73b1e8be 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt @@ -111,12 +111,12 @@ abstract class DeviceDisplay : Component(), Connection, DeviceListen * @param property */ protected fun bindBooleanToState(state: String, property: BooleanProperty) { - getStateBinding(state).addListener { observable, oldValue, newValue -> + getStateBinding(state).addListener { _, oldValue, newValue -> if (isOpen && oldValue !== newValue) { property.value = newValue.booleanValue() } } - property.addListener { observable, oldValue, newValue -> + property.addListener { _, oldValue, newValue -> if (isOpen && oldValue != newValue) { runAsync { if(!device.isInitialized){ diff --git a/numass-control/src/main/kotlin/inr/numass/control/FXExtensions.kt b/numass-control/src/main/kotlin/inr/numass/control/FXExtensions.kt index 1eb066e0..3840c9a6 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/FXExtensions.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/FXExtensions.kt @@ -117,7 +117,7 @@ fun Node.deviceStateToggle(connection: DeviceDisplay<*>, state: String, title: S if (connection.device.hasState(state)) { togglebutton(title) { isSelected = false - selectedProperty().addListener { observable, oldValue, newValue -> + selectedProperty().addListener { _, oldValue, newValue -> if (oldValue != newValue) { connection.device.setState(state, newValue).thenAccept { isSelected = it.booleanValue() diff --git a/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt b/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt index 3ea8c99f..0bbafffa 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt @@ -108,7 +108,7 @@ fun findDeviceMeta(config: Meta, criterion: Predicate): Optional { fun setupContext(meta: Meta): Context { val ctx = Global.getContext("NUMASS-CONTROL") - ctx.getPluginManager().getOrLoad(StorageManager::class.java) + ctx.pluginManager.getOrLoad(StorageManager::class.java) return ctx } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt index 3f8fa266..0c033c32 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt @@ -24,7 +24,7 @@ import inr.numass.control.DeviceView class CM32Device(context: Context, meta: Meta) : PortSensor(context, meta) { @Throws(ControlException::class) - override fun buildHandler(portName: String): Port { + override fun buildPort(portName: String): Port { logger.info("Connecting to port {}", portName) val new: Port if (portName.startsWith("com")) { @@ -50,7 +50,7 @@ class CM32Device(context: Context, meta: Meta) : PortSensor(context, met @Throws(Exception::class) override fun doMeasure(): Double? { - val answer = sendAndWait("MES R PM 1\r\n", timeout()) + val answer = sendAndWait("MES R PM 1\r\n") if (answer.isEmpty()) { this.updateMessage("No signal") diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt index 08e24a3a..ba1e2446 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt @@ -35,8 +35,8 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(conte } @Throws(ControlException::class) - override fun buildHandler(portName: String): Port { - val handler = super.buildHandler(portName) + override fun buildPort(portName: String): Port { + val handler = super.buildPort(portName) handler.setDelimiter("\r") return handler } @@ -50,7 +50,7 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(conte @Synchronized @Throws(Exception::class) override fun doMeasure(): Double? { - val answer = sendAndWait("AV" + channel + "\r", timeout()) + val answer = sendAndWait("AV" + channel + "\r") if (answer == null || answer.isEmpty()) { // invalidateState("connection"); updateState(PortSensor.CONNECTED_STATE, false) diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt index 9468fec2..ebe35942 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt @@ -66,7 +66,7 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, m @Throws(ControlException::class) private fun talk(requestContent: String): String? { - val answer = sendAndWait(String.format("@%s%s;FF", deviceAddress, requestContent), timeout()) + val answer = sendAndWait(String.format("@%s%s;FF", deviceAddress, requestContent)) val match = Pattern.compile("@" + deviceAddress + "ACK(.*);FF").matcher(answer) return if (match.matches()) { @@ -77,8 +77,8 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, m } @Throws(ControlException::class) - override fun buildHandler(portName: String): Port { - val handler = super.buildHandler(portName) + override fun buildPort(portName: String): Port { + val handler = super.buildPort(portName) handler.setDelimiter(";FF") return handler } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt index 2c5dc107..c1c7a77b 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt @@ -27,8 +27,8 @@ import java.util.regex.Pattern class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) { @Throws(ControlException::class) - override fun buildHandler(portName: String): Port { - val newHandler = super.buildHandler(portName) + override fun buildPort(portName: String): Port { + val newHandler = super.buildPort(portName) newHandler.setDelimiter("\r\n") return newHandler } @@ -59,7 +59,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(contex @Throws(Exception::class) override fun doMeasure(): Double? { - val answer = sendAndWait(query, timeout()) { phrase -> phrase.startsWith(base) } + val answer = sendAndWait(query) { phrase -> phrase.startsWith(base) } if (answer.isEmpty()) { this.updateMessage("No signal") diff --git a/numass-server/src/main/resources/templates/NumassLoader.ftl b/numass-server/src/main/resources/templates/NumassLoader.ftl index 9abe66a2..e9955504 100644 --- a/numass-server/src/main/resources/templates/NumassLoader.ftl +++ b/numass-server/src/main/resources/templates/NumassLoader.ftl @@ -17,7 +17,7 @@ // alert('sending request to ${dataSource}') var query = new google.visualization.Query("${dataSource}", opts); query.setRefreshInterval(${updateInterval}); - query.send(handleQueryResponse); + query.command(handleQueryResponse); } function handleQueryResponse(response) {