MODBUS enables you to establish master-slave communications with any connected device that supports the MODBUS protocol. Any controller in the network may function as either master or slave using any of the controller's existing COM Ports.
Unitronics currently supports MODBUS in the following transmission modes:
RTU (binary)
M91 |
The M91 series supports MODBUS via built-in COM ports |
Jazz |
Although Jazz PLCs do not comprise built-in COM ports, Jazz can support MODBUS if you install an appropriate add-on port module, available separately. |
M90 |
The M90 series does not support MODBUS |
Jazz |
Jazz 2 controllers can support Ethernet via an Add-on Port module plugged into the Jazz Jack. For more information, refer to the topic Ethernet: Jazz_2_only. Via this port, you can run MODBUS commands over Ethernet. |
Note that:
Communications capabilities are determined by the type of Add-on Module.
Default COM settings and pin-outs are given in the technical specifications of the relevant Add-on Port.
The MJ20-PRG Programming Port may be used for RS232 communications with devices that supply active (RS232 positive voltage) DTR and RTS signals.
Since there are no Ladder elements for MODBUS functions; you perform them by storing values into SIs in accordance with the tables and figures shown below.
Before you can run a MODBUS command, you must configure MODBUS parameters for both Master and Slave devices.
These parameters configure a controller for MODBUS communications. A device is configured for MODBUS by storing the value 600 into SI 140.
To configure a slave device, build a Ladder net that stores the appropriate values into the SIs according to the following table, and that ends by storing the value 600 into SI 140.
Jazz Users: note that in order to implement MODBUS via RS485, you must first configure MODBUS, and then initialize the Jazz port to RS485 as explained in the topic Change COM Port Parameters.
Parameter |
Store into SI |
Function |
Network ID |
141 |
Range: 0-255. This is the Network ID number of the device on the network. You can either assign an ID via an MI, or directly via a constant number. Do not assign the same ID number to more than one device. |
Time out |
142 |
Time out units:10 msecs; a Time out value of 100 is equal to 1 second. This is the amount of time a master device will wait for an answer from a slave. |
Retries |
143 |
This is the number of times a device will try to send a message. |
Maximum Time Delay |
144 |
Time units: 2.5 msec. This is the maximum time interval permitted between 2 messages. This should be set to 2, setting the permitted interval to 5 msecs (n x 2.5 =interval). |
Baud Rate |
145 |
Store the value into SI 145 to set the baud rate. Note that Jazz does not support the following baud rates: 110, 38400, 57600. In addition, ‘2’ Stop Bits is not supported. In Jazz controllers; use Function 310 to modify the default settings of an Add-on Port. Legal Baud rates are: 110 300 600 1200 2400 4800 9600 19200 38400 (store 384) 57600 (store 57600) |
Call MODBUS Configuration |
140 |
This must be the final parameter stored. Storing the value 600 into SI 140 configures the controller for MODBUS. Storing the value 599 into SI 140 configures the controller for MODBUS and also enables Unitronics' PC applications to access the PLC. |
Note that Unitronics software applications, such as U90 Ladder, Remote Access, and DataXport, all use the 'backslash' character ( / ) (ASCII character 47) as the Start of Text (STX) character. Therefore, in order to enable a Unitronics' PC application to access a PLC communicating via MODBUS:
Configure MODBUS by using Command Number 599 instead of 600. This means that after you store all of MODBUS Configuration parameters as shown above, you must store 599 into SI 140.
Do NOT use controller ID number 47 in your network. Doing so will cause communication conflicts, since MODBUS protocol uses the controller ID number to begin communications strings while Unitronics applications use ASCII character 47 as an STX.
There are two differences in the values you store to enable MODBUS over Ethernet:
Parameter |
Store into SI |
Function |
Network ID |
141 |
You must store 255 into SI 141, or MODBUS will not run. |
Call MODBUS Configuration |
140 |
Command 600 enables MODBUS only. Command 599 configures the controller for MODBUS and also enables Unitronics' PC applications to access the PLC. Note that this requires OS 2.22, B03 and higher. |
You can use the status of SB 198 to restrict MODBUS Master access to a specified range of operands.
To restrict the range of accessible MBs, store the start address in SI 165, and the end address in SI 166.
To restrict the range of accessible MIs, store the start address in SI 167, and the end address in SI 168.
Before you can call a MODBUS command, you store the appropriate parameter values into the correct SIs in accordance with the Command Parameters table. After this is done, call the command by storing the command number into SI 140.
The figure below shows how to implement the MODBUS command Read Output Registers.
Parameter |
Store into SI |
Function |
||||||||||||||||
Slave Unit Network ID |
141 |
The ID of the slave device containing the data to be read (data source). |
||||||||||||||||
Slave: Start of Vector |
142 |
The start of the vector of operands in the slave. Check the Slave Address Tables below. |
||||||||||||||||
Vector Length |
143 |
The vector length. |
||||||||||||||||
Master: Operand Type |
144 |
Store the number that relates to the type of operand you wish to write to in the master device.
|
||||||||||||||||
Master start of Vector |
145 |
|
||||||||||||||||
MODBUS Command |
140 |
|
Note ♦ |
While a master attempts to send a command, SB 66 Function In Progress is ON. The number of attempts that the master will make is the number in Retries +1, where '1' is the initial access attempt. |
♦ |
When a master attempts to access a
slave device, and the slave does not answer, SB 66 Function
In Progress will turn ON. This bit will remain on according
to the following: |
The number in parenthesis is given for reference purposes only; it is the standard MODBUS command number.
MODBUS Commands |
U90 Command # (Value to store into SI 140 |
Read Coils (1) |
601 |
Force Coil (5) |
602 The value you enter in SI 145 (0 or 1) is written (forced) to the coil whose address is given in SI 144. Do not set Vector length (SI 143). |
Force Coils (15) |
603 |
Read Registers (3) |
604 |
Preset Register (6) |
605 |
Preset Registers (16) |
606 |
Read Input Registers (4) |
609 |
Read Inputs (2) |
611 |
Loopback Test (8) |
612 |
SB 66 Function in Progress |
Turns ON when:
|
Turns OFF when
|
SI 66 Shows status of master's data requests and the replies the master receives from the slaves |
|
# |
Status Message |
0 |
Status OK |
1 |
Unknown Command Number This is received from the slave device. |
2 |
Illegal Data Address
|
3 |
Slave
to Master: Illegal Data Type Quantity Note ♦ A MODBUS command cannot read more than 124 16-bit integers, or 1900 bit operands at one time. In addition, 0 is not a legal vector length. |
4 |
Master--Time Out |
5 |
No
Communication |
Note ♦ Messages 4 & 5. TimeOut and Number of Retries are defined as Configuration Parameters. A Retry is an attempt to establish a MODBUS session. If, for example, TimeOut is defined as 2 seconds,
and number of Retries as 3: -If any attempt succeeds, the Status Message will be 0. |
|
* 6 |
Master-slave data incorrectly synchronized |
* 7 |
Master-slave data incorrectly synchronized |
8 |
Master
to application: Illegal Data Type Quantity Note
♦
A MODBUS command cannot
read more than 124 16-bit integers, 62 double registers,
62 float registers, or 1900 bit operands at one time. |
9 |
Slave ID =0 An attempt does to communicate with Slave ID 0. |
* 11 |
Master-slave data incorrectly synchronized |
* Messages 6, 7, and 11mean that the master has found incompatible elements in the data sent between master and slave. |
Coils |
MODBUS Command Number |
||
---|---|---|---|
Pointer Value From: |
Operand type |
Read |
Write |
0000 |
MB |
#601 Read Coils |
#602/603 Force Coils |
3000 |
SB |
#602/603 Force Coils |
|
4000 |
I (read-only) |
Read-only |
|
5000 |
O |
#602/603 Force Coils |
|
6000 |
T(read-only) |
Read-only |
Registers |
MODBUS Command Number |
|||
Pointer Value From: |
Operand type |
Register size |
Read |
Write |
0000 |
MI |
16 bit |
# 604 Read Registers |
# 16 Preset Registers |
4000 |
SI |
16 bit |
||
6900 |
Timer preset |
16 bit |
||
7200 |
Timer current |
16 bit |
The examples below show that:
MODBUS addressing systems start at 1.
Unitronics PLC addressing starts at 0.
Bit Operands
Read a 10-bit vector of inputs from a slave Unitronics PLC, starting at Input 20, into MB 8 - MB 17 in a master Unitronics PLC via Read Coils (Command 601)
Unitronics PLC as the MODBUS master
Store 4020 into SI 142 (Slave: Start of Vector parameter), 10 into SI 143 (Read: Vector Length parameter), 1 into SI 144 (Master: Operand Type), 8 into SI 145, and 601 into SI 140. Within the slave PLC, the master PLC will read I 20 - I 29 and force their status into MB 8 - MB 17 .
SCADA
as the MODBUS master
In the SCADA application, set the Slave: Start of Vector parameter
to 34021(30001 + 4000 + 20), and the Read: Vector Length to
10, enabling the master device to read I 20 - I 29 within
the slave PLC.
Write a 3-bit vector of outputs into a slave Unitronics PLC, O 8 O 10; from data source I 5 -I 7 in a master Unitronics PLC via Force Coils (Command 603).
Unitronics PLC as the MODBUS master
Store 5008 into SI 142 (Slave: Start of Vector parameter), 3 into SI 143 (Read: Vector Length parameter), 9 into SI 144 (Master: Operand Type), and 603 into SI 140. Within the slave PLC, the master will copy the status of its operands I 5 -I 7 to the slave's operands O 8 - O 10.
SCADA
as the MODBUS master
In the SCADA application, set the Slave: Start of Vector parameter
to 35009 (30001 + 5000 + 8) and the Read: Vector Length parameter
to 3, enabling the master device to write to O 8 - O 10 within
the slave controller.
Registers
Read a 2-register long vector of 16-bit integers from a slave Unitronics controller, starting at SI 80, via Read Holding Registers (Command 604) into a master PLC registers, MI 101-109
Unitronics
PLC as the MODBUS master
Store 4080 into SI 142 (Slave: Start of Vector parameter),
2 into SI 143 (Read: Vector Length parameter), 3 into SI 144
(Master: Operand Type),and 604 into SI 140. Within the slave
PLC, the master PLC will read the values of MI 32 - MI 40
and copy them into its own registers, SI 80 - SI 81.
SCADA
as the MODBUS master
In the SCADA application, set the Slave: Start of Vector parameter
to 40033 (40001 + 0000 + 3), and the Read: Vector Length parameter
to 9, enabling the master device to read MI 32 - MI 41 within
the slave controller.
Note ♦ |
M91 does not support 32-bit registers. |
Write a 6-register long vector of 16-bit integers into a slave Unitronics controller, starting at MI 32, via Preset Registers (Command 606); the data source is MI 100 - 105 in the Master PLC
Unitronics
PLC as the MODBUS master
Store 32 into SI 142 (Slave: Start of Vector parameter), 6
into SI 143 (Read: Vector Length parameter), 3 into SI 144
(Master: Operand Type),and 606 into SI 140. Within the slave
PLC, the master PLC will copy its internal registers values
from MI 100 - 101 into the slave's MI 32 - MI 38.
SCADA
as the MODBUS master
In the SCADA application, set the Slave: Start of Vector parameter
to 40033, and the Read: Vector Length parameter to 6, enabling
the master device to write to MI 32 - MI 37 within the slave
controller.