Fixed part of motionMaster
This commit is contained in:
parent
44514cd477
commit
a9592d0372
@ -100,6 +100,7 @@ public abstract class AbstractAsynchronousPort(
|
||||
* Send a data packet via the port
|
||||
*/
|
||||
override suspend fun send(data: ByteArray) {
|
||||
check(isOpen){"The port is not opened"}
|
||||
outgoing.send(data)
|
||||
}
|
||||
|
||||
|
@ -45,10 +45,8 @@ fun ColumnScope.piMotionMasterAxis(
|
||||
axisName: String,
|
||||
axis: PiMotionMasterDevice.Axis,
|
||||
) {
|
||||
Row {
|
||||
Text(axisName)
|
||||
var min by remember { mutableStateOf(0f) }
|
||||
var max by remember { mutableStateOf(0f) }
|
||||
var max by remember { mutableStateOf(1f) }
|
||||
var targetPosition by remember { mutableStateOf(0f) }
|
||||
val position: Double by axis.composeState(PiMotionMasterDevice.Axis.position, 0.0)
|
||||
|
||||
@ -60,6 +58,10 @@ fun ColumnScope.piMotionMasterAxis(
|
||||
targetPosition = axis.read(PiMotionMasterDevice.Axis.position).toFloat()
|
||||
}
|
||||
|
||||
|
||||
Row {
|
||||
Text(axisName)
|
||||
|
||||
Column {
|
||||
Slider(
|
||||
value = position.toFloat(),
|
||||
@ -70,10 +72,10 @@ fun ColumnScope.piMotionMasterAxis(
|
||||
Slider(
|
||||
value = targetPosition,
|
||||
onValueChange = { newPosition ->
|
||||
targetPosition = newPosition
|
||||
scope.launch {
|
||||
axis.move(newPosition.toDouble())
|
||||
}
|
||||
targetPosition = newPosition
|
||||
},
|
||||
valueRange = min..max
|
||||
)
|
||||
@ -158,14 +160,14 @@ fun PiMotionMasterApp(device: PiMotionMasterDevice) {
|
||||
if (!connected) {
|
||||
device.launch {
|
||||
device.connect(host, port)
|
||||
}
|
||||
axes = device.axes
|
||||
}
|
||||
} else {
|
||||
device.launch {
|
||||
device.disconnect()
|
||||
}
|
||||
axes = null
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
|
@ -165,12 +165,12 @@ class PiMotionMasterDevice(
|
||||
}
|
||||
//Update port
|
||||
//address = portSpec.node
|
||||
port = portFactory(portSpec, context)
|
||||
propertyChanged(connected, true)
|
||||
port = portFactory(portSpec, context).apply { open() }
|
||||
// connector.open()
|
||||
//Initialize axes
|
||||
val idn = read(identity)
|
||||
failIfError { "Can't connect to $portSpec. Error code: $it" }
|
||||
propertyChanged(connected, true)
|
||||
logger.info { "Connected to $idn on $portSpec" }
|
||||
val ids = request("SAI?").map { it.trim() }
|
||||
if (ids != axes.keys.toList()) {
|
||||
|
@ -8,6 +8,8 @@ import io.ktor.util.InternalAPI
|
||||
import io.ktor.util.moveToByteArray
|
||||
import io.ktor.utils.io.writeAvailable
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.Global
|
||||
|
||||
@ -28,13 +30,12 @@ fun Context.launchPiDebugServer(port: Int, axes: List<String>): Job = launch(exc
|
||||
val input = socket.openReadChannel()
|
||||
val output = socket.openWriteChannel()
|
||||
|
||||
val sendJob = launch {
|
||||
virtualDevice.subscribe().collect {
|
||||
val sendJob = virtualDevice.subscribe().onEach {
|
||||
//println("Sending: ${it.decodeToString()}")
|
||||
output.writeAvailable(it)
|
||||
output.flush()
|
||||
}
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
|
||||
try {
|
||||
while (isActive) {
|
||||
|
Loading…
Reference in New Issue
Block a user