|
|
@@ -34,7 +34,7 @@ class PortManager private constructor(
|
|
|
output.flush()
|
|
|
return true
|
|
|
} catch (e: IOException) {
|
|
|
-// Logger.e("PortManager", "串口写数据失败", e)
|
|
|
+ LogUtil.e("串口写数据失败 : ${e.message}")
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
|
@@ -59,7 +59,7 @@ class PortManager private constructor(
|
|
|
listener(data)
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
-// Logger.e("PortManager", "串口读取或处理异常", e)
|
|
|
+ LogUtil.e("串口读取或处理异常 : ${e.message}")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -82,9 +82,6 @@ class PortManager private constructor(
|
|
|
companion object {
|
|
|
|
|
|
private const val BUFFER_SIZE = 256
|
|
|
- private var plcThread: ScheduledExecutorService? = null
|
|
|
-
|
|
|
- var plcPort: PortManager? = null
|
|
|
|
|
|
/**
|
|
|
* 打开串口
|
|
|
@@ -98,21 +95,21 @@ class PortManager private constructor(
|
|
|
Executor.delayOnMain({
|
|
|
// 如果线程被阻塞达到 1 秒,则打断唤醒
|
|
|
if (blocked) {
|
|
|
-// Logger.w("PortManager", "超 0.5 秒未打开串口,打断唤醒")
|
|
|
+ LogUtil.w("超 0.5 秒未打开串口,打断唤醒")
|
|
|
thread.interrupt()
|
|
|
}
|
|
|
}, 500)
|
|
|
try {
|
|
|
val file = File(if(usb) "/dev/ttyUSB${port}" else "/dev/ttyS${port}")
|
|
|
-// Logger.i("PortManager", "连接 port file")
|
|
|
+ LogUtil.i("连接 port file")
|
|
|
SerialPort(file, bps, 0).run {
|
|
|
blocked = false
|
|
|
-// Logger.i("PortManager", "建立 SerialPort")
|
|
|
+ LogUtil.i("建立 SerialPort")
|
|
|
return PortManager(inputStream, outputStream)
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
blocked = false
|
|
|
-// Logger.e("PortManager", "异常", e)
|
|
|
+ LogUtil.e("异常 : ${e.message}")
|
|
|
// Tip.toast("串口[${port}, ${bps}, ${usb}]打开失败[${e.javaClass.simpleName}]${e.message}")
|
|
|
// synchronized(Tip) {
|
|
|
// Tip.audioNum(port)
|
|
|
@@ -131,7 +128,7 @@ class PortManager private constructor(
|
|
|
val port = 1
|
|
|
val bps = 9600
|
|
|
val usb = false
|
|
|
-// Logger.i("PortManager", "主控板 port = ${port}, bps = ${bps}, usb = ${usb}")
|
|
|
+ LogUtil.i("主控板 port = ${port}, bps = ${bps}, usb = $usb")
|
|
|
return open(port, bps, usb)
|
|
|
}
|
|
|
}
|