Apollo3zehn / FluentModbus

Lightweight and fast client and server implementation of the Modbus protocol (TCP/RTU).
MIT License
188 stars 69 forks source link

Added broadcast support to ModbusTcpClient #103

Open mile-bkoos opened 6 months ago

mile-bkoos commented 6 months ago

The ModbusTcpClient missed the support for broadcast messages. I copied the two code parts from the ModbusRtuClient into the ModbusTcpClient.

Apollo3zehn commented 5 months ago

Hi, thanks for your contribution! I am quite slow right now, I know. I don't know yet when I will be able to review your changes and I need to be careful with such kind of changes as this project became more popular recently (which means I need to check the specification against your changes).

I will do it eventually but please bear with me :-)

Apollo3zehn commented 4 months ago

I wanted to merge your changes but it causes many tests to fail.

In the spec (https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf, p.23) I read about the broadcast support and unit identifiers and found this:

grafik

My understanding is that when talking to Modbus RTU devices, a unit identifier of 0 means broadcast. And when talking to Modbus TCP devices, a unit identifier of 0 is a normal address.

Since the Modbus TCP client cannot distinguish between a regular Modbus TCP server and a Modbus TCP/RTU bridge I am not sure how to implement this properly.

The unit tests fail because they use unit identifier 0 to talk to the server and the newly introduced broadcast checks cause exceptions like Invalid use of broadcast: Unit identifier '0' can only be used for write operations..

Do you have an idea how to implement this properly?

mile-bkoos commented 4 months ago

First of all sorry for not running the unit tests before creating the pull requests. In fact we are using it to connect to a modbus RTU gateway / bridge. I added a new flag RTUGatewayMode so that the special handling for the unit identifier 0 only triggers if the flag is set to true :)

endrelovas commented 4 months ago

Guys how is this going now? Is it getting merged?