Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit_id=0 is not treated as broadcast (for TCP->RTU gateway) #56

Open
vanDrunen opened this issue Jun 27, 2022 · 1 comment
Open

unit_id=0 is not treated as broadcast (for TCP->RTU gateway) #56

vanDrunen opened this issue Jun 27, 2022 · 1 comment

Comments

@vanDrunen
Copy link

When using a ModbusTCP to RTU gateway, the unit_id is used to indicate the slave address on the RS-485 bus.
Slave address 0 is for broadcasting, for which no answers from the slaves should be expected, but pyModbusTCP threats unit_id=0 just like all the other values and waits for a response.

The only way to send a series of broadcast messages right now is to set the timeout value very low (approx. the time it takes for the frame to transmit on the RS-485 bus) and to ignore the return value of the write function.

Many devices using ModbusTCP (that are not RTU gateways) often ignore the unit_id value or use unit_id=0 as a regular target, so I understand the reason why it's implemented this way.
It would be a good feature though to be able to indicate somehow that the target is a RTU-Gateway, where unit_id=0 is treated as a broadcast message and the write function just returns True when the transmission is done.

@vanDrunen
Copy link
Author

In the official Modbus TCP documentation there are some contradicting statements about the use of the unit ID (page 23/46):
https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf

I have highlighted the contradiction in bold:

If the MODBUS server is connected to a MODBUS+ or MODBUS Serial Line sub-network and addressed through a bridge or a gateway, the MODBUS Unit identifier is necessary to identify the slave device connected on the sub- network behind the bridge or the gateway. The destination IP address identifies the bridge itself and the bridge uses the MODBUS Unit identifier to forward the request to the right slave device.
The MODBUS slave device addresses on serial line are assigned from 1 to 247 (decimal).
Address 0 is used as broadcast address.

On TCP/IP, the MODBUS server is addressed using its IP address; therefore, the MODBUS Unit Identifier is useless. The value 0xFF has to be used.
Remark : The value 0 is also accepted to communicate directly to a MODBUS/TCP device.

  1. You should treat Unit ID 0 as a broadcast address for RTU gateways
  2. You should not use Unit ID 1-247 (significant slave addresses) for Modbus/TCP devices
  3. Unit ID 255 has to be used for Modbus/TCP endpoints
  4. Unit ID 0 is also accepted, contradicting point 1.

So the best solution I think would be to have a configuration option for the modbus client e.g. "gateway" that can be set to True in case Unit ID 0 is broadcast and has no response from the slave.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants