Numass control update

This commit is contained in:
Alexander Nozik 2018-04-11 12:49:47 +03:00
parent 94ed08f7bd
commit 4372f46055
12 changed files with 37 additions and 45 deletions

View File

@ -145,7 +145,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) {
super.shutdown() super.shutdown()
} }
override fun connect(meta: Meta): GenericPortController { override fun buildConnection(meta: Meta): GenericPortController {
val portName = meta.getString("name", "virtual") val portName = meta.getString("name", "virtual")
val port: Port = if (portName == "virtual") { val port: Port = if (portName == "virtual") {

View File

@ -64,17 +64,17 @@ 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: Boolean by valueState("controlled") { _, value -> var controlled = valueState(CONTROLLED_STATE) { _, value ->
control(value.booleanValue()) control(value.booleanValue())
}.booleanDelegate }
var filament by valueState("filament") { old, value -> var filament by valueState("filament") { old, value ->
selectFilament(value.intValue()) selectFilament(value.intValue())
}.intDelegate }.intDelegate
var filamentOn: Boolean by valueState("filamentOn") { _, value -> var filamentOn = valueState("filamentOn") { _, value ->
setFilamentOn(value.booleanValue()) setFilamentOn(value.booleanValue())
}.booleanDelegate }
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate 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 { override fun buildConnection(meta: Meta): GenericPortController {
val portName = meta.getString("name") logger.info("Connecting to port {}", meta)
logger.info("Connecting to port {}", portName)
val port: Port = PortFactory.build(meta) val port: Port = PortFactory.build(meta)
return GenericPortController(context, port, "\r\r").also { return GenericPortController(context, port, "\r\r").also {
it.weakOnPhrase({ it.startsWith("FilamentStatus") }, this) { it.weakOnPhrase({ it.startsWith("FilamentStatus") }, this) {
@ -108,22 +107,12 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
@Throws(ControlException::class) @Throws(ControlException::class)
override fun shutdown() { override fun shutdown() {
super.stopMeasurement() super.stopMeasurement()
if (connected) { if (connected.booleanValue) {
setFilamentOn(false) setFilamentOn(false)
connect(false)
} }
super.shutdown() 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 override val type: String
get() = MSP_DEVICE_TYPE get() = MSP_DEVICE_TYPE
@ -138,7 +127,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
val sensorName: String val sensorName: String
if (on) { if (on) {
//ensure device is connected //ensure device is connected
connected = true connected.set(true)
var response = commandAndWait("Sensors") var response = commandAndWait("Sensors")
if (response.isOK) { if (response.isOK) {
sensorName = response[2, 1] 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.") notifyError("Can't start measurement. Filament is not turned on.")
} }
if (!commandAndWait("ScanAdd", measurementName).isOK) { if (!commandAndWait("ScanAdd", measurementName).isOK) {
@ -403,6 +392,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
companion object { companion object {
const val MSP_DEVICE_TYPE = "numass.msp" const val MSP_DEVICE_TYPE = "numass.msp"
const val CONTROLLED_STATE = "controlled"
private val TIMEOUT = Duration.ofMillis(200) private val TIMEOUT = Duration.ofMillis(200)
} }

View File

@ -8,9 +8,7 @@ import hep.dataforge.meta.Meta
* Created by darksnake on 09-May-17. * Created by darksnake on 09-May-17.
*/ */
class MspDeviceFactory : DeviceFactory { class MspDeviceFactory : DeviceFactory {
override fun getType(): String { override val type = MspDevice.MSP_DEVICE_TYPE
return MspDevice.MSP_DEVICE_TYPE
}
override fun build(context: Context, config: Meta): MspDevice { override fun build(context: Context, config: Meta): MspDevice {
return MspDevice(context, config) return MspDevice(context, config)

View File

@ -16,9 +16,9 @@
package inr.numass.control.msp package inr.numass.control.msp
import hep.dataforge.connections.NamedValueListener import hep.dataforge.connections.NamedValueListener
import hep.dataforge.control.devices.DeviceListener
import hep.dataforge.control.devices.PortSensor import hep.dataforge.control.devices.PortSensor
import hep.dataforge.control.devices.Sensor import hep.dataforge.control.devices.Sensor
import hep.dataforge.fx.asBooleanProperty
import hep.dataforge.fx.bindWindow import hep.dataforge.fx.bindWindow
import hep.dataforge.fx.fragments.LogFragment import hep.dataforge.fx.fragments.LogFragment
import hep.dataforge.fx.plots.PlotContainer 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.setMaxItems
import hep.dataforge.plots.data.TimePlot.Companion.setPrefItems import hep.dataforge.plots.data.TimePlot.Companion.setPrefItems
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.states.ValueState
import hep.dataforge.values.Value import hep.dataforge.values.Value
import inr.numass.control.DeviceDisplayFX import inr.numass.control.DeviceDisplayFX
import inr.numass.control.deviceStateIndicator import inr.numass.control.deviceStateIndicator
@ -53,7 +54,7 @@ import tornadofx.*
* @author darksnake * @author darksnake
*/ */
class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueListener { class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
private val table = FXCollections.observableHashMap<String, Value>() private val table = FXCollections.observableHashMap<String, Value>()
@ -68,7 +69,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
} }
override fun pushValue(valueName: String, value: Value) { override fun pushValue(valueName: String, value: Value) {
table.put(valueName, value) table[valueName] = value
} }
@ -127,7 +128,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
minWidth = 600.0 minWidth = 600.0
top { top {
toolbar { toolbar {
deviceStateToggle(this@MspDisplay, PortSensor.CONNECTED_STATE, "Connect") deviceStateToggle(this@MspDisplay, MspDevice.CONTROLLED_STATE, "Connect")
combobox(filamentProperty, listOf(1, 2)) { combobox(filamentProperty, listOf(1, 2)) {
cellFormat { cellFormat {
text = "Filament $it" text = "Filament $it"
@ -136,9 +137,8 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
} }
switch { switch {
padding = Insets(5.0, 0.0, 0.0, 0.0) padding = Insets(5.0, 0.0, 0.0, 0.0)
disableProperty() disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE))
.bind(booleanStateProperty(PortSensor.CONNECTED_STATE)) device.filamentOn.asBooleanProperty().bindBidirectional(selectedProperty())
bindBooleanToState("filamentOn", selectedProperty())
} }
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) { deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {
when (it.stringValue()) { when (it.stringValue()) {
@ -153,13 +153,12 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
togglebutton("Measure") { togglebutton("Measure") {
isSelected = false isSelected = false
disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE).not()) disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE).not())
device.measuring.asBooleanProperty().bindBidirectional(selectedProperty())
bindBooleanToState(Sensor.MEASURING_STATE, selectedProperty())
} }
togglebutton("Store") { togglebutton("Store") {
isSelected = false isSelected = false
disableProperty().bind(booleanStateProperty(Sensor.MEASURING_STATE).not()) disableProperty().bind(booleanStateProperty(Sensor.MEASURING_STATE).not())
bindBooleanToState("storing", selectedProperty()) device.states.getState<ValueState>("storing")?.asBooleanProperty()?.bindBidirectional(selectedProperty())
} }
separator(Orientation.VERTICAL) separator(Orientation.VERTICAL)
pane { pane {
@ -172,7 +171,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
LogFragment().apply { LogFragment().apply {
addLogHandler(device.logger) addLogHandler(device.logger)
bindWindow(selectedProperty()) bindWindow(this@togglebutton, selectedProperty())
} }
} }
} }

View File

@ -16,10 +16,10 @@ limitations under the License.
--> -->
<config> <config>
<storage path="D:/temp/test" type = "numass"/> <storage path="file:///D:/temp/test" type = "numass"/>
<device type="msp" name="msp"> <device type="msp" name="numass.msp" debug = "true">
<!--<connection ip="127.0.0.1" port="10014"/>--> <!--<connection ip="127.0.0.1" port="10014"/>-->
<connection ip="192.168.111.11" port="10014"/> <port type="tcp" ip="192.168.111.11" port="10014"/>
<peakJump> <peakJump>
<peak mass="2" title="hydrogen" color="black" thickness="4"/> <peak mass="2" title="hydrogen" color="black" thickness="4"/>
<peak mass="3"/> <peak mass="3"/>

View File

@ -111,7 +111,7 @@ abstract class DeviceDisplayFX<D : Device> : Component(), Connection {
if (view == null) { if (view == null) {
isDisable = true isDisable = true
} }
view?.bindWindow(selectedProperty()) view?.bindWindow(this,selectedProperty())
} }
} }
} }

View File

@ -47,7 +47,7 @@ abstract class NumassControlApplication<in D : Device> : App() {
abstract fun getDeviceMeta(config: Meta): Meta abstract fun getDeviceMeta(config: Meta): Meta
private fun setupDevice(): D { 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 ctx = setupContext(config)
val deviceConfig = getDeviceMeta(config) val deviceConfig = getDeviceMeta(config)

View File

@ -20,7 +20,7 @@ import inr.numass.control.DeviceView
@DeviceView(VacDisplay::class) @DeviceView(VacDisplay::class)
class CM32Device(context: Context, meta: Meta) : PortSensor(context, meta) { 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") val portName = meta.getString("name")
logger.info("Connecting to port {}", portName) logger.info("Connecting to port {}", portName)
val port: Port = if (portName.startsWith("com")) { val port: Port = if (portName.startsWith("com")) {

View File

@ -32,7 +32,7 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(context, meta
return meta.getString("type", "numass.vac.baratron") 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) val port: Port = PortFactory.build(meta)
logger.info("Connecting to port {}", port.name) logger.info("Connecting to port {}", port.name)
return GenericPortController(context, port) { it.endsWith("\r") } return GenericPortController(context, port) { it.endsWith("\r") }

View File

@ -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) val port: Port = PortFactory.build(meta)
logger.info("Connecting to port {}", port.name) logger.info("Connecting to port {}", port.name)
return GenericPortController(context, port) { it.endsWith(";FF") } return GenericPortController(context, port) { it.endsWith(";FF") }

View File

@ -28,7 +28,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(context, meta)
var address by valueState("address").intDelegate var address by valueState("address").intDelegate
override fun connect(meta: Meta): GenericPortController { override fun buildConnection(meta: Meta): GenericPortController {
val port: Port = PortFactory.build(meta) val port: Port = PortFactory.build(meta)
logger.info("Connecting to port {}", port.name) logger.info("Connecting to port {}", port.name)

View File

@ -10,6 +10,7 @@ import hep.dataforge.storage.commons.StorageManager
import hep.dataforge.storage.filestorage.FileStorage import hep.dataforge.storage.filestorage.FileStorage
import java.net.URI import java.net.URI
import java.nio.file.FileSystems import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
@ -43,6 +44,10 @@ class NumassStorageFactory : StorageType {
} else { } else {
path = Paths.get(uri) 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) return NumassStorage(context, meta, path)
} else { } else {
context.logger.warn("A storage path not provided. Creating default root storage in the working directory") context.logger.warn("A storage path not provided. Creating default root storage in the working directory")