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