福兮祸所伏, 祸兮福所倚。(现在发生在你身上的都是好事,福祸相伴)
这些源码应该都可以看的懂 我就不解释了。
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.out = this.serialPort.getOutputStream(); this.serialflag = true; } else { System.out.println("Error: Only serial ports are handled by this example."); } } }
讯享网
那咱们就运行 ,结果。。。。。。。。。。。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/71713.html