注明:图片是串口调试软件接收的信息。按照如下操作无法解析出来,请大神帮忙,谢谢。
以下是我web程序的配置。
第一步导入 comm2.0.jar 配置环境
第二步 打开COM3 端口
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("COM3");
SerialPort sPort = null;
try {
sPort = (SerialPort) portIdentifier.open("COM3", 2000);
} catch (PortInUseException e) {//如果端口被占用就抛出这个异常
throw new Exception(e.getMessage());
}
第三步 设置串口参数
if (sPort instanceof SerialPort) {
sPort = (SerialPort) sPort;
try {
//设置一下串口的波特率等参数
int baudrate = 115200;
//int data
sPort.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
throw new Exception();
}
第四步 取出数据
InputStream is = new BufferedInputStream(sPort.getInputStream());
System.out.println("sdsdsds==="+is.read());
第五步 无法解析出来 求大神指点,小弟感激不尽。