Modbus TCPIP master to many slaves

M

Thread Starter

Miroslav

Hi,

I am writing a modbus TCP/IP master (client) that should be able to talk to many slaves (servers). My question is: If, for example, I am talking to 15 slaves, should I keep 15 TCP/IP connections at the same time or shall I just use 1 connection that I close after finishing with slave 1 and reopen for slave 2 and so on?. I don't seem to find the answer in TCP/IP implementation guide.

Thanks.
 
I would suggest to leave your 15 connections open for efficiency. It may not be necessary, but why add any unnecessary overhead?

KEJR
 
D

Darrin Hansen

Functionally, either will work. It's more an issue of performance, which may or may not be a concern depending on your application. The ideal solution is probably to maintain separate sockets for each connection, but sometimes a master's resources (RAM/ROM etc.) may not be adequate to do this.

Regards,
Darrin Hansen
ICC, Inc.
 
This has been answered a couple of times already, but I would like to clarify a point. Normally, you would just open 15 sockets and leave them open. However, if you have some special resource constraints (i.e. you are using a very small embedded system) on your client (master) then you might be forced into opening just one socket at a time.

Also, there is no reason to poll one server (slave) at a time (unless of course you have resource constraints). You can poll them all in parallel. This is Ethernet, not RS-485. You don't have to manually control access to the network to prevent collisions. Ethernet and TCP/IP take care of that for you. You just need to write your software to be asynchronous or multi-threaded and you can send out all 15 (or more) requests at the same time and get the replies back when each server is ready.
 
Miroslav,

If your slaves (servers) support Modbus/UDP, then you could use Modbus/UDP as an alternative.

Since UDP is an unconnected (no open sockets) protocol, you can eliminate the overhead of 15 open sockets.

I don't think that Modbus/UDP is a formal standard, but many devices implement it nonetheless. I think (but am not sure) that KepServerEx (OPC Server) supports it, as well.

And then there are some gateways that can convert Modbus/RTU or Modbus/TCP to Modbus/UDP. The Digi One IAP is one example.

Hope this helps!
 
Hi,
thanks for your comments. You clarified what I was thinking. I will implement 1x socked per slave.

Thanks,
Miroslav
 
L

Lynn August Linse

>> thanks for your comments. You clarified what I was thinking. I will implement 1x socked per slave. <<

Just one field warning - something you'll discover as more users try your host tool.

If those 15 slaves all have the same IP address, then you might discover 'they' won't allow you to hold 15 sockets open at once - it could be that all 15 slaves *DO* represent 15 RS-485 devices on a single 'device server' or 'Modbus Ethernet-to-serial bridge'. Such devices might support as few as 4 concurrent sockets or as many as 64.

Several OPC servers get around this by including an option they might call 'optimize the sockets', meaning they use a single socket to all slaves with the same IP address. You won't need this in your first product, but just keep it in mind as you design.

- LynnL, digi.com
 
Top