Updates to control using coroutines

This commit is contained in:
Alexander Nozik 2018-03-29 23:00:57 +03:00
parent 700707a7a9
commit f2d292b853
4 changed files with 33 additions and 28 deletions

View File

@ -143,11 +143,11 @@ abstract class DeviceDisplay<D : Device> : Component(), Connection, DeviceListen
}
}
override fun notifyDeviceStateChanged(device: Device, name: String, state: Value) {
override fun notifyStateChanged(device: Device, name: String, state: Value) {
bindings[name]?.invalidate()
}
override fun notifyDeviceStateChanged(device: Device, name: String, state: Meta) {
override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) {
metaBindings[name]?.invalidate()
}

View File

@ -12,6 +12,11 @@ import java.time.Instant
* Created by darksnake on 06-Dec-16.
*/
object ConsoleVac {
private fun Sensor.read():Double{
this.measure()
}
@Throws(Exception::class)
@JvmStatic
fun main(args: Array<String>) {
@ -33,7 +38,7 @@ object ConsoleVac {
var className: String = cli.getOptionValue("c") ?: throw RuntimeException("Vacuumeter class not defined")
if (!className.contains(".")) {
className = "inr.numass.readvac.devices." + className
className = "inr.numass.readvac.devices.$className"
}
val name = cli.getOptionValue("n", "sensor")

View File

@ -34,6 +34,7 @@ import inr.numass.control.StorageHelper
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.time.delay
import java.time.Duration
import java.time.Instant
import java.util.*
import java.util.stream.Stream
@ -53,11 +54,11 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection<S
notifyResult(it)
}
override fun notifyDeviceStateChanged(device: Device, name: String, state: Value) {
override fun notifyStateChanged(device: Device, name: String, state: Value) {
}
override fun notifyDeviceStateChanged(device: Device, name: String, state: Meta) {
override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) {
if (name == MEASUREMENT_RESULT_STATE) {
collector.put(device.name, state.getValue("value"))
}
@ -110,8 +111,8 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection<S
}
private fun notifyResult(values: Values) {
notifyResult(produceResult(values.toMeta()))
private fun notifyResult(values: Values, timestamp: Instant = Instant.now()) {
super.notifyResult(values,timestamp)
helper.push(values)
}

View File

@ -8,9 +8,11 @@ package inr.numass.control.readvac
import hep.dataforge.control.devices.Device
import hep.dataforge.control.devices.PortSensor.Companion.CONNECTED_STATE
import hep.dataforge.control.devices.Sensor
import hep.dataforge.kodex.stringValue
import hep.dataforge.kodex.timeValue
import hep.dataforge.kodex.value
import hep.dataforge.meta.Meta
import hep.dataforge.values.Value
import inr.numass.control.DeviceDisplay
import inr.numass.control.switch
import javafx.application.Platform
@ -48,27 +50,13 @@ open class VacDisplay : DeviceDisplay<Sensor>() {
return VacView();
}
override fun evaluateDeviceException(device: Device, message: String, exception: Throwable) {
if (!message.isEmpty()) {
Platform.runLater {
status = "ERROR: $message"
}
}
}
override fun onMeasurementFailed(measurement: Measurement<*>, exception: Throwable) {
Platform.runLater {
value = "Err"
}
}
fun message(message: String) {
Platform.runLater {
status = message
}
}
fun onResult(res: Any, time: Instant) {
private fun onResult(res: Any, time: Instant) {
val result = Number::class.java.cast(res).toDouble()
val resString = FORMAT.format(result)
Platform.runLater {
@ -78,19 +66,30 @@ open class VacDisplay : DeviceDisplay<Sensor>() {
}
}
override fun notifyDeviceStateChanged(device: Device, name: String, state: Meta) {
super.notifyDeviceStateChanged(device, name, state)
override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) {
super.notifyMetaStateChanged(device, name, state)
when (name) {
Sensor.MEASUREMENT_RESULT_STATE -> {
if(state.getBoolean(Sensor.RESULT_SUCCESS)) {
val res by state.value(Sensor.RESULT_VALUE)
val time by state.timeValue(Sensor.RESULT_TIMESTAMP)
onResult(res, time)
} else{
Platform.runLater {
value = "Err"
}
}
}
Sensor.MEASUREMENT_ERROR_STATE -> {
val message by state.stringValue("message")
message(message)
}
}
}
}
}
override fun notifyStateChanged(device: Device, name: String, state: Value) {
super.notifyStateChanged(device, name, state)
}
fun getTitle(): String {