Colway Solutions
Modbus Member Logo

Supporting multiple Modbus TCP connections in MSPL-C

 

A Modbus TCP slave application listens for connection requests on the Modbus port no. and accepts multiple connections. This requires a dedicated thread or task to listen for connection requests and accept them while another set of dedicated threads and tasks handle further communication with connected masters.

 

In MSPL-C, each connected socket is considered as a channel of communication. There are three approaches you can take to support for multiple Modbus TCP connections.

i.         A dedicated thread for listening to connection requests and accepting them. Another set of threads to do further communication with connected clients (i.e. one thread per connected
client). The connection handling thread can block waiting for new connection requests in this case.


ii.       A dedicated thread for listening to connection requests and accepting them. Another thread (i.e. just one thread) to do further communication with connected clients. In this case too, the connection handling thread can block waiting for new connection requests.


iii.      On platforms that do not have a facility for multitasking, a single thread (i.e. the main thread) will have to do the task of both listening for new connection requests as well as handling communication with connected clients. Obviously, the connection handling code cannot block waiting for new connection requests. Instead such code should only query the underlying TCP/IP stack to enquire if a new connection request has come in. If yes, it must be accepted and execution must continue to the code that handles further Modbus communication with the connected clients.

 

The Win32 port of MSPL-C demonstrates how to support multiple Modbus TCP connections simultaneously.

 

Back to Index

Privacy Policy Site Map FAQ Contact Us