Fix nullability in actions
This commit is contained in:
parent
25d7fe0a8e
commit
7b792afd7a
@ -162,7 +162,7 @@ class PiMotionMasterDevice(
|
|||||||
send("STP")
|
send("STP")
|
||||||
}
|
}
|
||||||
|
|
||||||
val connect by metaAction(descriptorBuilder = {
|
val connect by action(MetaConverter.meta, MetaConverter.unit, descriptorBuilder = {
|
||||||
info = "Connect to specific port and initialize axis"
|
info = "Connect to specific port and initialize axis"
|
||||||
}) { portSpec ->
|
}) { portSpec ->
|
||||||
//Clear current actions if present
|
//Clear current actions if present
|
||||||
@ -171,11 +171,10 @@ class PiMotionMasterDevice(
|
|||||||
}
|
}
|
||||||
//Update port
|
//Update port
|
||||||
//address = portSpec.node
|
//address = portSpec.node
|
||||||
port = portFactory(portSpec ?: Meta.EMPTY, context)
|
port = portFactory(portSpec, context)
|
||||||
updateLogical(connected, true)
|
updateLogical(connected, true)
|
||||||
// connector.open()
|
// connector.open()
|
||||||
//Initialize axes
|
//Initialize axes
|
||||||
if (portSpec != null) {
|
|
||||||
val idn = read(identity)
|
val idn = read(identity)
|
||||||
failIfError { "Can't connect to $portSpec. Error code: $it" }
|
failIfError { "Can't connect to $portSpec. Error code: $it" }
|
||||||
logger.info { "Connected to $idn on $portSpec" }
|
logger.info { "Connected to $idn on $portSpec" }
|
||||||
@ -188,19 +187,16 @@ class PiMotionMasterDevice(
|
|||||||
execute(initialize)
|
execute(initialize)
|
||||||
failIfError()
|
failIfError()
|
||||||
}
|
}
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
val disconnect by metaAction({
|
val disconnect by unitAction({
|
||||||
info = "Disconnect the program from the device if it is connected"
|
info = "Disconnect the program from the device if it is connected"
|
||||||
}) {
|
}) {
|
||||||
port?.let{
|
port?.let {
|
||||||
execute(stop)
|
execute(stop)
|
||||||
it.close()
|
it.close()
|
||||||
}
|
}
|
||||||
port = null
|
port = null
|
||||||
updateLogical(connected, false)
|
updateLogical(connected, false)
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -212,7 +208,7 @@ class PiMotionMasterDevice(
|
|||||||
|
|
||||||
class Axis(
|
class Axis(
|
||||||
val mm: PiMotionMasterDevice,
|
val mm: PiMotionMasterDevice,
|
||||||
val axisId: String
|
val axisId: String,
|
||||||
) : DeviceBySpec<Axis>(Axis, mm.context) {
|
) : DeviceBySpec<Axis>(Axis, mm.context) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,7 +240,7 @@ class PiMotionMasterDevice(
|
|||||||
|
|
||||||
private fun axisBooleanProperty(
|
private fun axisBooleanProperty(
|
||||||
command: String,
|
command: String,
|
||||||
descriptorBuilder: PropertyDescriptor.() -> Unit = {}
|
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
||||||
) = booleanProperty(
|
) = booleanProperty(
|
||||||
read = {
|
read = {
|
||||||
readAxisBoolean("$command?")
|
readAxisBoolean("$command?")
|
||||||
@ -257,7 +253,7 @@ class PiMotionMasterDevice(
|
|||||||
|
|
||||||
private fun axisNumberProperty(
|
private fun axisNumberProperty(
|
||||||
command: String,
|
command: String,
|
||||||
descriptorBuilder: PropertyDescriptor.() -> Unit = {}
|
descriptorBuilder: PropertyDescriptor.() -> Unit = {},
|
||||||
) = doubleProperty(
|
) = doubleProperty(
|
||||||
read = {
|
read = {
|
||||||
mm.requestAndParse("$command?", axisId)[axisId]?.toDoubleOrNull()
|
mm.requestAndParse("$command?", axisId)[axisId]?.toDoubleOrNull()
|
||||||
@ -334,11 +330,11 @@ class PiMotionMasterDevice(
|
|||||||
info = "Velocity value for closed-loop operation"
|
info = "Velocity value for closed-loop operation"
|
||||||
}
|
}
|
||||||
|
|
||||||
val move by metaAction {
|
val move by action(MetaConverter.meta, MetaConverter.unit) {
|
||||||
val target = it.double ?: it?.get("target").double ?: error("Unacceptable target value $it")
|
val target = it.double ?: it["target"].double ?: error("Unacceptable target value $it")
|
||||||
write(closedLoop, true)
|
write(closedLoop, true)
|
||||||
//optionally set velocity
|
//optionally set velocity
|
||||||
it?.get("velocity").double?.let { v ->
|
it["velocity"].double?.let { v ->
|
||||||
write(velocity, v)
|
write(velocity, v)
|
||||||
}
|
}
|
||||||
write(targetPosition, target)
|
write(targetPosition, target)
|
||||||
@ -347,7 +343,6 @@ class PiMotionMasterDevice(
|
|||||||
read(position)
|
read(position)
|
||||||
delay(200)
|
delay(200)
|
||||||
}
|
}
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user