Numass control update
This commit is contained in:
parent
94ed08f7bd
commit
4372f46055
@ -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") {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<MspDevice>(), DeviceListener, NamedValueListener {
|
||||
class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
|
||||
|
||||
private val table = FXCollections.observableHashMap<String, Value>()
|
||||
|
||||
@ -68,7 +69,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
|
||||
}
|
||||
|
||||
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
|
||||
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<MspDevice>(), 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<MspDevice>(), 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<ValueState>("storing")?.asBooleanProperty()?.bindBidirectional(selectedProperty())
|
||||
}
|
||||
separator(Orientation.VERTICAL)
|
||||
pane {
|
||||
@ -172,7 +171,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), DeviceListener, NamedValueLis
|
||||
|
||||
LogFragment().apply {
|
||||
addLogHandler(device.logger)
|
||||
bindWindow(selectedProperty())
|
||||
bindWindow(this@togglebutton, selectedProperty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ limitations under the License.
|
||||
-->
|
||||
|
||||
<config>
|
||||
<storage path="D:/temp/test" type = "numass"/>
|
||||
<device type="msp" name="msp">
|
||||
<storage path="file:///D:/temp/test" type = "numass"/>
|
||||
<device type="msp" name="numass.msp" debug = "true">
|
||||
<!--<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>
|
||||
<peak mass="2" title="hydrogen" color="black" thickness="4"/>
|
||||
<peak mass="3"/>
|
||||
|
@ -111,7 +111,7 @@ abstract class DeviceDisplayFX<D : Device> : Component(), Connection {
|
||||
if (view == null) {
|
||||
isDisable = true
|
||||
}
|
||||
view?.bindWindow(selectedProperty())
|
||||
view?.bindWindow(this,selectedProperty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ abstract class NumassControlApplication<in D : Device> : 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)
|
||||
|
@ -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")) {
|
||||
|
@ -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") }
|
||||
|
@ -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") }
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user