modbus: MODBUS communication

Top  Previous  Next

 

MODBUS is a messaging protocol for master/slave communication between devices connected on different types of buses or networks and has been the serial de facto standard of the industry since 1979.

 

The MODBUS API is an alternative to the I/O Extension feature which gives the application full control over the MODBUS communication - thus allowing custom control over all requests and replies.

The MODBUS API supports the RTU protocol version, the ASCII protocol version, and the TCP protocol version.

 

Please note it is not possible to use the MODBUS API, MODBUS ASCII API and I/O Extension on the same port at the same time as they are equivalent to each other.

 

The following functions are used to access the MODBUS network.

 


ioDeviceEnable

Enables or disables a device in the I/O Extension.


ioInputLatchSet

Configure if inputs of devices in the I/O Extension should be latched.


ioGetStatus

Gets the status for a device in the I/O Extension.


ioNetRemove

Disables a net in the I/O Extension until device reset.


ioNetEnable

Enables or disables a net in the I/O Extension.


ioNetConfig

Configure an disabled I/O Extension net.


ioSetMode

Sets the update mode for the I/O Extension devices.


ioSynchronize

Synchronizes the I/O Extension devices.


ioWaitException

Waits for an exception in the I/O Extension.


modbusOpen

Opens the MODBUS RTU network on a serial port.


modbusOpenX

Opens a MODBUS network.


modbusClose

Closes a MODBUS network.


modbusReceive

Receives a MODBUS message.


modbusSend

Sends a MODBUS message.


modbusWaitData

Waits for data received or timeout.


modasciiOpen

Opens the MODBUS ASCII network on a serial port.


modasciiClose

Closes a MODBUS ASCII network.


modasciiReceive

Receives a MODBUS ASCII message.


modasciiSend

Sends a MODBUS ASCII message.


modasciiWaitData

Waits for ASCII data received or timeout.

 

The MODBUS message is made up of  2 fields: the function code and the function data.

 

modbus-msg

 

The function code field is coded in one byte. Valid codes are in the range of 1...255 decimal (the range 128 – 255 is reserved and used for exception responses).

When a message is sent from a master to a slave device, the function code field tells the slave what kind of action to perform.

 

The data field of messages sent from a master to a slave devices contains additional information that the server uses to take the action defined by the function code.

This can include items like discrete and register addresses, the quantity of items to be handled, and the count of actual data bytes in the field.

The data field may be nonexistent (of zero length) in certain kinds of requests - in this case the server does not require any additional information.

The function code alone specifies the action.

 

Consult the MODBUS protocol for more information on MODBUS messages. For the commands used and supported by the I/O Extension, please see the MODBUS commands section.

 

The implementation of MODBUS has the following limitations:

A maximum of 3 MODBUS networks can be used. (shared with I/O extension)

A maximum of 2 MODBUS networks can use the same protocol. (RTU, ASCII or TCP)

A maximum of 16 devices (32 devices under the NX32L architecture) can be connected to a TCP MODBUS network.