Modbus

From HSYCO
Jump to navigation Jump to search

The Modbus Protocol is a messaging structure. It is used to establish master-slave/client-server communication between intelligent devices. It is a de facto standard. The Modbus RTU specification defines the default communication protocol over serial lines. The Modbus TCP/IP specification takes the Modbus instruction set and wraps TCP/IP around it.

HSYCO supports both Modbus TCP and Modbus RTU, acting as a Modbus master in both cases.

This support is implemented as a set of Java APIs that allow read/write functions as described in the HSYCO Programming Handbook, and an I/O Server with a data point representation that you can use in the EVENTS language to poll Modbus data and generate events.

General Configuration

Modbus TCP

If a Modbus TCP/IP device is used to interface HSYCO to a Modbus RTU or ASCII bus over RS485, the gateway should be configured as Modbus TCP/IP slave and Modbus RTU/ASCII master.

HSYCO can also directly access Modbus TCP slave devices.

Modbus RTU

HSYCO supports Modbus RTU over RS485, using the FTDI’s USB-RS485 cable, a USB to RS485 levels serial UART converter cable incorporating FTDI’s FT232RQ USB to serial UART interface IC device which handles all the USB signaling and protocols. The cable provides a fast, simple way to connect devices with a RS485 interface to USB.

The USB-RS485 cable connects to any USB port of the HSYCO server, and doesn’t require external power supply. It offers an internal 120 Ohm resistor for line termination, and +5Vcc and ground level references that could become handy to connect pull-up and pull-down resistors for lines’ polarization (See the MODBUS over Serial Line Specification & Implementation guide for additional information about line polarization and termination).

Note  The USB-RS485 cable doesn’t provide opto-isolated RS485 lines. Transient currents and voltage levels exceeding the cable’s specification could damage the USB-RS485 cable, HSYCO server and any Modbus device attached to the RS485 line.

HSYCO Configuration

Options

ID Default Values Description
eventslog false true if the general eventsLog option is also true in hsyco.ini, Modbus events for this gateway are written in the log files
false Modbus events for this gateway are not written in the log files, even if the eventsLog option is true in hsyco.ini
extendednames false true when this option is set, data point names used to return values will have the postfix .FF, where FF is the 2-digit decimal function code
false data points’ default naming convention is used

Modbus Integration

Because the Modbus protocol is not asynchronous, but is based on polling, you always have to request a read to tell the driver to actually read the data and eventually generate an event on the associated data point if the data has changed.

Datapoints

The naming convention HSYCO uses for the events is closely related to the Modbus addressing standards and data types.

The data point names always begin with the same format: ID.unitid.address, where ID is the I/O server id, unitid is the Modbus slave device address, from 1 to 247, and address is the initial register address you are reading.

The supported public function codes are:

  • 01: Read Coils
  • 02: Read Discrete Inputs
  • 03: Read Holding Registers
  • 04: Read Input Registers
  • 05: Write Single Coil
  • 06: Write Single Register
  • 15: Write Multiple Coils
  • 16: Write Multiple Registers

Read operations with functions 03 and 04 support the following data types:

Type code Description Return range Number of registers
ushort unsigned short integer 0 ... 65535 1
uint unsigned integer 0 ... (232 - 1) 2
ulong unsigned long integer 0 ... (264 - 1) 4
short signed short integer -32768 ... +32767 1
int signed integer -231 ... (231 - 1) 2
long signed long integer -263 ... (263 - 1) 4
float signed IEEE 754 floating point +/- 2-149 ... (2-2-23)x2127 2

Read Coils

Reads from 1 to 2000 contiguous coils, using function code 01. Each coil returns a binary value, 0 or 1, in distinct data points, one for each coil.

ID Value R/W Description
unitid.address.di bit:0
bit:false
bit:off
W sets a single bit in the discrete inputs data table to off
bit:1
bit:true
bit:on
W sets a single bit in the discrete inputs data table to on
bits:<0|1|-...>
'-' characters in the sequence are skipped
W sets multiple bits in the discrete inputs data table.
The left-most bit in the sequence is the discrete input at <address>

Coils Data Table

The internal coils data table can be read or written by a Modbus client, and written locally to set the coils’ values.

Examples

Reading an integer value from two registers

TIME: IO modbus.27.400 = readholdingregisters:uint
IO modbus.27.400 : UISET mydata.text = IO modbus.27.400

The first line executes the read holding registers function on a Modbus device with address 27, reading two contiguous registers starting at address 400.

The second line sets a text object of the Web interface with the value read from the Modbus device.

Release Notes

3.3.0

  • added support for Write Multiple Coils function:

writeMultipleCoils(String name, int unit, int address, int coils, byte[] bytes) Java method

ID.unitid.address = bits:<0|1>... in EVENTS

3.2.1

  • EVENTS: minor fixes to the readcoils and readdiscreteinputs actions

3.2.0

  • reading multiple consecutive values with a single Modbus read is now supported for readholdingregisters and readinputregisters

3.1.1

  • using format options bitshort, bitint and bitlong for readholdingregisters and readinputregisters, it is now possible to read 1, 2 or 4 registers and return the individual bit values

3.1.0

  • new error events on Modbus read or write errors
  • new option extendedNames. When this option is set, data point names used to return values will have the postfix .FF, where FF is the 2-digit decimal function code

3.0.3

  • fixes to the Modbus write functions
  • variables can now be used in value strings

3.0.0

  • initial release

Modbus is a registered trademark of Modbus Organization, Inc.

ID Value R/W Description