Automatic diff
This commit is contained in:
parent
4372f46055
commit
e99fe84053
@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Alexander Nozik.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package inr.numass.control.magnet.fx
|
|
||||||
|
|
||||||
import tornadofx.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Alexander Nozik
|
|
||||||
*/
|
|
||||||
class MagnetControllerApp : App() {
|
|
||||||
|
|
||||||
//
|
|
||||||
// private lateinit var device: LambdaHub
|
|
||||||
//
|
|
||||||
// @Throws(IOException::class, ControlException::class)
|
|
||||||
// override fun start(stage: Stage) {
|
|
||||||
// Locale.setDefault(Locale.US)// чтобы отделение десятичных знаков было точкой
|
|
||||||
// val rootLogger = LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
|
|
||||||
//
|
|
||||||
// val logLevel = parameters.named.getOrDefault("logLevel", "INFO")
|
|
||||||
//
|
|
||||||
// rootLogger.level = Level.valueOf(logLevel)
|
|
||||||
//
|
|
||||||
// val logFile = parameters.named["logFile"]
|
|
||||||
//
|
|
||||||
// if (logFile != null) {
|
|
||||||
// val appender = FileAppender<ILoggingEvent>()
|
|
||||||
// appender.file = logFile
|
|
||||||
// appender.context = rootLogger.loggerContext
|
|
||||||
// appender.start()
|
|
||||||
// rootLogger.addAppender(appender)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// val configFileName = parameters.named
|
|
||||||
// val config = MetaFileReader.instance().read(context,)
|
|
||||||
//
|
|
||||||
//// val portName = (parameters.named as java.util.Map<String, String>).getOrDefault("port", "virtual")
|
|
||||||
////
|
|
||||||
//// if (portName == "virtual") {
|
|
||||||
//// handler = VirtualLambdaPort("COM12", 1, 2, 3, 4)
|
|
||||||
//// } else {
|
|
||||||
//// handler = PortFactory.getPort(portName)
|
|
||||||
//// //TODO add meta reader here
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// sourceController = SafeLambdaMagnet("SOURCE", handler, 1)
|
|
||||||
//// pinchController = SafeLambdaMagnet("PINCH", handler, 2)
|
|
||||||
//// conusController = SafeLambdaMagnet("CONUS", handler, 3)
|
|
||||||
//// detectorController = SafeLambdaMagnet("DETECTOR", handler, 4)
|
|
||||||
////
|
|
||||||
//// conusController.bindTo(pinchController, 30.0)
|
|
||||||
////
|
|
||||||
//// controllers.add(sourceController)
|
|
||||||
//// sourceController.speed = 4.0
|
|
||||||
//// controllers.add(pinchController)
|
|
||||||
//// controllers.add(conusController)
|
|
||||||
//// controllers.add(detectorController)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// val showConfirmation = java.lang.Boolean.parseBoolean((parameters.named as java.util.Map<String, String>).getOrDefault("confirmOut", "false"))
|
|
||||||
//
|
|
||||||
// val vbox = VBox(5.0)
|
|
||||||
// var height = 0.0
|
|
||||||
// var width = 0.0
|
|
||||||
// for (controller in controllers) {
|
|
||||||
// val comp = MagnetControllerComponent.build(controller)
|
|
||||||
// width = Math.max(width, comp.prefWidth)
|
|
||||||
// height += comp.prefHeight + 5
|
|
||||||
// if (!showConfirmation) {
|
|
||||||
// comp.setShowConfirmation(showConfirmation)
|
|
||||||
// }
|
|
||||||
// vbox.children.add(comp)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// val scene = Scene(vbox, width, height)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// stage.title = "Numass magnet view"
|
|
||||||
// stage.scene = scene
|
|
||||||
// stage.isResizable = false
|
|
||||||
// stage.show()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Throws(Exception::class)
|
|
||||||
// override fun stop() {
|
|
||||||
// super.stop() //To change body of generated methods, choose Tools | Templates.
|
|
||||||
// for (magnet in controllers) {
|
|
||||||
// magnet.stopMonitorTask()
|
|
||||||
// magnet.stopUpdateTask()
|
|
||||||
// }
|
|
||||||
// if (handler.isOpen) {
|
|
||||||
// handler.close()
|
|
||||||
// }
|
|
||||||
// System.exit(0)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// companion object {
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param args the command line arguments
|
|
||||||
// */
|
|
||||||
// @JvmStatic
|
|
||||||
// fun main(args: Array<String>) {
|
|
||||||
// Application.launch(*args)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
@ -39,6 +39,7 @@ import hep.dataforge.tables.ValuesListener
|
|||||||
import hep.dataforge.values.ValueType
|
import hep.dataforge.values.ValueType
|
||||||
import inr.numass.control.DeviceView
|
import inr.numass.control.DeviceView
|
||||||
import inr.numass.control.NumassStorageConnection
|
import inr.numass.control.NumassStorageConnection
|
||||||
|
import inr.numass.control.msp.MspDevice.Companion.SELECTED_STATE
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ import java.util.*
|
|||||||
)
|
)
|
||||||
@StateDefs(
|
@StateDefs(
|
||||||
StateDef(value = ValueDef(name = "controlled", info = "Connection with the device itself"), writable = true),
|
StateDef(value = ValueDef(name = "controlled", info = "Connection with the device itself"), writable = true),
|
||||||
|
StateDef(ValueDef(name = SELECTED_STATE)),
|
||||||
StateDef(value = ValueDef(name = "storing", info = "Define if this device is currently writes to storage"), writable = true),
|
StateDef(value = ValueDef(name = "storing", info = "Define if this device is currently writes to storage"), writable = true),
|
||||||
StateDef(value = ValueDef(name = "filament", info = "The number of filament in use"), writable = true),
|
StateDef(value = ValueDef(name = "filament", info = "The number of filament in use"), writable = true),
|
||||||
StateDef(value = ValueDef(name = "filamentOn", info = "Mass-spectrometer filament on"), writable = true),
|
StateDef(value = ValueDef(name = "filamentOn", info = "Mass-spectrometer filament on"), writable = true),
|
||||||
@ -62,18 +64,22 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
|
|
||||||
// private var measurementDelegate: Consumer<MspResponse>? = null
|
// private var measurementDelegate: Consumer<MspResponse>? = null
|
||||||
|
|
||||||
val selected: Boolean by valueState("selected").booleanDelegate
|
//val selected: Boolean by valueState("selected").booleanDelegate
|
||||||
|
|
||||||
var controlled = valueState(CONTROLLED_STATE) { _, value ->
|
var controlled = valueState(CONTROLLED_STATE) { _, value ->
|
||||||
control(value.booleanValue())
|
control(value.booleanValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
var filament by valueState("filament") { old, value ->
|
var filament by valueState("filament") { old, value ->
|
||||||
selectFilament(value.intValue())
|
if (old != value) {
|
||||||
|
selectFilament(value.intValue())
|
||||||
|
}
|
||||||
}.intDelegate
|
}.intDelegate
|
||||||
|
|
||||||
var filamentOn = valueState("filamentOn") { _, value ->
|
var filamentOn = valueState("filamentOn") { old, value ->
|
||||||
setFilamentOn(value.booleanValue())
|
if (old != value) {
|
||||||
|
setFilamentOn(value.booleanValue())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
|
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
|
||||||
@ -124,42 +130,47 @@ 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 {
|
||||||
val sensorName: String
|
synchronized(this) {
|
||||||
if (on) {
|
logger.info("Starting initialization sequence")
|
||||||
//ensure device is connected
|
if (on != this.controlled.booleanValue) {
|
||||||
connected.set(true)
|
val sensorName: String
|
||||||
var response = commandAndWait("Sensors")
|
if (on) {
|
||||||
if (response.isOK) {
|
//ensure device is connected
|
||||||
sensorName = response[2, 1]
|
connected.setAndWait(true)
|
||||||
} else {
|
var response = commandAndWait("Sensors")
|
||||||
notifyError(response.errorDescription, null)
|
if (response.isOK) {
|
||||||
return false
|
sensorName = response[2, 1]
|
||||||
}
|
} else {
|
||||||
//PENDING определеить в конфиге номер прибора
|
notifyError(response.errorDescription, null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
//PENDING определеить в конфиге номер прибора
|
||||||
|
|
||||||
response = commandAndWait("Select", sensorName)
|
response = commandAndWait("Select", sensorName)
|
||||||
if (response.isOK) {
|
if (response.isOK) {
|
||||||
updateState("selected", true)
|
updateState("selected", true)
|
||||||
} else {
|
} else {
|
||||||
notifyError(response.errorDescription, null)
|
notifyError(response.errorDescription, null)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
response = commandAndWait("Control", "inr.numass.msp", "1.1")
|
response = commandAndWait("Control", "inr.numass.msp", "1.1")
|
||||||
if (response.isOK) {
|
if (response.isOK) {
|
||||||
|
controlled.update(true)
|
||||||
updateState("controlled", true)
|
} else {
|
||||||
|
notifyError(response.errorDescription, null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// connected = true;
|
||||||
|
updateState(PortSensor.CONNECTED_STATE, true)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return !commandAndWait("Release").isOK
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
notifyError(response.errorDescription, null)
|
return on
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
// connected = true;
|
|
||||||
updateState(PortSensor.CONNECTED_STATE, true)
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return !commandAndWait("Release").isOK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,8 +212,14 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
*/
|
*/
|
||||||
@Throws(PortException::class)
|
@Throws(PortException::class)
|
||||||
private fun commandAndWait(commandName: String, vararg parameters: Any): MspResponse {
|
private fun commandAndWait(commandName: String, vararg parameters: Any): MspResponse {
|
||||||
send(buildCommand(commandName, *parameters))
|
val command = buildCommand(commandName, *parameters)
|
||||||
val response = connection.waitFor(TIMEOUT) { str: String -> str.trim { it <= ' ' }.startsWith(commandName) }
|
if (debug) {
|
||||||
|
logger.info("SEND: $command")
|
||||||
|
}
|
||||||
|
val response = connection.sendAndWait(command, TIMEOUT) { str: String -> str.trim { it <= ' ' }.startsWith(commandName) }
|
||||||
|
if (debug) {
|
||||||
|
logger.info("RECEIVE:\n$response")
|
||||||
|
}
|
||||||
return MspResponse(response)
|
return MspResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,19 +297,6 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
|||||||
operator fun get(lineNo: Int, columnNo: Int): String = data[lineNo][columnNo]
|
operator fun get(lineNo: Int, columnNo: Int): String = data[lineNo][columnNo]
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Throws(MeasurementException::class)
|
|
||||||
// override fun createMeasurement(): PeakJumpMeasurement {
|
|
||||||
// val measurementMeta = meta.getMeta("peakJump")
|
|
||||||
// val s = measurementMeta.getString("type", "peakJump")
|
|
||||||
// if (s == "peakJump") {
|
|
||||||
// val measurement = PeakJumpMeasurement(measurementMeta)
|
|
||||||
// this.measurementDelegate = measurement
|
|
||||||
// return measurement
|
|
||||||
// } else {
|
|
||||||
// throw MeasurementException("Unknown measurement type")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
override fun stopMeasurement() {
|
override fun stopMeasurement() {
|
||||||
super.stopMeasurement()
|
super.stopMeasurement()
|
||||||
execute {
|
execute {
|
||||||
@ -393,6 +397,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"
|
const val CONTROLLED_STATE = "controlled"
|
||||||
|
const val SELECTED_STATE = "selected"
|
||||||
|
|
||||||
private val TIMEOUT = Duration.ofMillis(200)
|
private val TIMEOUT = Duration.ofMillis(200)
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
|
|||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
padding = Insets(5.0, 0.0, 0.0, 0.0)
|
padding = Insets(5.0, 0.0, 0.0, 0.0)
|
||||||
disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE))
|
disableProperty().bind(device.controlled.asBooleanProperty().not())
|
||||||
device.filamentOn.asBooleanProperty().bindBidirectional(selectedProperty())
|
device.filamentOn.asBooleanProperty().bindBidirectional(selectedProperty())
|
||||||
}
|
}
|
||||||
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {
|
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {
|
||||||
|
@ -118,7 +118,9 @@ fun Node.deviceStateToggle(connection: DeviceDisplayFX<*>, state: String, title:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
connection.valueStateProperty(state).onChange {
|
connection.valueStateProperty(state).onChange {
|
||||||
isSelected = it?.booleanValue() ?: false
|
runLater {
|
||||||
|
isSelected = it?.booleanValue() ?: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deviceStateIndicator(connection, state, false)
|
deviceStateIndicator(connection, state, false)
|
||||||
@ -143,3 +145,8 @@ fun BorderPane.plot(plottable: Plottable, metaTransform: (KMetaBuilder.() -> Uni
|
|||||||
center = PlotContainer(frame).root
|
center = PlotContainer(frame).root
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//val ValueState.property: ObjectProperty<Value>
|
||||||
|
// get() {
|
||||||
|
// ret
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user