Updates on control

This commit is contained in:
Alexander Nozik 2018-04-13 11:52:12 +03:00
parent d032c48ef4
commit 7e676681b7
4 changed files with 65 additions and 91 deletions

View File

@ -96,14 +96,14 @@ class PKT8Display : DeviceDisplayFX<PKT8Device>(), PKT8ValueListener {
plotButton = togglebutton("Plot") { plotButton = togglebutton("Plot") {
isSelected = false isSelected = false
plotView.bindWindow(selectedProperty()) plotView.bindWindow(this, selectedProperty())
} }
logButton = togglebutton("Log") { logButton = togglebutton("Log") {
isSelected = false isSelected = false
LogFragment().apply { LogFragment().apply {
addLogHandler(device.logger) addLogHandler(device.logger)
bindWindow(selectedProperty()) bindWindow(this@togglebutton, selectedProperty())
} }
} }
} }

View File

@ -29,6 +29,7 @@ import hep.dataforge.description.ValueDef
import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.ControlException
import hep.dataforge.exceptions.MeasurementException import hep.dataforge.exceptions.MeasurementException
import hep.dataforge.exceptions.PortException import hep.dataforge.exceptions.PortException
import hep.dataforge.kodex.useMeta
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.states.StateDef import hep.dataforge.states.StateDef
import hep.dataforge.states.StateDefs import hep.dataforge.states.StateDefs
@ -108,13 +109,19 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
} }
} }
override fun init() {
super.init()
meta.useMeta("peakJump"){
updateState(MEASUREMENT_META_STATE, it)
}
}
@Throws(ControlException::class) @Throws(ControlException::class)
override fun shutdown() { override fun shutdown() {
super.stopMeasurement() if (controlled.booleanValue) {
if (connected.booleanValue) {
setFilamentOn(false) setFilamentOn(false)
} }
controlled.set(false)
super.shutdown() super.shutdown()
} }
@ -129,10 +136,10 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
* @throws hep.dataforge.exceptions.ControlException * @throws hep.dataforge.exceptions.ControlException
*/ */
private fun control(on: Boolean): Boolean { private fun control(on: Boolean): Boolean {
logger.info("Starting initialization sequence")
if (on != this.controlled.booleanValue) { if (on != this.controlled.booleanValue) {
val sensorName: String val sensorName: String
if (on) { if (on) {
logger.info("Starting initialization sequence")
//ensure device is connected //ensure device is connected
connected.setAndWait(true) connected.setAndWait(true)
var response = commandAndWait("Sensors") var response = commandAndWait("Sensors")
@ -163,6 +170,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
updateState(PortSensor.CONNECTED_STATE, true) updateState(PortSensor.CONNECTED_STATE, true)
return true return true
} else { } else {
logger.info("Releasing device")
return !commandAndWait("Release").isOK return !commandAndWait("Release").isOK
} }
} else { } else {
@ -248,59 +256,11 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
} }
} }
/**
* The MKS response as two-dimensional array of strings
*/
class MspResponse(response: String) {
private val data = ArrayList<List<String>>()
val commandName: String
get() = this[0, 0]
val isOK: Boolean
get() = "OK" == this[0, 1]
init {
val rx = "[^\"\\s]+|\"(\\\\.|[^\\\\\"])*\""
val scanner = Scanner(response.trim { it <= ' ' })
while (scanner.hasNextLine()) {
val line = ArrayList<String>()
var next: String? = scanner.findWithinHorizon(rx, 0)
while (next != null) {
line.add(next)
next = scanner.findInLine(rx)
}
data.add(line)
}
}
fun errorCode(): Int {
return if (isOK) {
-1
} else {
Integer.parseInt(get(1, 1))
}
}
val errorDescription: String
get() {
return if (isOK) {
throw RuntimeException("Not a error")
} else {
get(2, 1)
}
}
operator fun get(lineNo: Int, columnNo: Int): String = data[lineNo][columnNo]
}
override fun stopMeasurement() { override fun stopMeasurement() {
super.stopMeasurement()
runOnDeviceThread { runOnDeviceThread {
stopPeakJump() stopPeakJump()
} }
super.stopMeasurement()
} }
override fun startMeasurement(oldMeta: Meta?, newMeta: Meta) { override fun startMeasurement(oldMeta: Meta?, newMeta: Meta) {
@ -322,7 +282,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
val filterMode = meta.getString("filterMode", "PeakAverage") val filterMode = meta.getString("filterMode", "PeakAverage")
val accuracy = meta.getInt("accuracy", 5) val accuracy = meta.getInt("accuracy", 5)
//PENDING вставить остальные параметры? //PENDING вставить остальные параметры?
sendAndWait("MeasurementRemoveAll") sendAndWait("MeasurementRemoveAll", Duration.ofMillis(200))
// val peakMap: MutableMap<Int, String> = LinkedHashMap() // val peakMap: MutableMap<Int, String> = LinkedHashMap()
@ -393,6 +353,55 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
notifyMeasurementState(MeasurementState.STOPPED) notifyMeasurementState(MeasurementState.STOPPED)
} }
/**
* The MKS response as two-dimensional array of strings
*/
class MspResponse(response: String) {
private val data = ArrayList<List<String>>()
val commandName: String
get() = this[0, 0]
val isOK: Boolean
get() = "OK" == this[0, 1]
init {
val rx = "[^\"\\s]+|\"(\\\\.|[^\\\\\"])*\""
val scanner = Scanner(response.trim { it <= ' ' })
while (scanner.hasNextLine()) {
val line = ArrayList<String>()
var next: String? = scanner.findWithinHorizon(rx, 0)
while (next != null) {
line.add(next)
next = scanner.findInLine(rx)
}
data.add(line)
}
}
fun errorCode(): Int {
return if (isOK) {
-1
} else {
Integer.parseInt(get(1, 1))
}
}
val errorDescription: String
get() {
return if (isOK) {
throw RuntimeException("Not a error")
} else {
get(2, 1)
}
}
operator fun get(lineNo: Int, columnNo: Int): String = data[lineNo][columnNo]
}
companion object { companion object {
const val MSP_DEVICE_TYPE = "numass.msp" const val MSP_DEVICE_TYPE = "numass.msp"
const val CONTROLLED_STATE = "controlled" const val CONTROLLED_STATE = "controlled"

View File

@ -64,41 +64,6 @@ class SpectrumView(
private val data: ObservableMap<String, NumassSet> = FXCollections.observableHashMap(); private val data: ObservableMap<String, NumassSet> = FXCollections.observableHashMap();
val isEmpty = booleanBinding(data) { data.isEmpty() } val isEmpty = booleanBinding(data) { data.isEmpty() }
/*
<BorderPane fx:id="spectrumPlotPane" prefHeight="200.0" prefWidth="200.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<VBox>
<Label text="Lo channel"/>
<TextField fx:id="lowChannelField" prefWidth="60.0"/>
</VBox>
<RangeSlider fx:id="channelSlider" accessibleRole="SLIDER"
highValue="1900.0" lowValue="300.0" majorTickUnit="500.0"
max="4000.0" minorTickCount="5" prefHeight="38.0"
prefWidth="276.0" showTickLabels="true" showTickMarks="true">
<padding>
<Insets left="10.0" right="10.0"/>
</padding>
</RangeSlider>
<VBox>
<Label text="Up channel"/>
<TextField fx:id="upChannelField" prefWidth="60.0"/>
</VBox>
<Separator orientation="VERTICAL"/>
<VBox>
<Label text="Dead time (us)"/>
<TextField fx:id="dTimeField" prefHeight="25.0" prefWidth="0.0"
text="7.2"/>
</VBox>
<Separator orientation="VERTICAL"/>
<Pane minWidth="0.0" HBox.hgrow="ALWAYS"/>
<Button fx:id="spectrumExportButton" mnemonicParsing="false" text="Export"/>
</ToolBar>
</top>
</BorderPane>
*/
override val root = borderpane { override val root = borderpane {
top { top {
toolbar { toolbar {

View File

@ -122,7 +122,7 @@ class StorageView(private val context: Context = Global) : View(title = "Numass
isSelected = false isSelected = false
LogFragment().apply { LogFragment().apply {
addLogHandler(context.logger) addLogHandler(context.logger)
bindWindow(selectedProperty()) bindWindow(this@togglebutton, selectedProperty())
} }
} }
} }