You are here: Start » Technical Issues » Working with Modbus TCP Devices

Working with Modbus TCP Devices

Introduction

The filters for Modbus over TCP communication are located in the System :: Modbus TCP

Establishing Connection

To communicate with a ModbusTCP device, first a connection needs to be established. The ModbusTCP_Connect filter should be used for establishing the connection. The default port for ModbusTCP protocol is 502. Usually, a connection is created before the application enters its main loop and it remains valid through multiple iterations of the process. It becomes invalid when it is explicitly closed using ModbusTCP_Close filter or when an I/O error occurs. The Modbus filters work on the same socket as TCP IP filters. If Modbus device supports Keep-Alive mechanism it is recommended to enable it, to increase chance of detecting a broken connection. For more details please read Using TCP/IP Communication.

Reading and Writing Values

Adaptive Vision Studio provides set of filters to manage Modbus objects. The following is table of object types provided by a modbus:

Object Type Access Size
Coil Read-Write 1-bit
Discrete Input Read-Only 1-bit
Input Register Read-Only 16-bits
Holding Register Read-Write 16-bits

The Coils, Inputs and Registers in ModbusTCP protocol are addressed starting at zero. The table below lists filters to control object types mentioned above.

Object Type Read Write
Coil ModbusTCP_ReadCoils ModbusTCP_WriteCoil
ModbusTCP_ForceMultipleCoils
Discrete Input ModbusTCP_ReadDiscreteInputs Read-Only
Input Register ModbusTCP_ReadInputRegisters_AsByteBuffer
ModbusTCP_ReadInputIntegerRegisters
ModbusTCP_ReadInputRealRegisters
Read-Only
Holding Register ModbusTCP_ReadMultipleRegisters_AsByteBuffer
ModbusTCP_ReadMultipleIntegerRegisters
ModbusTCP_ReadMultipleRealRegisters
ModbusTCP_WriteSingleRegister
ModbusTCP_WriteMultipleRegisters_AsByteBuffer
ModbusTCP_WriteMultipleIntegerRegisters
ModbusTCP_WriteMultipleRealRegisters

Sample Application

The following example illustrates how to use ModbusTCP filters.

Main macrofilter - establish and close connection

Main Loop - communication with Modbus device

Inspection - sample inspection algorithm

Custom Functions

To support device specific function Adaptive Vision Studio provides ModbusTCP_SendBuffer filter. This filter allows to create a custom Modbus frame.

Previous: Working with National Instruments Devices Next: Project Files