功能优化,增加心跳数据处理
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.shuwei.intelligent.shelves.serial
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.shuwei.intelligent.shelves.utils.hexToBytes
|
||||
import com.shuwei.intelligent.shelves.utils.toHexString2
|
||||
import io.github.jeadyx.jserialport.AndroidSerialPort
|
||||
@@ -38,7 +39,6 @@ object SerialPortManager {
|
||||
// 发送数据
|
||||
suspend fun send(data: String): Boolean {
|
||||
return try {
|
||||
// serialPort?.write(data.toByteArray())
|
||||
serialPort?.write(data.hexToBytes())
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
@@ -48,11 +48,12 @@ object SerialPortManager {
|
||||
}
|
||||
|
||||
// 启动接收协程
|
||||
@Suppress("DEPRECATION")
|
||||
@SuppressLint("DefaultLocale")
|
||||
fun startReceive(callback: (String) -> Unit) {
|
||||
scope.launch {
|
||||
while (isActive) {
|
||||
serialPort?.read()?.collect { buffer ->
|
||||
// val data = String(buffer)
|
||||
val data = buffer.toHexString2().toUpperCase()
|
||||
callback(data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user