Modbus Master Connection

When GPL operates as a MODBUS master, it sets up a TCP client connection with a remote MODBUS/TCP slave.  The slave acts as a TCP server.  When the connection is no longer needed, it may be closed.  To establish a connection, follow this procedure:

Step Action

1.  

Create an IPEndPoint object for the remote MODBUS/TCP slave.  This object normally specifies the IP address of the slave and omits the port number, in which case the standard MODBUS/TCP port is used.

2.  

Create a Modbus object using this endpoint_object.   Creating a Modbus object does not establish a connection, but simply saves the endpoint information for later.

3.  

Use the modbus_object.Timeout property to set an appropriate timeout value for the connection.  By default the timeout is infinite.

4.  

Use the various Modbus class methods to read or write data.  The first time you issue a read or write, GPL attempts to connect with the MODBUS slave.  If the slave does not respond, an exception is thrown.

5.  

When finished with the MODBUS slave, call modbus_object.Close to close it.  Do this at the end of a session, not after each read or write request.