2
\$\begingroup\$

I'm using a number of Modbus RTU devices connected to my PC through a Modbus TCP gateway. I'd like to poll all the available slave addresses to check which ones are available through my program.

What would be the best way to do this ?? I guess I could just do a read on some arbitrary register but I would like to use a method and value that's common to all devices.

The official Modbus Application Protocol guide mentions a Diagnostics function code but that seems to be for serial line devices only.

\$\endgroup\$
  • \$\begingroup\$ But you what? Looks like your question got cut off... \$\endgroup\$ – Kevin Vermeer May 17 '12 at 16:45
1
\$\begingroup\$

There are no guaranteed addresses or registers with ModBus; that's one of its biggest failings (or one if it's greatest strengths, depending on how (in)experienced you are in the field). There have been numerous attempts to generate some kind of standard for common devices but ultimately there is no way to do this since there is no standards body oversight for such a thing to succeed.

\$\endgroup\$
  • \$\begingroup\$ But surely there must be some way to figure out if there is actually a device connected at a particular slave address. Maybe read time for even an exception response vs. a timeout \$\endgroup\$ – Saad Farooq May 18 '12 at 5:19
  • \$\begingroup\$ Nope. If you don't know of a specific coil/input that the slave is listening on, it will not answer. If you do know of a specific coil/input, then poll it with a reasonable timeout. If you get an answer, it's alive and if you don't, retry a couple of times (assume the network ate the packet) and if there's still no answer, consider the slave gone. There is no "bad request" response that is specified that all slaves must implement. \$\endgroup\$ – akohlsmith May 19 '12 at 0:59
1
\$\begingroup\$

MODBUS masters start polling of all slaves on the same physical channel, and then the ones that timeout for N times are the ones that should be considered not responding. It's up to a MODBUS master application to determine if it will retry again later, or kick out the missing slave from polling in order not to slow down polling of remaining slaves.

\$\endgroup\$
  • \$\begingroup\$ I assume you mean the Modbus Gateway at the RTU end is the master (as opposed to the server client architecture on the other end of the gateway). I find this interesting... according to you answer, the gateway should already have polled its slaves and know which ones are alive. I don't think I'll have that sort of access but I'll see if the docs show anything. However, the real question here is : What does a master (whether it be the gateway or my PC) poll for that we can be sure will be available on all devices ?? \$\endgroup\$ – Saad Farooq May 18 '12 at 14:10
  • 1
    \$\begingroup\$ You have missed the point. There is no general way to do what you want with unknown slaves. You can do what you want only with known slaves, where you know at least one valid tag address, which will be used by master in timeouts I mentioned. You never attach unknown MODBUS slaves and then browse their address space (like with OPC) simply because it is not available feature, and standard does not define these things, not even a single guaranteed tag address. A slave is free to implement just a subset of features, therefore diagnostic function is not guaranteed to be implemented... \$\endgroup\$ – avra May 21 '12 at 9:24
  • 1
    \$\begingroup\$ ... Also, although MODBUS TCP<=>RTU gateway is a master for RTU slaves, in reality this communication is transparent, and your PC app is not aware of this trick. Therefore, your PC app is a master in reality. You must know MODBUS address of each RTU device, and addresses of all tags you want to read BEFORE you start the communication. Then, your application either gets a valid response (MODBUS error code is also a valid response), or a timeout that you need to deal with. You either ignore it (which will slow all other MODBUS slaves) or temporary or permanently kick it out of the communication. \$\endgroup\$ – avra May 21 '12 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.