private void openPort(String id) {
System.out.printf("opening port %s @ %d bauds\n", id, this.baudRate);
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(id);
if (portId.isCurrentlyOwned()) {
System.err.printf("error: %s port currently in use\n", id);
return;
}
CommPort commPort = portId.open(this.getClass().getName(), 5000);
if (commPort instanceof SerialPort) {
this.port = (SerialPort) commPort;
this.port.setSerialPortParams(this.baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
this.portOut = this.port.getOutputStream();
} else {
System.err.printf("error: port %s is not serial\n", id);
return;
}
} catch (Exception e) {
System.err.printf("error: cannot find/open port %s\n", id);
System.err.printf("%s\n", e.getMessage());
}
}
SerialInterface.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:phil-cereals
作者:
评论列表
文章目录