注明:图片是串口调试软件接收的信息。按照如下操作无法解析出来,请大神帮忙,谢谢。以下是我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());
第五步 无法解析出来 求大神指点,小弟感激不尽。
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());
第五步 无法解析出来 求大神指点,小弟感激不尽。
解决方案 »
- 请教个SPRING2.0里 RowMapperResultSetExtractor的问题
- 参加武汉达内java培训,有经验的给点意见啊,感谢!广告请绕行!
- 如果想要函数 fun() 返回 值为int 与 long ,那么函数原型怎么写?
- hibernate中save和merg的区别
- TomCat中设置虚拟目录的问题?
- 连JDBC时出的奇怪问题,大虾们帮一把阿
- 新手的困惑:调用EJB
- 怎样用jboss下运行servlet编好的class文件 (求救!)
- 如何在websphere 里配置数据库连接池呢?谢谢!!
- 关于EJB的问题,高手帮忙!
- 使用s:iterator遍历嵌套list,EL表达式出错,s:property可以输出
- 电商项目
2 web程序?一旦出现并发就会抢串口,最好写成客户端软件