3
\$\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 server 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\$
1
  • \$\begingroup\$ But you what? Looks like your question got cut off... \$\endgroup\$ May 17, 2012 at 16:45

3 Answers 3

2
\$\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\$
3
  • \$\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\$ May 18, 2012 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, 2012 at 0:59
  • \$\begingroup\$ @SaadFarooq In theory a device is supposed to respond with an exception to "valid" but inacceptable queries such as a wrong register or even an invalid function call. In reality chances are a device might just ignore your request though... \$\endgroup\$ May 12, 2020 at 12:12
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\$
3
  • \$\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\$ May 18, 2012 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, 2012 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, 2012 at 9:31
0
\$\begingroup\$

While there are no guaranteed addresses or registers, theoretically via Function 43 (0x2B)'s 0x2B/0x0E Read Device Identification (see 6.21 in the standard) you should be able to at least query the mandatory objects

Object Id | Object Name / Description
0x00      | VendorName
0x01      | ProductCode
0x02      | MajorMinorRevision

edit In fact theoretically any valid query should result in some response instead of a timeout, at the very least an exception as described in section 7:

If the server receives the request without a communication error, but cannot handle it (for example, if the request is to read a non–existent output or register), the server will return an exception response informing the client of the nature of the error.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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