设备联调优化

This commit is contained in:
马增飞
2025-11-06 19:29:18 +08:00
parent a355828bab
commit 647ec0dcb7
22 changed files with 488 additions and 174 deletions
@@ -7,6 +7,7 @@ import io.github.jeadyx.jserialport.AndroidSerialPort
import io.github.jeadyx.jserialport.SerialPort
import io.github.jeadyx.jserialport.SerialPortFactory
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collectLatest
import java.nio.charset.Charset
import java.util.Locale
@@ -53,9 +54,14 @@ object SerialPortManager {
fun startReceive(callback: (String) -> Unit) {
scope.launch {
while (isActive) {
serialPort?.read()?.collect { buffer ->
val data = buffer.toHexString2().toUpperCase()
callback(data)
try {
val flow = serialPort?.read()
flow?.collect { buffer ->
val data = buffer.toHexString2().toUpperCase()
callback(data)
}
} catch (e: Exception) {
e.printStackTrace()
}
delay(50)
}