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 ed674f50..427470af 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 @@ -145,7 +145,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) { super.shutdown() } - override fun connect(meta: Meta): GenericPortController { + override fun buildConnection(meta: Meta): GenericPortController { val portName = meta.getString("name", "virtual") val port: Port = if (portName == "virtual") { 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 18d8dffa..af909a32 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 @@ -64,17 +64,17 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { val selected: Boolean by valueState("selected").booleanDelegate - var controlled: Boolean by valueState("controlled") { _, value -> + var controlled = valueState(CONTROLLED_STATE) { _, value -> control(value.booleanValue()) - }.booleanDelegate + } var filament by valueState("filament") { old, value -> selectFilament(value.intValue()) }.intDelegate - var filamentOn: Boolean by valueState("filamentOn") { _, value -> + var filamentOn = valueState("filamentOn") { _, value -> setFilamentOn(value.booleanValue()) - }.booleanDelegate + } var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate @@ -89,9 +89,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { } } - override fun connect(meta: Meta): GenericPortController { - val portName = meta.getString("name") - logger.info("Connecting to port {}", portName) + override fun buildConnection(meta: Meta): GenericPortController { + logger.info("Connecting to port {}", meta) val port: Port = PortFactory.build(meta) return GenericPortController(context, port, "\r\r").also { it.weakOnPhrase({ it.startsWith("FilamentStatus") }, this) { @@ -108,22 +107,12 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { @Throws(ControlException::class) override fun shutdown() { super.stopMeasurement() - if (connected) { + if (connected.booleanValue) { setFilamentOn(false) - connect(false) } super.shutdown() } -// //TODO make actual request -// override fun computeState(stateName: String): Any = when (stateName) { -// "controlled" -> false -// "filament" -> 1 -// "filamentOn" -> false//Always return false on first request -// "filamentStatus" -> "UNKNOWN" -// else -> super.computeState(stateName) -// } - override val type: String get() = MSP_DEVICE_TYPE @@ -138,7 +127,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { val sensorName: String if (on) { //ensure device is connected - connected = true + connected.set(true) var response = commandAndWait("Sensors") if (response.isOK) { sensorName = response[2, 1] @@ -381,7 +370,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { } } - if (!filamentOn) { + if (!filamentOn.booleanValue) { notifyError("Can't start measurement. Filament is not turned on.") } if (!commandAndWait("ScanAdd", measurementName).isOK) { @@ -403,6 +392,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) { companion object { const val MSP_DEVICE_TYPE = "numass.msp" + const val CONTROLLED_STATE = "controlled" private val TIMEOUT = Duration.ofMillis(200) } diff --git a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDeviceFactory.kt b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDeviceFactory.kt index ff87de90..95e06e7d 100644 --- a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDeviceFactory.kt +++ b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDeviceFactory.kt @@ -7,10 +7,8 @@ import hep.dataforge.meta.Meta /** * Created by darksnake on 09-May-17. */ -class MspDeviceFactory: DeviceFactory { - override fun getType(): String { - return MspDevice.MSP_DEVICE_TYPE - } +class MspDeviceFactory : DeviceFactory { + override val type = MspDevice.MSP_DEVICE_TYPE override fun build(context: Context, config: Meta): MspDevice { return MspDevice(context, config) diff --git a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt index 97f384bd..24ef2994 100644 --- a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt +++ b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt @@ -16,9 +16,9 @@ package inr.numass.control.msp import hep.dataforge.connections.NamedValueListener -import hep.dataforge.control.devices.DeviceListener import hep.dataforge.control.devices.PortSensor import hep.dataforge.control.devices.Sensor +import hep.dataforge.fx.asBooleanProperty import hep.dataforge.fx.bindWindow import hep.dataforge.fx.fragments.LogFragment import hep.dataforge.fx.plots.PlotContainer @@ -31,6 +31,7 @@ import hep.dataforge.plots.data.TimePlot import hep.dataforge.plots.data.TimePlot.Companion.setMaxItems import hep.dataforge.plots.data.TimePlot.Companion.setPrefItems import hep.dataforge.plots.jfreechart.JFreeChartFrame +import hep.dataforge.states.ValueState import hep.dataforge.values.Value import inr.numass.control.DeviceDisplayFX import inr.numass.control.deviceStateIndicator @@ -53,7 +54,7 @@ import tornadofx.* * @author darksnake */ -class MspDisplay() : DeviceDisplayFX(), DeviceListener, NamedValueListener { +class MspDisplay() : DeviceDisplayFX(), NamedValueListener { private val table = FXCollections.observableHashMap() @@ -68,7 +69,7 @@ class MspDisplay() : DeviceDisplayFX(), DeviceListener, NamedValueLis } override fun pushValue(valueName: String, value: Value) { - table.put(valueName, value) + table[valueName] = value } @@ -127,7 +128,7 @@ class MspDisplay() : DeviceDisplayFX(), DeviceListener, NamedValueLis minWidth = 600.0 top { toolbar { - deviceStateToggle(this@MspDisplay, PortSensor.CONNECTED_STATE, "Connect") + deviceStateToggle(this@MspDisplay, MspDevice.CONTROLLED_STATE, "Connect") combobox(filamentProperty, listOf(1, 2)) { cellFormat { text = "Filament $it" @@ -136,9 +137,8 @@ class MspDisplay() : DeviceDisplayFX(), DeviceListener, NamedValueLis } switch { padding = Insets(5.0, 0.0, 0.0, 0.0) - disableProperty() - .bind(booleanStateProperty(PortSensor.CONNECTED_STATE)) - bindBooleanToState("filamentOn", selectedProperty()) + disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE)) + device.filamentOn.asBooleanProperty().bindBidirectional(selectedProperty()) } deviceStateIndicator(this@MspDisplay, "filamentStatus", false) { when (it.stringValue()) { @@ -153,13 +153,12 @@ class MspDisplay() : DeviceDisplayFX(), DeviceListener, NamedValueLis togglebutton("Measure") { isSelected = false disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE).not()) - - bindBooleanToState(Sensor.MEASURING_STATE, selectedProperty()) + device.measuring.asBooleanProperty().bindBidirectional(selectedProperty()) } togglebutton("Store") { isSelected = false disableProperty().bind(booleanStateProperty(Sensor.MEASURING_STATE).not()) - bindBooleanToState("storing", selectedProperty()) + device.states.getState("storing")?.asBooleanProperty()?.bindBidirectional(selectedProperty()) } separator(Orientation.VERTICAL) pane { @@ -172,7 +171,7 @@ class MspDisplay() : DeviceDisplayFX(), DeviceListener, NamedValueLis LogFragment().apply { addLogHandler(device.logger) - bindWindow(selectedProperty()) + bindWindow(this@togglebutton, selectedProperty()) } } } diff --git a/numass-control/msp/src/main/resources/config/devices.xml b/numass-control/msp/src/main/resources/config/devices.xml index a1f61c5e..48541f74 100644 --- a/numass-control/msp/src/main/resources/config/devices.xml +++ b/numass-control/msp/src/main/resources/config/devices.xml @@ -16,10 +16,10 @@ limitations under the License. --> - - + + - + diff --git a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt index 0afdfe61..6e583d13 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt @@ -111,7 +111,7 @@ abstract class DeviceDisplayFX : Component(), Connection { if (view == null) { isDisable = true } - view?.bindWindow(selectedProperty()) + view?.bindWindow(this,selectedProperty()) } } } diff --git a/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt b/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt index bda6ff27..c01a0a37 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt @@ -47,7 +47,7 @@ abstract class NumassControlApplication : App() { abstract fun getDeviceMeta(config: Meta): Meta private fun setupDevice(): D { - val config = getConfig(this).optional.orElseGet { readResourceMeta("/config/devices.xml") } + val config = getConfig(this).optional.orElseGet { readResourceMeta("config/devices.xml") } val ctx = setupContext(config) val deviceConfig = getDeviceMeta(config) 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 958cfae8..96a5b79c 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 @@ -20,7 +20,7 @@ import inr.numass.control.DeviceView @DeviceView(VacDisplay::class) class CM32Device(context: Context, meta: Meta) : PortSensor(context, meta) { - override fun connect(meta: Meta): GenericPortController { + override fun buildConnection(meta: Meta): GenericPortController { val portName = meta.getString("name") logger.info("Connecting to port {}", portName) val port: Port = if (portName.startsWith("com")) { 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 d2de665a..379c2ff7 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 @@ -32,7 +32,7 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(context, meta return meta.getString("type", "numass.vac.baratron") } - override fun connect(meta: Meta): GenericPortController { + override fun buildConnection(meta: Meta): GenericPortController { val port: Port = PortFactory.build(meta) logger.info("Connecting to port {}", port.name) return GenericPortController(context, port) { it.endsWith("\r") } 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 ae5750a2..508bc0f4 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 @@ -58,7 +58,7 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) { } } - override fun connect(meta: Meta): GenericPortController { + override fun buildConnection(meta: Meta): GenericPortController { val port: Port = PortFactory.build(meta) logger.info("Connecting to port {}", port.name) return GenericPortController(context, port) { it.endsWith(";FF") } 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 a73e9512..c1a06a71 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 @@ -28,7 +28,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) var address by valueState("address").intDelegate - override fun connect(meta: Meta): GenericPortController { + override fun buildConnection(meta: Meta): GenericPortController { val port: Port = PortFactory.build(meta) logger.info("Connecting to port {}", port.name) diff --git a/numass-core/src/main/kotlin/inr/numass/data/storage/NumassStorageFactory.kt b/numass-core/src/main/kotlin/inr/numass/data/storage/NumassStorageFactory.kt index b84be66f..94201562 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/storage/NumassStorageFactory.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/storage/NumassStorageFactory.kt @@ -10,6 +10,7 @@ import hep.dataforge.storage.commons.StorageManager import hep.dataforge.storage.filestorage.FileStorage import java.net.URI import java.nio.file.FileSystems +import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -43,6 +44,10 @@ class NumassStorageFactory : StorageType { } else { path = Paths.get(uri) } + if(!Files.exists(path)){ + context.logger.info("File $path does not exist. Creating a new storage directory.") + Files.createDirectories(path) + } return NumassStorage(context, meta, path) } else { context.logger.warn("A storage path not provided. Creating default root storage in the working directory")