Modbus device discovery with many Slaves.


Thread Starter


I am new to Modbus protocol. I have read the spec and ported the stack and gotten basic functionality working (Master talking to a slave, reading and writing registers based on a map, handling exceptions).

I am trying to understand how to configure multiple slave-ids on an existing RS-485 network without having any duplicate slave-ids. Since modbus doesn't support response to broadcast packets, we cannot send a broadcast and ask for who has a particular slave-id...

My initial research tells me the following: (Please advice on better ways to configure slave-ids on devices without having any duplicate slave-ids).

a) Run a modbus scanner to identify used slave-ids on the network.

b) Configure slave-ids for the new devices to be added to the network (one at a time outside the RS-485 network). We cannot do this on the existing RS-485 network setup because all new devices will receive the same command to configure their slave-ids.

c) Once all slave-ids are configured, then add the devices to the existing RS-485 network.

Is this how EMS's do it? Are there better ways to handle this issue... as this involves ensuring manual configuration of slave-ids... any automated ways to do this?

Modbus addressing is primitive. By that I mean the engineer designing the host is also responsible for assigning all slave addresses to fit in with his/her overall system design.

Otherwise, the only method available to determine if a slave address is open/available is to test poll each slave address to see if there is a device out there already using that address. I would attempt this procedure by polling function 1 "Read Coil Status" starting at coil 0 for 16 coils.

Lynn August Linse

Modbus offers no such easy 'fix after screw up'.

You need to add new units one by one, plus generally AVOID using the default slave address in the real system.

Some vendors default to a high number like 247, 254, or 255 so that address 1 can be used. But if your device defaults to 1, then you should avoid using 1, as if one of N units on the RS-485 ever does a 'factory reset' due to a surge or fault, then if you actively use that address you risk having 2 slaves with the same address ... which under Modbus pretty much promises no good response can be seen as the 2 nodes should collide on the response wires.

'Smart' vendors also offer some form of DIP switch or jumper which causes the Modbus slave to be a fixed address, fixed baud rate, etc. Otherwise recoding a slave with unknown slave address and baud rate can be very frustrating.
Thanks for all your responses!

If we do not know all the various places our device goes into, how do we know what numbers to assign, as the slave address?

The only way I can think of is to run a Modbus scanner polling from 1 to 247 which reads offset 0 (because almost all devices use this address for something) with function-code (0x1, 0x2,0x3,0x4) because the device may support only a few of the read functions. For example: On our device, we only support 0x3,0x4 for read and no coil registers.

Once the scanner runs, then we know the unused slave-ids which can be assigned.

Any other thoughts?

What do large EMS companies do when they have multiple devices from different companies to monitor?
> What do large EMS companies do when they have multiple devices from different companies to monitor?

I'm just a one man show so I do it my way - I enter the slave ID number in the column next to the device's tag name in the spreadsheet. I even have a 'physical location' column. Seems to work for me.

Frank O'Gorman

The configuration of your Modbus master should tell you the slave addresses that are being used. You should only need to scan if you have devices connected that are not being used by the master.

If you do scan, it does not matter what function code or register address you use - the slave should send an error response if it doesn't support that function or register (except for a couple of the function code 8 Diagnostics functions). I would scan all slave addresses in the range 1-255 - although the spec restricts the range to 1-247, most masters and slaves will support 1-255.