且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Modbus RTU协议主控实现

更新时间:2022-12-05 12:43:56

使用 NModbus [ ^ ]

请参阅: http ://www.mesta-automation.com/modbus-with-c-sharp-libraries-examples/ [ ^ ]。



但你需要看清楚:Modbus / TCP通过TCP / IP工作,Modbus / RTU可以通过RS232和RS485等串行协议工作。你不能只是混合它们。如果digi模块不是modbus网关,它将无法工作。正如我所见,Digi模块可以编程为网关,但你真的想要这个吗?

如果PC软件将轮询PIC,则需要在PIC上实现Digi Modbus / TCP从站(非主站)+ Modbus / RTU主站和Modbus / RTU从站。

但是,使用现成的设备可能会更便宜。像这样: http://www.moxa.com/product/MGate_MB3180_3280_3480.htm [ ^ ]。甚至更便宜: http://www.shjelectronic.com/EthernetModules.htm [ ^ ]

即使Digi拥有自己的网关:http://www.digi.com/products/serial-servers/industrial-hardened-serial- servers / digioneia [ ^ ]



当然,如果这是你的愿望,继续,并编程Digi。您可以在其上实现Modbus / RTU和Modbus / TCP堆栈。由于设备可以托管嵌入式Linux ...你可以从这个开始: http://mbus.sourceforge.net/ [ ^ ],但可能是其他人准备好了。



从协议的角度来看,如果需要,您可以一次读取所有寄存器。不要试图重新发明***,因为Modbus是一个相当古老和广泛使用的行业标准包。很多东西都支持它,但如果你试图添加你自己的花哨的东西,它将不再符合,你将来会挣扎。



For测试你可以使用标准 Modscan32 [ ^ ] - 但这不值得付出代价(对不起朋友) - 更好的方法是使用NModbus实现。



另一方面,您根本不需要Modbus / TCP,因为您可以在以太网端实现更高级别的服务。如果您严格需要工业标准,请实施OPC UA。如果没有,请放置REST API。如果目标是非通用数据采集,则更容易实现和适应。
Use NModbus[^]
See: http://www.mesta-automation.com/modbus-with-c-sharp-libraries-examples/[^].

But you need to see something clear: Modbus/TCP works over TCP/IP, Modbus/RTU works over serial protocols like RS232 and RS485. You can't just mix them. If the digi module is no modbus gateway, it won't work. As I see, the Digi module could be programmed to be a gateway, but do you really want this?
You need to implement on the Digi Modbus/TCP Slave (not master) + Modbus/RTU Master, and Modbus/RTU slave on the PIC - if the PC software will poll the PIC.
However, you could end up much cheaper with a ready-made device. Like this one: http://www.moxa.com/product/MGate_MB3180_3280_3480.htm[^]. Or even cheaper with these: http://www.shjelectronic.com/EthernetModules.htm[^]
Even Digi has it's own gateway: http://www.digi.com/products/serial-servers/industrial-hardened-serial-servers/digioneia[^]

Of course, if this is your desire, go on, and program the Digi. You can implement both Modbus/RTU and Modbus/TCP stacks on it. As the device can host Embedded linux... you could start from this one: http://mbus.sourceforge.net/[^], but could be others out there ready to run.

From protocol's point of view you can read all registers at once, if you want. Don't try to reinvent the wheel, as Modbus is a quite old and widely used industry standard pack. Many things are supporting it, but if you try to add your own fancy things, it won't be compliant anymore, and you will struggle in the future.

For testing you can use the "standard" Modscan32[^] - but it's not worth the price (sorry folks) -, better simply implement your with NModbus.

On the other hand, you don't need Modbus/TCP at all, because you can implement higher level services on the ethernet side. If you strictly need industrial standards, implement OPC UA. If not, put a REST API in place. Far simpler to implement, and to adapt - if the goal is non generic data acquisition.