diff --git a/app/src/main/java/com/casic/common/detector/gd/base/SerialPortBaseActivity.kt b/app/src/main/java/com/casic/common/detector/gd/base/SerialPortBaseActivity.kt index 1d0c9e3..a0f3460 100644 --- a/app/src/main/java/com/casic/common/detector/gd/base/SerialPortBaseActivity.kt +++ b/app/src/main/java/com/casic/common/detector/gd/base/SerialPortBaseActivity.kt @@ -102,10 +102,14 @@ fun sendSerialPortCommand(command: Int) { if (serialPorts.isNotEmpty()) { - val outStream = serialPorts.first().outputStream - outStream.write(command) - outStream.flush() - Log.d(kTag, "sendSerialPortCommand: $command") + try { + val outStream = serialPorts.first().outputStream + outStream.write(command) + outStream.flush() + Log.d(kTag, "sendSerialPortCommand: $command") + } catch (e: IOException) { + e.printStackTrace() + } } } @@ -113,10 +117,14 @@ * 停止串口数据传输 * */ fun stopSerialPortCommand() { - if (serialPorts.isNotEmpty()) { - val outStream = serialPorts.first().outputStream - outStream.write(SerialPortCommand.STOP_SERIAL_PORT_DATA) - outStream.flush() + try { + if (serialPorts.isNotEmpty()) { + val outStream = serialPorts.first().outputStream + outStream.write(SerialPortCommand.STOP_SERIAL_PORT_DATA) + outStream.flush() + } + } catch (e: IOException) { + e.printStackTrace() } }