java读取modbus(串口,DTU(WIFI )也可 DTU(gprs)也可)协议数据 解释详细 踩坑完整 拿来就可以用的demo(下)

java读取modbus(串口,DTU(WIFI )也可 DTU(gprs)也可)协议数据 解释详细 踩坑完整 拿来就可以用的demo(下)福兮祸所伏 祸兮福所倚 现在发生在你身上的都是好事 福祸相伴 这些源码应该都可以看的懂 我就不解释了 public void Connect String comPort throws Exception 类似于串口连接 个人理解 this portIdentifi CommPortIden

大家好,我是讯享网,很高兴认识大家。

福兮祸所伏, 祸兮福所倚。(现在发生在你身上的都是好事,福祸相伴)  

这些源码应该都可以看的懂 我就不解释了。

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."); } } }

讯享网

那咱们就运行 ,结果。。。。。。。。。。。


讯享网

小讯
上一篇 2025-03-10 10:47
下一篇 2025-02-21 17:13

相关推荐

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