Commit fffed4bb authored by zhushanglei's avatar zhushanglei

init

parent cc86d1bc
......@@ -141,10 +141,10 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
serialPort.closePort();
}
private int writeComm(SerialPort serialPort, byte[] data) throws InterruptedException {
if(serialPort == null || !serialPort.isOpen()){
logger.info("COM口未打开");
return -2;
}
// if(serialPort == null || !serialPort.isOpen()){
// logger.info("COM口未打开");
// return -2;
// }
int result = serialPort.writeBytes(data,data.length);//将字节数组全部写入串口
if(result != -1){
logger.info("COM口已成功写入数据");
......@@ -155,10 +155,10 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
}
private String readComm(SerialPort serialPort) {
if (serialPort == null || !serialPort.isOpen()) {
logger.error("COM口未打开");
return null;
}
// if (serialPort == null || !serialPort.isOpen()) {
// logger.error("COM口未打开");
// return null;
// }
String readData = "";
while(serialPort.bytesAvailable()>0){ //循环读取所有的返回数据。如果可读取数据长度为0或-1,则停止读取
byte[] newData = new byte[serialPort.bytesAvailable()];//创建一个字节数组,长度为可读取的字节长度
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment