I am currently working on an application which communicated with devices using Modbus serial. The application is written in C#.
Our devices have been modified to use Ethernet and I have now been tasked with converting this application to use Modbus TCP/IP.
I initially thought it would be very simple, and would only require changing the Serial connection to a TCP Client connection and Listener.
I have read some documentation on Modbus TCP/IP
https://www.prosoft-technology.com/kb/assets/intro_modbustcp.pdf https://www.honeywellprocess.com/library/support/Public/Documents/51-52-25-121.pdf
Although I feel like I still may be missing some essential differences.
From what I understand, this is what needs to be done.
- Introduce new MBAP header in place of the Additional Address section at the start of a packet.
- Remove checksum from the Modbus packet as this is handled by TCP/IP.
- Open connection with each device using the
Socket
class. To open these connections I will now need to store each Device IP in my Client/Master configuration. They will be listening on the default Port 502 and the connection must be opened from a random available port > 1024. The connection should also remain open, therefore I will maintain anArray
ofTcpClient
objects. Or should I simply close the connection after I receive a response? Will I need to have a thread for each Server/Slave?