福兮祸所伏, 祸兮福所倚。(现在发生在你身上的都是好事,福祸相伴)
这些源码应该都可以看的懂 我就不解释了。
public void Connect(String comPort) throws Exception {// 类似于串口连接(个人理解)this.portIdentifier = CommPortIdentifier.getPortIdentifier(comPort);if (this.portIdentifier.isCurrentlyOwned()) {System.out.println("Error: Port is currently in use");} else {int timeout = 2000;// 串口对象CommPort commPort = this.portIdentifier.open(this.getClass().getName(), timeout);if (commPort instanceof SerialPort) {this.serialPort = (SerialPort)commPort;this.serialPort.setSerialPortParams(9600, 8, 1, 2);this.serialPort.enableReceiveTimeout(1000);this.serialPort.disableReceiveThreshold();this.in = this.serialPort.getInputStream();this.