From 00c66da847b7b1b899dcef74875c51874707be18 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 2 Mar 2023 10:07:54 +0300 Subject: [PATCH] Update pressure sensor demo --- .../kscience/controls/spec/DeviceSpec.kt | 3 +-- .../sciprog/devices/mks/MksPdr900Device.kt | 19 +++++++++++++------ .../pimotionmaster/PiMotionMasterDevice.kt | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt index 00f5ad5..83364ee 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt @@ -236,8 +236,7 @@ public fun > DeviceSpec.logicalProperty( override val converter: MetaConverter = converter - override suspend fun read(device: D): T? = - device.getProperty(propertyName)?.let(converter::metaToObject) + override suspend fun read(device: D): T? = device.getProperty(propertyName)?.let(converter::metaToObject) override suspend fun write(device: D, value: T): Unit = device.writeProperty(propertyName, converter.objectToMeta(value)) diff --git a/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt b/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt index 7ba1e03..304102e 100644 --- a/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt +++ b/demo/mks-pdr900/src/main/kotlin/center/sciprog/devices/mks/MksPdr900Device.kt @@ -14,8 +14,12 @@ import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.int import space.kscience.dataforge.meta.transformations.MetaConverter + +//TODO this device is not tested class MksPdr900Device(context: Context, meta: Meta) : DeviceBySpec(MksPdr900Device, context, meta) { + private val address by meta.int(253) + private val portDelegate = lazy { val ports = context.request(Ports) ports.buildPort(meta["port"] ?: error("Port is not defined in device configuration")).synchronous() @@ -23,9 +27,6 @@ class MksPdr900Device(context: Context, meta: Meta) : DeviceBySpec(), Factory { - override fun build(context: Context, meta: Meta): MksPdr900Device = MksPdr900Device(context, meta) + const val DEFAULT_CHANNEL: Int = 5 + + override fun build(context: Context, meta: Meta): MksPdr900Device = MksPdr900Device(context, meta) val powerOn by booleanProperty(read = MksPdr900Device::readPowerOn, write = MksPdr900Device::writePowerOn) - val value by doubleProperty(read = MksPdr900Device::readChannelData) + val channel by logicalProperty(MetaConverter.int) + + val value by doubleProperty(read = { + readChannelData(channel.get() ?: DEFAULT_CHANNEL) + }) val error by logicalProperty(MetaConverter.string) diff --git a/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt b/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt index 3b00e0c..d6c9482 100644 --- a/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt +++ b/demo/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt @@ -194,9 +194,9 @@ class PiMotionMasterDevice( val disconnect by metaAction({ info = "Disconnect the program from the device if it is connected" }) { - if (port != null) { + port?.let{ stop() - port?.close() + it.close() } port = null updateLogical(connected, false)