This page is a
translated version of the page
Modbus and the translation is 100% complete.
iRidium for Modbus
is a set of tools for creating interfaces for controlling equipment compatible with Modbus
Description
The documentation was updated on 26.9.2023
Description
iRidium for Modbus is a set of tools for creating interfaces to control homes or offices on the basis of equipment compatible with Modbus.
iRidium connects to the controller as Modbus Master, the controller is always Slave. Supported Modbus protocols: TCP, RTU, ASCII (it is possible to work via RS232). To connect to the OPC server you can use the Modbus Server driver which enables work in the Slave moe. But this mode does not work with PLC.
Licensing of iRidium for Modbus: in details
Connection
Equipment configuration and settings required for iRidium to control PLCs compatible with Modbus.
Ways of connection to PLC
Different ways of connection to PLC require selection of different drivers in iRidium.
1. Modbus TCP / Modbus TCP Server
2. Modbus TCP / Modbus TCP to RTU / Modbus TCP to ASCII
1. Connection using the client-server model where i3 pro is Master initiating transactions to the Slave controller. To work with the controller you do not need any additional hardware as the controller had the Ethernet interface.
2. The same model of data transfer is used but it is required to havу a converter from the TCP/IP protocol into the Modbus RTU/ASCII protocol. Any gateway of the indicated type (Moxa, ICP-DAS, etc.) can be a converter.
If you selected work using the Modbus protocol consider its features:
PLCs often have a limited number of concurrent connections. Make sure your controller supports the number of connections you require.
Do not add registers which are not set up for the PLC in the project as it will lead to delays of control
Increase the value of Update Time for the controller if it starts to work worse when connecting with iRidium
iRidium sends fc5 and fc6 (single coil, single register) commands to Coil and Holding registers . If the controller does not support these commands it has to response with error 01 (illegal function). After that iRidium automatically switches for sending fc15 and fc16 (multiple coils, multiple registers) commands. If the controller does not return error 01, there will be no switch for fc15 and fc16! Set up the controller for working with fc5 and fc6 (single coil, single register) functions if register control does not work but there is feedback from the controller.
Modes of communication:
- Modbus TCP - the driver for direct connection to the controller via Modbus TCP without any additional hardware or software. iRidium - Master, the controller - Slave
- Modbus TCP to RTU and Modbus TCP to ASCII - the drivers for connection to the controller via the converter from TCP/IP to Modbus RTU (ASCII). iRidium - Master, the controller - Slave
- Modbus RTU and Modbus ASCII - the drivers for connection to the controller via Modbus RTU or ASCII using RS232/RS485 serial networks. When using these drivers the iRidium application can be launched only on the device physically connected to the controller by the serial port of data transfer. iRidium - Master, the controller - Slave
- Modbus Server - for connecting iRidium to the ОРС server using the Modbus TCP protocol, iRidium - Slave, the ОРС server - Master. It cannot be used with a standard PLC as at each iRidium launch there is reset of Modbus variables on the Slave side (it is necessary to provide protection of PLC from reset of variables at the application launch).If you use Modbus Server driver, place data in feedback channels, channels are not used.
Contact iRidium technical support team to get more detailed recommendations.
Import of Modbus addresses in iRidium
The Modbus protocol in iRidium enables control of any number of controllers by different manufacturers. The universal system of data import allows you to create the list of commands and feedback channels for the Modbus driver in the Exel table. This table is saved in the CSV format and can be imported in iRidium projects as a new driver:
- In the block marked blue, indicate the IP-address, port and frequency of transactions for connection to the controller via Modbus TCP. If you use another driver, copy its name from iRidium Studio and indicate it in the first string of the template instead of MODBUS TCP (TCP)
- In the block marked green, the list of commands (Commands) which you need to create in the project device tree is formed. Each string is a command with the name and a number of settings (you can see more information in the section "Sending Commands and Reading Data by the Modbus protocol")
- In the block marked orange, the list of feedback channels (Feedbacks) which you need to create in the project device tree is formed. Each string is a channel with the name and a number of settings (you can see more information in the section "Sending Commands and Reading Data by the Modbus protocol")
When the list of commands and channels is formed save the Exel table in the *.CSV format:
As a result you will have the file ready for importing in iRidium. Go to iRidium Studio, create a new project and use File > Import. Select the created CSV file and confirm import of data to your project.
Commands & Feedbacks
As a result we have two levels of PLC settings:
- Modbus TCP - the driver unites the list of PLC registers
- Commands and Feedbacks - the commands and feedbacks inside devices. They enable control of Modbus registers. The commands are registers available for writing, the channels are registers available for reading.
Commands and feedback channels have to be assigned to project graohic items to control equipment:
- Commands are assigned to graphic items indicating the value to be sent to registers when clicking on the items
- Feedback channels are assigned to graphic items to display the register state
To assign commands or channels to graphic items use the drag&drop
method.
Below you can see examples of commands for control of different types of registers.
iRidium supports the following registers and functions:
- Coil Register (0x05, 0x0F, 0x01) - flag registers, one bit, reading and writing
- Holding Register (0x06, 0x10, 0x03) - registers for storing, 16-bit word, reading and writing
- Discrete Inputs (0x02) - discrete inputs, one bit, reading only
- Input Register (0x04) - input registers, 16-bit word, reading only
Word Size - the size of words sent to the controller, it can be up to 32 bit:
- Word (16-bit) - 16-bit word corresponding to the standard Modbus protocol
- Word(16 bit) unsigned - 16-bit unsigned word corresponding to the standard Modbus protocol.
- DWord (32-bit) - 32-bit word consisting of two standard Word registers
- Float (32-bit) - 32-bit word, it supports values with floating point
- Dword(32 bit) unsigned - 32-bit unsigned word, consisting of two standard Word registers.
If a project has 32-bit registers and the SinglePoll function of subdevice properties is turned on, the addresses of channels and feedbacks must have a 2-digit difference (for example, there can be addresses like 2, 4, 6, 8, 10 and there can't be addresses like 2, 3, 4, 6, 7, 8).
Content Type is a classification by the sequence of writing data and their size:
For 16-bit:
- Low Endian - the order of bytes typical for the standard Modbus protocol. Data are written starting with the low byte and ending with the high byte (b1, b2);
- Big Endian - data are written starting with the high byte and ending with the low byte (b2, b1).
For 32-bit:
- Swapped Big Endian - the order of bytes typical for the standard Modbus protocol. Data are written starting with the low byte and ending with the high byte (b1, b2, b3, b4);
- Swapped Low Endian - data are written starting with the high byte and ending with the low byte (b4, b3, b2, b1);
- Low Endian and Big Endian - the order of bytes corresponds to the definitions above, but pairs of bytes in each word swapped their places (for Low Endian - b3, b4, b1, b2 , for Big Endian b2, b1, b4, b3).
Sending and receiving data are performed by the driver on the basis of the list of commands (Commands) and channels (Feedbacks) it has. Transaction frequency is indicated when setting up the connection.
Setting up connection to PLC
Select the connection settings by default. They can be changed while working with the project.
Modbus TCP / Modbus TCP to RTU / Modbus TCP to ASCII / Modbus TCP Server:
- Host - the PLC IP-address (IPv4)
- Port - the ТСР port of connection to PLC (usually 502)
- Keep Alive - an interval to check TCP connection. In case there is no answer to Keep Alive requst, the driver will be forced into the off state. The parameter is created to display the correct on-line status, if the client was disconnected in an emergency or in a wrong way. 0 - turns off the setting.
- Update time (ms) - the frequency of sending requests to the PLC to update data about its state
- Coil Write Function- The mode of sending a command of discrete commands (Single - writing one register of flags, Multiple - writing several flags registers)
- Holding Write Function- Mode for sending commands to output registers (Single - write one register, Multiple - write multiple registers)
To work via the Internet, indicate the public IP-address of the router to which the controller is connected and set up Port Forwarding.
You can see the public IP-address of the router here
Modbus RTU / Modbus ASCII:
- Log Level - the level of logging.
- Host - the number of the СОМ-port to which the controller is connected.
- Used with iRidi device - set the host for the corresponding equipment (if this parameter is selected, the Host line will be inactive).
- Update Time (ms) - the frequency which which iRidium will request information about status changes of controller variables. Recommended values - 1000...2000 ms
- Baud Rate - the speed of data exchange with the controller
- Data Bits - the number of information bits in a frame
- Parity - parity control
- Stop Bits - the stop bit in a frame (1; 1,5; 2).
In the web interface, stop bits are displayed as:
iRidium studio: |
Web interface:
|
1 |
0
|
1,5 |
1
|
2 |
2
|
- Coil Write Function - it send a separate packet to write each register (Single - writing one flag register, Multiple - writing several flag registers).
- Holding Write Function - a mode to send commands to output registers (Single - writing one register, Multiple - writing several registers).
- Silent Period - it sets a pause between sending commands.
The RS232 protocol will work only on devices which are physically connected to PLC (СОМ-port) or have one virtual СОМ-port for connection to PLC
Modbus TCP Network
- Log Level - level of logging.
- Host - IP address of the controller (IPv4)
- Port - ТСР connection port to the controller (usually 502)
- Wait for Data (ms) - period of time to wait for an answer from the driver. After the set period of time, connection attempt to the driver is repeated.
- Keep Alive - an interval to check TCP connection. In case there is no answer to Keep Alive requst, the driver will be forced into the off state. The parameter is created to display the correct on-line status, if the client was disconnected in an emergency or in a wrong way. 0 - turns off the setting.
- Update time (ms) - request period of the controller to update data about its state.
- Coil Write Function- sending a separate packet to write each register (Single - writing one register, Multiple - writing several registers).
- Holding Write Function- mode to send commands for output registers (Single - writing one register, Multiple - writing several registers).
- Single Poll - when this parameter is on a single packet is formed to request each channel of a subdevice.
- Send Wait Time - a pause between attempts to request a subdevice. The number of attempts is set in the "Number of attempts" field of a subdevice.
Subdevices now have Change Write Function' parameter. When it is activated, additional settings of a subdevice appear, such as Coil Write Function and Holding Write Function.
Modbus RTU Network
- Log Level - level og logging.
- Host - address of COM-port.
- Wait for Data (ms) - period of time to wait for an answer from the driver. After the set period of time, connection attempt to the driver is repeated.
- Used with iRidi device - set the host for the corresponding equipment (if this parameter is selected, the Host line will be inactive).
- Update time (ms) - request period of the controller to update data about its state.
- Baud Rate - speed of data exchange with a controller.
- Data Bits - number of information registers in a shot.
- Parity - parity check.
- Stop Bits - stop bit in a shot(1; 1,5; 2).
In the web interface, stop bits are displayed as:
iRidium studio: |
Web interface:
|
1 |
0
|
1,5 |
1
|
2 |
2
|
sending a separate packet to write each register (Single - writing one register, Multiple - writing several registers).
- Holding Write Function- mode to send commands for output registers (Single - writing one register, Multiple - writing several registers).
- Single Poll - when this parameter is on a single packet is formed to request each channel of a subdevice.
- Send Wait Time - a pause between attempts to request a subdevice. The number of attempts is set in the "Number of attempts" field of a subdevice.
- Silent Period - it sets a pause between sending commands.
Change of connection settings
You need the possibility to change connection properties when you disconnect from the Wi-Fi network of the automation object and start using 3G or another Wi-Fi network. To maintain control of the object you need to switch from the local to public IP-address of the Internet router.
The switch is not automatic. You have to select the connection mode. For remote acces you have to make ports for controlling the automation system public. In order to do that you have o set up the Port Forwarding service on your Internet router. VPN can provide protected connection.
1 Download the template (*.js) (right-click button: "Save object as ..."), add the template in the script editor with the button
(+) Add Script from file
2 Set up script properties as it is shown in the example:
- function Internal_1() {
- IR.GetDevice("Modbus TCP").SetParameters({Host: "192.168.0.100", Port: 502, UpdateTime: 1000});
- }
- function External_1() {
- IR.GetDevice("Modbus TCP").SetParameters({Host: "215.110.10.10", Port: 502, UpdateTime: 1000});
- }
Copy the driver name from Projeсt Device Panel - the list of properties has to be copied from the example.
3 Select the button which will be responsible for the switch of Internal and External properties. Open Macros Editor
for the Press event (Object Properties > Programming), select the Script Call
command and add it by double-clicking on it. Select the name of the function which will be activated by the button:
Now each pressing on the button will apply the corresponding connection properties.
PLC features
INSYTE SPIDER 2
To work with a SPIDER 2 controller via the Modbus TCP protocol, activate the possibility of work with this protocol in the network settings of the controller, the Ethernet tab. Example of configuration:
Make sure your SPIDER 2 controller has firmware 1.40 or later. Otherwise, there can be big delays of connection with the controller and problems in work with Coil registers.
When creating commands, shift the addressing by "-1" in relation to INSYTE: in SPIDER 2 register addresses start with 1, and in iRidium - with zero.
To refer to SPIDER 2 VARIABLES use the formula:
Address = 1000 + [slot number]*2
Each variable has a slot number. It is seen when you point the mouse cursor on the variable. Type: Holding Register, Word Size: Dword(32-bit)
For sending IR commands use:
Address = the number of IR emitter
Value = the number of IR command
Beckhoff
Modbus/ADS memory card for Beckhoff CX8090:
Modbus areas
|
Modbus address (HEX)
|
Modbus address (DEC)
|
ADS area
|
Digital inputs |
0x0000 - 0x7FFF |
0 - 32767 |
Index group: 0xF021 - process image of physical inputs (bit access) |
Index offset: 0x0
|
0x8000 - 0x80FF |
32768 - 33023 |
Name of the variables in PLC program: .mb_Input_Coils |
Data type: ARRAY [0..255] OF BOOL
|
Digital outputs (coils) |
0x0000 - 0x7FFF |
0 - 32767 |
Index group: 0xF031 - process image of physical outputs (bit access) |
Index offset: 0x0
|
0x8000 - 0x80FF |
32768 - 33023 |
Name of the variables in PLC program: .mb_Output_Coils |
Data type: ARRAY [0..255] OF BOOL
|
Input registers |
0x0000 - 0x7FFF |
0 - 32767 |
Index group: 0xF020 - process image of physical inputs
|
Index offset: 0x0
|
0x8000 - 0x80FF |
32768 - 33023 |
Name of the variables in PLC program: .mb_Input_Registers |
Data type: ARRAY [0..255] OF WORD
|
Output registers |
0x0000 - 0x2FFF |
0 - 12287 |
Index group: 0xF030 - process image of physical outputs |
Index offset: 0x0
|
0x3000 - 0x5FFF |
12288 - 24575 |
0x4020 - PLC memory area |
0x0
|
0x6000 - 0x7FFF |
24576 - 32767 |
0x4040 - PLC data area |
0x0
|
0x8000 - 0x80FF |
32768 - 33023 |
Name of the variables in PLC program: .mb_Output_Registers |
Data type: ARRAY [0..255] OF WORD
|
Read/Write Holding Registers:
- iPad1 AT %MB0 : WORD; (*address 12288*)
- iPad2 AT %MB1 : WORD; (*address 12289*)
Read/Write Coils. It is required to create global_var in the array mb_Output_Coils:
- mb_Output_Coils AT %QB1000 : ARRAY[0..255] OF BOOL;
- Create the variables:
- iPad1 AT %QX1000.0 : BOOL; (*address 32768*)
- iPad2 AT %QX1001.0 : BOOL; (*address 32769*)
- iPad3 AT %QB1002 : ARRAY[0..5] OF BOOL; (*address 32770-32775*)
- iPad3 AT %QB1007 : ARRAY[0..5] OF BOOL; (*address 32775-32780*)
Modbus/ADS memory card for Beckhoff BC9хх0:
Calculation of the Modbus address Read/Write Holding Registers is performed using the formula:
Address = 16384 + 12 - 1 = 16395
- 16384 - the beginning of the area %MB (0x4000-0x47FF)
- 12 – the variable index (it can be seen in the variable properties)
- 1 – takes into account counting from zero
ОВЕН
When setting up the controller, in the FIX
property it is required to add the ТСР Port of conenction to the controller. It is 502 by default. One port contains one connection of ТСР Master (the iRidium client).
Numbers of Modbus registers can see by such addresses as%QB7.1.5
:
Address = %QB7.1.5 - 1 = 5 - 1 = 4
The last number of the address minus one - it is the register number which is indicated in iRidium.
Alligning of CoDeSys variables when placing them in the Modbus memory area:
Variables with sizes 8 bits, 2 bytes and 4 bytes should be located only at particular addresses. The address of a 4-byte variable is devisable by 4, the address of a 2-byte variable is devisable by 2 and the address of a 1-byte variable is devisable by 1. The addresses can be in any point of the memory space. I.e. if the first variable has the “byte” type it will be located at the address 0х00, the following - at 0х01 and etc. If a 4-byte variable goes next, it has to be located at the address 0х04 and etc. At that if a 1-byte variable took the place devisable by 4, the next 4-byte variable takes the next free place devisable by 4. The way of adding variables is random but the alignment puts the variables on the places which are devisable by their length. As a consequence, there are memory places which are not taken by anything. They should be considered by the user when the status of the device is requested. It should be done at the point of adding the variables.
Adding and Setting Subdevices
A required number of subdevices can be added to a driver of the Network type. Each subdevice can be responsible for a separate type of equipment (light, air-conditioner). To add a subdevice, click left mouse button on the added driver (Network) and choose Add subdevice > Custom.
Settings of subdevices:
- Name - the name of a subdevice;
- Driver Type - the type of a driver;
- Device ID - the individual identifier of a device;
- Number of attempts - the number of attempts to request a device, if it does not answer;
- Skip to recovery - the number of missed requests of a subdevice, if it does not answer (it works when connection attempts are over "Number of attempts");
- Change Write Function - it turns on/off the following settings "Coil Write function" and "Holding write function". If it is on, the settings of a subdevice are taken, If is is off, general settings of "Coil Write function" and "Holding write function" are taken for network;
- Single Poll - it turns on a separate request of registers (if it is off - neighbouring registers are requested with one packet , if it is on - each register is requested with a separate packet).
- Holding Write Function- a mode to send commands to output registers (Single - writing one register ,Multiple - writing several registers);
- Single Poll - it turns on separate request of registers (if it is off, neighbouring registers are requested with one packet, if it is on - each register is requested with one packet).
Control of registers
To control equipment, set commands (Commands) and feedback channels (Feedbacks). To send a command, drag'n'drop it on a graphic item and enter a value (Value) to be sent. To display a value from a feedback channel, drag'n'drop a feedback channel on a graphic item and enter how to output/display a value.
Read more about work with graphic items in the "Types of graphic items" article.
Possible settings of commands, channels and graphic items are presented below:
Coil
Command:
Device ID |
0 .. n |
the PLC identifier (Slave ID)
|
Type |
Coil |
the flag register available for reading and writing
|
Address |
0 .. n |
the register address in the decimal format
|
Value * |
|
value
|
0 .. 1 |
|
0 = Off, 1 = On
|
* - indicate when dragging the command on graphic items
Feedback:
The settings are similar to commands. Values come to Feedback and they can be used for displaying the status of registers on items
Holding
Command:
Device ID |
0 .. n |
the PLC identifier (Slave ID)
|
Type |
Holding Register |
the register for storing, available for reading and writing
|
Address |
0 .. n |
the register address in the decimal format
|
Word Size |
Word(16 bit) |
16-bit word corresponding to the standard Modbus protocol
|
Word(16 bit) unsigned |
16-bit unsigned word corresponding to the standard Modbus protocol
|
DWord (32-bit) |
32-bit word consisting of two standard Word registers
|
Float (32-bit) |
32-bit word with floating point
|
Dword(32 bit) unsigned |
32-bit unsigned word, consisting of two standard Word registers.
|
Content Type A definite "Content Type" is used for different types of equipment. |
Low Endian |
writing begins with the lower byte and ends with the higher byte (b1, b2, b3, b4)
|
Big Endian |
the writing begins with the higher byte and ends with the lower byte (b4, b3, b2, b1)
|
Swapped Low Endian, Swapped Big Endian |
bits in each word are written in the reversed order (n,...,1)
|
Value * |
Word Size |
value
|
0 .. 65535 |
Word(16 bit) |
unsigned 2 bytes
|
-32768 .. 32767 |
Word(16 bit) |
signed 2 bytes
|
0 ... 4294967295 |
Dword(32 bit) |
unsigned 4 bytes
|
-2147483648 .. 2147483647 |
Dword(32 bit) |
signed 4 bytes
|
-2147483648.0 .. 2147483647.0 |
Float(32 bit) |
4 bytes with floating point
|
0 ... 4294967295 |
Dword(32 bit) unsigned |
4 unsigned bites
|
Feedback:
The settings are similar to commands. Values come to Feedback and they can be used for displaying the status of registers on items
Discrete Inputs
Feedback:
Device ID |
0 .. n |
the PLC identifier (Slave ID)
|
Type |
Discrete Inputs |
the discrete register available for reading only
|
Address |
0 .. n |
the register address in the decimal format
|
Value * |
|
value
|
0 .. 1 |
|
0 = Off, 1 = On
|
* - Values come to Feedback and they can be used for displaying the status of registers on items
Input Register
Feedback:
Device ID |
0 .. n |
the PLC identifier (Slave ID)
|
Type |
Input Register |
the input register, available for reading
|
Address |
0 .. n |
the register address in the decimal format
|
Word Size |
Word(16 bit) |
16-bit word
|
DWord (32-bit) |
32-bit word consisting of two standard Word registers
|
Float (32-bit) |
32-bit word with floating point
|
Content Type |
Low Endian |
the writing begins with the lower byte and ends with the higher byte (b1, b2, b3, b4)
|
Big Endian |
the writing begins with the higher byte and ends with the lower byte (b4, b3, b2, b1)
|
Swapped Low Endian, Swapped Big Endian |
bits in each word are written in the reversed order (n,...,1)
|
Value * |
Word Size |
value
|
0 .. 65535 |
Word(16 bit) |
unsigned 2 bytes
|
-32768 .. 32767 |
Word(16 bit) |
signed 2 bytes
|
0 ... 4294967295 |
Dword(32 bit) |
unsigned 4 bytes
|
-2147483648 .. 2147483647 |
Dword(32 bit) |
signed 4 bytes
|
-2147483648.0 .. 2147483647.0 |
Float(32 bit) |
4 bytes with floating point
|
* - Values come to Feedback and they can be used for displaying the status of registers on items
Monitoting
You can see all information about sent and received values of a controller for a definite period of time in the web-interface. To go to the Monitoring tab, enter the server web-interface and choose WORK > Drivers > Monitoring. The monitoring system works for TCP as well as for RTU drivers.
Example of monitoring for Modbus RTU Network:
- Start log - a button to turn on logging (logging is off by default);
- Stop log - a button to turn off logging (the workspace with the log is not cleared);
- Save to CSV - a button to save the log in an Excel table;
- Disable Scroll - turn off a function to scroll the log;
- Clear - a button to clear the log. The log is cleared automatically, when there are 1000 log files;
- Date/time - date and time of the log file (a request period is set in the driver settings);
- Log level - the level of logging (it is set in the driver settings);
- Command Type - a type of commands:
- Receive - write the answer from equipment (feedback);
- Send - write a request from the driver to equipment (command);
- Value - a sent / received value (equipment sends a packet that contains the address of the device, the type of functions and a value in the hexadecimal system).