TCP Multiple Servers via Modbus

Hello all ,

Quick question - can you set up more than one modbus tcp server on a device (hence same IP) aslong as you have a different ID and Port number for each?

Therefore any client you make on the other device would be able to read either server as long as it specifies the correct ID and Port number?

Thank you :)

By ID, I assume you're referring to the Unit Identifier that is within the MBAP header.

To answer your question, yes you could theoretically do this, but it would depend on the capabilities of the client.

Also, you don't need to have both a different Unit Identifier and a different port number.

For example, a Modbus/TCP server could use different Unit Identifiers to represent different virtual devices, all accessed using a single port (TCP port 502 is the default for Modbus/TCP). As long as the client supports making requests using different Unit Identifiers, this would work.

Alternatively, your device could run multiple Modbus server instances, each bound to a unique port (for example, 502, 503, 504, etc.). This would only work, though, if the client supports connecting to multiple devices using different ports.
Multiple TCP masters and servers (or a combination thereof) can run concurrently on the same PC, but they need different TCP port numbers (say 502, 503..). Within each server instance, you can do what you want with the ID's, it is up to the server software to handle this. I.e. they could represent some hardware device inside the sever, or a logical device, or a combination. This is how gateways usually work.