Skip to main content
Submitted by Galil_AndyH on Thu, 03/31/2011 - 17:58

When setting up an RIO as extended I/O of a controller it is recommended to setup a modbus connection between the controller and the RIO.

This post is also applicable for creating a robust Modbus connection to a standard Modbus slave device.

The Galil software will typically connect using the lower handles (A, B, C), so the modbus handle should be established using one of the upper handles (F, G, H).  This will limit the potential that host software will connect over the same handle that will then be used as the modbus connection to the RIO.

The I/O can be addressed by knowing the handle that is used to establish the modbus communication.

I/O Number = (HandleNum*1000) + (BitNum)

If the handle is established over handle 'H', input 1 on the RIO can be addressed by reading input # 8001.

MG @IN[8001]

Handle 'H' is the 8th handle and we want to read input 1 therefore 8000+1=8001.  The analog inputs, analog outputs, digital inputs and digital outputs can be referenced in the same manner.

There are 2 types of errors that can occur when communicating via modbus to an RIO.  A TCP error or a standard communication error.  The TCP error will result in an error code (_TC) of 123 and the #TCPERR automatic subroutine will be executed.  The other communication errors will result in error codes from 120 to 129 and the #CMDERR automatic subroutine will be executed.

When an error occurs with the Modbus communication the connection should be refreshed to the RIO.

Code can be found in via the below link that demonstrates how to establish the modbus connection to the slave, send and receive I/O status from the RIO or Modbus slave, and recover from a communication error between the two devices.

Code Example