title: Converting Modbus Serial Application to Modbus TCP/IP c#
body: <p>I am currently working on an application which communicated with devices using Modbus serial. The application is written in C#.</p>
  
  <p>Our devices have been modified to use Ethernet and I have now been tasked with converting this application to use Modbus TCP/IP. </p>
  
  <p>I initially thought it would be very simple, and would only require changing the Serial connection to a TCP Client connection and Listener. </p>
  
  <p>I have read some documentation on Modbus TCP/IP</p>
  
  <p><a href="https://www.prosoft-technology.com/kb/assets/intro_modbustcp.pdf" rel="nofollow noreferrer">https://www.prosoft-technology.com/kb/assets/intro_modbustcp.pdf</a>
  <a href="https://www.honeywellprocess.com/library/support/Public/Documents/51-52-25-121.pdf" rel="nofollow noreferrer">https://www.honeywellprocess.com/library/support/Public/Documents/51-52-25-121.pdf</a></p>
  
  <p>Although I feel like I still may be missing some essential differences. </p>
  
  <p>From what I understand, this is what needs to be done.</p>
  
  <ol>
  <li>Introduce new MBAP header in place of the Additional Address section at the start of a packet.</li>
  <li>Remove checksum from the Modbus packet as this is handled by TCP/IP.</li>
  <li>Open connection with each device using the <code>Socket</code> 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 an <code>Array</code> of <code>TcpClient</code> objects. Or should I simply close the connection after I receive a response?  Will I need to have a thread for each Server/Slave?</li>
  </ol>