Modbus Input Data

Last updated:  September 3, 2003

Introduction
This document is one of five that describes the basic ICON program (skeleton.icn) which normally provides the framework for all ICON programs. This document describes the  module named "Modbus Inputs" which reads external sensor data into your ICON program. Each block contains the following functions:

  1. Provide means to override the input values for testing.
  2. Setup the ICON 1-wire configuration. (May be deleted if using Modbus devices that require no configuration.)
  3. Write configuration to the ICON with a Modbus write instruction. (May be deleted if using Modbus devices that require no configuration.)
  4. Read ICON input registers (sensor values) with a Modbus read instruction.
  5. Export sensor results in a loop global variable for use by other modules.
An HMI interface is created that allows the user to interface to the above program to:
  1. Set raw Modbus override values for testing.
  2. Set 1-wire addressing (in case a sensor is replaced).
In the following sections the program is listed along with the configuration. The first line is the instruction and caption as would be listed when programming. This is followed by the general and table parameter configuration. Finally, a description of the purpose of the program is included if needed.

Module Modbus Inputs

Constant Override enable
General Parameters
Variable: override_enable1 Set to override_enable2 for the second block, etc. Value of 0 is no override, 1 enables override
Data type: Float
Mode: Capture
Table Parameters
No configuration necessary, set table length to 1

If Override values
Table Parameters
Variable Status Expression Description
Module 0 override_enable1 If override_enable1 is set to 1 then this If block is executed. This block loads override data.

Constant Override values
General Parameters
Variable: data1 Set to override_values2 for the second block, etc.) (Values set override values of Modbus registers for testing.)
Data type: Float
Mode: Normal
Table Parameters
Set table length to the length of the Modbus read plus 1 for status. Values can be set from the HMI but set your descriptions as appropriate to describe each Modbus register.

Elseif Otherwise get actual Modbus data
Table Parameters
Variable Status Expression
Module 0 1 This block will be executed if the If block is not. This block gets Modbus data.

OWconfig Configure 1-wire ICON
General Parameters
Config: OW_config1 Use OW_config2 for the second block, etc.
Table Parameters
The ID high: and ID low: can be set from the HMI. Refer to the following link for information on configuring the table parameters.

Modbus Send config to ICON
General Parameters
Parameter Example Description
Enable: Null
Status: Null
I/O transfer: OW_config1 Use OW_config2 for the second block, etc.
Com type: 2 You may select serial port 1 or 2 depending on which serial port your Modbus device is connected (usually 2).
IP address: 0.0.0.0
Port: 502
Unit Address: 255 The address of the Modbus device.
Register address: 4097
Command: Set multiple registers(16)
Register type: Unsigned integer
Timeout: 50 50 would cause the Modbus instruction to fail if a response from the remote Modbus device was not received within 500 mS.
Retries: 3 Allow command to be attempted 3 times before setting failure status.
Table Parameters
The table length indicates the number of items to transfer. Leave A set to 1 and B to 0 for all coefficients in all rows.

Modbus Read data
General Parameters
Parameter Example Description
Enable: Null
Status: status1 Use status2  for the second block, etc.
I/O transfer: data1[1] Use data2[1] for the second block, etc.
Com type: 2 You may select serial port 1 or 2 depending on which serial port your Modbus device is connected (usually 2).
IP address: 0.0.0.0
Port: 502
Unit Address: 255 The address of the Modbus device.
Register address: 1 Select the Modbus starting register address. For reading 1-wire devices and for most other Modbus devices you will use 1. This can only be found in your Modbus device documentation.
Command: 4 Select Read Coils(1), Read input discretes(2), Read registers(3) or Read input registers(4) as appropriate for your Modbus device.
Register type: Unsigned integer You may pick as appropriate. It does not matter for Commands 1 and 2.
Timeout: 50
Retries: 3
Table Parameters
The table length indicates the number of items to transfer. Normally set A to 1 and B to 0 for all coefficients in all rows. You may invert digital inputs (Commands 1 or 2) with A= -1 and B=1.

ExpressionSet Modbus Status
Table Parameters
Result: Expression: Description
data1 (Use data2 for the second block, etc.) status1>1 Since we are using "real" Modbus data the program exports the "real" modbus status. Notice the status is in the first element of the data array. Its value is 0 if the Modbus operation was successful and 1 if the Modbus read failed.

Endif

Fan Export data for 1st Modbus read
General Parameters
Source: data1 Use data_selected2 for the second block, etc.
Destination: #raw1 Use #data2 for the second block, etc. This is the exported data that will be used by other modules.
Count index: Null
Time index: Null
Time def: Null
Last period: Null.
Block size: 17 Set to length of Modbus read plus 1 for status.
Number of indexes: 1
Direction: Multiple sources to one destination

The following instruction is entered only one time at the end of the module to export the master Modbus alarm !alarm which is set if any individual Modus fail alarm sets.