MODBUS/TCP Master Scanner

The PreciseFlex™ Controller can automatically scan arbitrary MODBUS/TCP devices to transfer data to and from a block of digital I/O signals. Up to 8 different MODBUS/TCP devices can be automatically scanned. In addition, up to 12 registers blocks on each device can be accessed, so if a device supports both inputs and outputs, only one scanner is used.

When enabled, a scanner polls to initiate an Ethernet connection with a remote MODBUS/TCP device every 10 seconds. This polling continues forever so long as the scanner is enabled. To reduce system overhead, you should disable devices that are not used.

Once connected, the real-time data scanning proceeds at the configured scan rate. Each scanning interval, the controller issues commands to read or write data from the remote device registers. When a remote device responds to the PreciseFlex™ Controller, the configured input or output signals become installed and available for general use.

The scan period and timeout values are configurable. If a device fails to respond before the timeout, the configured input or output signals are removed, causing any programs that access them to throw an exception. Depending on the configuration, this timeout may also disable robot power.

If a timeout or other error occurs, the connection to the remote device is broken and the scanner attempts to reconnect every 10 seconds. The "MODBUS/TCP scanner connect count" parameter (DataID 584) counts up by one whenever a new connection is made, so you can detect if a connection was lost and automatically restored.

The bits in the configured block of GPL output signals are packed and sent to the remote output device. Data from the remote device is read and unpacked into a block of GPL input signals.

It is possible to use the MODBUS Master Scanner to access a PreciseFlex™ Remote I/O (RIO) board by configuring the RIO board to act as a MODBUS/TCP slave. However, it is much more efficient to use the standard RIO communications. See Controller Software > Introduction to the Software > Communications > Digital Inputs and Outputs > Remote Inputs and Outputs for details on configuring a PreciseFlex™ Controller to access an RIO board.

Configuration

Before the scanner can access a remote device, it must be configured using the standard Parameter Database. Unlike some configuration parameters, these values go into effect whenever a scanner is stopped and restarted by DataID 582. No reboot is required.

DataIDs 580 and 581 are single values that apply to all 8 scanners. DataIDs 582-585 are indexed by the scanner number, from 1 to 8. In the GPL Controller.PDbNum property, this scanner number is passed as the unit parameter.

The scanning and data transfer must be configured as shown below:

Parameter Database ID Parameter Name Default Value Description

580

MODBUS/TCP scanner time in sec

0.016

Defines how often the MODBUS/TCP scanners automatically read and write remote I/O boards to update data. This value must be large enough to ensure the I/O boards have sufficient time to respond and that the scanner does not use excessive CPU time polling. Most devices cannot respond faster than 4 milliseconds. If the value is too small, the scanners scan as fast as possible

581

MODBUS/TCP scanner timeout in sec

0.100

The time period used by the MODBUS/TCP scanners to determine if a remote I/O board is not responding. If the board does not respond within this time, an error occurs and any signals associated with it are uninstalled. Depending on the setting of "MODBUS/TCP scanner mode" (DataID 582), the robot power may be disabled. This value should be large enough to allow for retries after lost packets.

582

MODBUS/TCP scanner mode

0

Mode flags that control the operation of a MODBUS/TCP scanner. The unit parameter specifies the scanner, from 1 to 8.

The flag bits are as follows:

   &H01 - If set, the scanner is enabled and polls to connect every 10 seconds. Once connected, scanning begins. If cleared, the scanner stops.
    &H02 - If set, a scanner error causes the robot power to be disabled.

583

MODBUS/TCP scanner map

 

A string that describes the mapping between a scanned MODBUS/TCP device and the signals on the PreciseFlex™ Controller. The unit parameter specifies the scanner, from 1 to 8.

The string contents are described below.

584

MODBUS/TCP scanner connect count

 

A read-only count of the number of times the scanner has connected to the MODBUS/TCP device. The unit parameter specifies the scanner, from 1 to 8.

Set to 1 by the first connection. When an error occurs and the scanner automatically reconnects, this value increases by 1.

585

MODBUS/TCP scanner status

 

A read-only value containing the status of the MODBUS/TCP scanner. The unit parameter specifies the scanner, from 1 to 8.

If 0, the scanner is running normally. Otherwise contains a standard GPL negative error number.

The "MODBUS/TCP scanner map" (DataID 583) string elements contain comma-delimited fields:

nnn.nnn.nnn.nnn, map1, map2, ... , map12

nnn.nnn.nnn.nnn is the IP address of the remote MODBUS/TCP device.  You must not specify an IP address that is being used by a Remote I/O (RIO) board, specified in DataID 555.

map* is a mapping between addresses on the MODBUS/TCP device and the GPL signals. Up to 12 mappings may be specified within each string element. Each mapping contains 3 fields, separated by commas:

address{ type }, bits, signal

address is the address of an I/O location on the slave. The addresses are 1's based, so you may need to add 1 to the address shown by some manufacturers. For example, if the manufacturer lists 40001 as an address, GPL may require a value of 40002. This difference is manufacturer-specific.

{type} is an optional parameter that specifies the MODBUS function codes that GPL uses to access the remote device.

Type Code MODBUS Input Function MODBUS Output

omitted

Function code 4, read input register

Function code 16, write multiple registers

:S

Function code 4, read input register

Function code 6, write single register

:B

Function code 2, read discrete inputs

Function code 15, write multiple coils

:C

Function code 1, read coils

Function code 15, write multiple coils

:H

Function code 3, read holding registers

Function code 16, write multiple registers

bits is the number of consecutive bits to be mapped. Up to 96 bits may be mapped at a time.

signal is the number of the GPL signal corresponding to the lowest bit to be mapped. The signals mapped are from signal to signal+bits-1. The range of this signal number determines if the mapping is for inputs or outputs.

The signals may be mapped to anywhere in the range 101 through 1596 for outputs or 10101 through 11596 for inputs, except that signal blocks may not include xxx97, xxx98, xxx99, or xxx00. The signal blocks may not overlap each other or any other installed signal from a RIO or other device.

For example, the string: "192.168.0.150, 1, 16, 101, 200:B, 25, 10101" assigns the scanner to the device at IP address "192.168.0.150" and contains 2 signal mappings:

16 output signals from register 1 are mapped to GPL signals 101 through 116

25 input signals from I/O points 200 through 224 are mapped to GPL signals 10101 through 10125

Examples

Below are some example configurations for various MODBUS/TCP modules.

Festo CPX-FEC Front End Controller

IP address 192.168.0.10
The device contains
     8 inputs at register address 45395
     8 inputs at 45398
     16 inputs at 45401
     8 outputs at 40003, 40004, 40005, and 40006

Note that one is added to each register address in the mapping below.

     DI: 583, 0, 0, 0, "MODBUS/TCP scanner map" =
        "192.168.0.10,45396:H,8,10101,45399:H,8,10109,45402:H,16,10117"
     DI: 583, 2, 0, 0, "MODBUS/TCP scanner map" =
         "192.168.0.10,40004,8,101,40005,8,109,40006,8,117,40007,8,125"