Modbus English Document v7 20180718 - 1645
Modbus English Document v7 20180718 - 1645
document
修改日期: 06-Mar-2018
目錄
目錄
Document infor.
Document history
Table of Contents
Introduction
This document is mainly for the SYNTEC of internal customer service and technical staff. Do
training through documents, education and training, so that colleagues understand and
master the Modbus bus and its use.
The contents of this document include an introduction to Modbus protocol and
instructions, the use of Modbus components of the SYNTEC of PLCs, and general purpose
Modbus plug-ins. It is expected that by reading this document, you will have a good
understanding of the Modbus application of the SYNTEC of controllers. If you need more
detailed information, you can contact the SYNTEC of head office.
1 MODBUS protocol introduction
1.1 Overview
Modbus was invented by Modicon (now a brand of Schneider Electric) in 1979 and is the
world's first bus protocol to be truly used in industrial fields. Popular to say: it is a common
language used in electronic controllers. Through this agreement, the controller can carry
on the data transmission with each other.
Modbus bus master-slave request / response mechanism. As shown in Figure 1, if a
controller sends a message as a master, a response can be returned from a slave device.
Similarly, when a controller accepts a message, it organizes the response message of a
slave device and returns it to the controller that sent the message.
4
Figure 1 Modbus request/response mode
1.2 Modbus transmission mode and its characteristics
The standard Modbus communication modes are mainly ASCII (American Information
Interchange code) mode, RTU (Remote Terminal Equipment) mode and Modbus / TCP
mode.
Among them, Modbus ASCII mode to send a byte of data converted to two bytes of ASCII
code. The main advantage of this mode is that it allows characters to be as long as, and will
not complain. At the same time, ASCII printable characters facilitate fault detection and are
suitable for host computers and host PCs programmed in high-level languages such as
Fortran.
Modbus RTU protocol data is encoded in binary, each byte of data requires only one byte
of traffic, and the message characters must be transmitted as a continuous stream of data.
The advantage is that at the same baud rate, more data can be transferred than in ASCII
mode. Computer and PC host for machine programming.
Modbus / TCP can be understood as Modbus over Ethernet. Modbus / TCP uses only the
TCP / IP standard to simply pack and compress Modbus packets. This allows Modbus / TCP
devices to connect and communicate over Ethernet and optical networks. Compared with
RS-485 interface, Modbus / TCP also allows to use more addresses, you can use multi-
master architecture, the transfer rate can reach GB / s level. The number of Modbus / TCP
network slaves is limited only by the capabilities of the network physical layer. Usually the
number of stations generally about 1024.
1.3 Modbus RTU mode and its information frame
5
Modbus RTU communication using master-slave mode, up to 255 bytes of data
transmission. The master communicates with one or more slaves. The typical main
equipment is PLC, PC, DCS (Distributed Control System) or RTU (Remote Terminal Unit).
Slave devices for Modbus RTU are generally field devices. When a Modbus RTU master
wants to get data from a slave, the master sends a data packet containing the address of
the slave, the required data, and a CRC for detecting the error. This information is received
by all other devices on the network, but only the slave device whose address is specified
will respond. Slaves on the Modbus network cannot initiate communications and can only
reply when the master speaks to it.
At the same time, Modbus RTU uses a 16-bit cyclic redundancy check (CRC). By a complex
program of ORing and shifting operations, a CRC is generated by the master and checked
by the receiving device. If the CRC value calculated by both parties does not match, the
slave device will request the retransmission of the message.
Modbus messages are transmitted as frames and each frame has a defined start and end
point, allowing the receiving device to read the address at the beginning of the message
and to determine the device to be addressed and the end of the message transfer. As
shown in Figure 2, Modbus message frame consists of address field, function code, data
and error checking. Among them, ADU is the application data unit, PDU is the agreement
data unit.
6
Master asked 01 03 00 64 00 01 C5 D5
Next, set the Modbus communication speed, data bit length, parity code mode, stop bits,
and timeout according to the device communication requirements on the Modbus bus.
Again, all devices on the Modbus bus should have the same communication modes and
serial communication parameters.
If the SYNTEC of X86 architecture controller, refer to Table 3:
Table 3 X86 architecture of the SYNTEC of Modbus port
7
3969 Third port stop bits 1
Register type Applicable function code Read and write status Operation bit SYNTEC memory block
01H denotes read coil, 02H denotes read discrete input, 03H denotes read-holding
register, 04H denotes read input register, 05H denotes write single coil, 06H denotes write
single register, 0FH denotes write multiple coils, 10H denotes write multiple register.
This shows that: in the Modbus bus, if the SYNTEC controller is a slave, the function codes
01H, 05H and 0FH can read / write the O-bit, C-bit and A-bit of the SYNTEC controller;
Function code 02H can read I-bit and S-bit of SYNTEC controller; function codes 03H, 06H
and 10H can read / write R-bit of SYNTEC controller.
It is worth noting that since the R-bit in the SYNTEC system is based on 32 bits, but
Modbus can only support 16 bits, the R register of the SYNTEC system uses two Modbus
standard register addresses to represent the SYNTEC of 32 bits R register high and
position, as shown in Table 6. To write R value after R30000, please refer to the SYNTEC
Modbus Slave Specification.
9
Table 6 New R register address in Modbus
R0 High 0
Low 1
R1 High 2
Low 3
Low 60001
Slave address Function code Register start address Number of registers CRC check
11 03 00 6B 00 03 -
Among them, the starting address of the register is from the station to store data starting
register number; the number of registers that the master station to read from the station a
few consecutive registers.
The message format of the slave response is:
Slave address Function code Number of bytes Register data CRC check
11 03 06 02 2B 00 00 00 64 -
Among them, the number of bytes that the slave feedback data has a few bytes; register
data that the master reads the actual value of the slave registers.
10
2.1.2 10H Function Code Introduction and Packet Analysis
10H function code to write multiple holding registers. Its role as the master will write one
or more consecutive register data to the specified slave register.
The message format that the master inquiry is:
Slave address function code Register start address Number of registers Number of bytes data input CRC check
11 10 00 01 00 02 04 00 0A 01 02 -
Among them, the starting address of the register is from the station to store data starting
register number; the number of registers that the master station to write a few registers
from the station. The number of bytes indicates how many bytes the master writes to the
slave. It can be seen, in the standard Modbus communication, a register can store two
bytes or 16bits of data.
The message format of the slave response is:
Slave address Function code initial address Number of registers CRC check
11 10 00 01 00 02 -
Among them, the starting address of the register is the starting register number for the
slave to store data; the number of registers indicates the number of registers that the slave
station stores the data sent by the master.
2.2 Serial debugging software in Modbus debugging application
2.2.1 Serial debugging software introduction
Serial debugging software is a software for serial debugging and monitoring. It combines
data transmission, data reception, data analysis and many other features in one, with
compact, simple operation, powerful features, won the user favorite. So that users in the
serial port communication monitoring, device communication test, can effectively improve
work efficiency.
11
This article savage - serial debugging assistant UartAssist V4.0 version, as shown in Figure
4. The software is divided into parameter editing area, Modbus message monitoring area
and Modbus command sending area.
12
Figure 6 common Modbus bus wiring
STEP2: Open UartAssist.exe, automatically detect or manually set the COM port. Then
configure the baud rate, parity bit, data bits and stop bit serial port parameters. Finally,
open the serial port. As the picture shows. If "[ERROR] Cannot open COM port" appears,
please check the PC COM port.
Open the serial port on the normal PC, let's take a look at this debugging software can give
us what function?
First, we can monitor the message from the master / slave on the Modbus bus on the PC
side, as shown in Figure 7. In this way we can analyze the condition of the equipment on
the Modbus bus and the anomaly analysis based on the actual message.
13
At the same time, PC-side through the serial debugging software, can be used as the
master on the Modbus bus, Modbus slave device commands. As shown in Figure 7, the PC
can test whether the slave device responds or not by knowing the packet format in
advance. It can be used to troubleshoot when communication between master and slave
devices is abnormal.
14
Figure 7 PC-side test from the station response status
3 SYNTEC Modbus function application
3.1 SYNTEC of common Modbus plug-in
3.1.1 General Modbus plug-in introduction
The SYNTEC of common Modbus plug-in is a Modbus communication module using
human-machine dialogue mode. It provides a graphical Modbus communication data
input window, eliminating the need for users to write PLC trouble. It is noteworthy that it is
often used: SYNTEC controller in the Modbus bus as a master, and the real-time
requirements are not very high occasions.
15
Figure 8 New generic Modbus plug-in human machine screen
It can be seen from Figure 8 that the man-machine interface of the general-purpose
Modbus plug-in is very simple. It contains ten groups of Modbus instruction editing
columns, communication test keys and Modbus communication enable / disable keys.
Understanding of Modbus function code and message rules, users only need to configure
basic Modbus message parameters to realize Modbus communication between SYNTEC
controller and slave devices.
3.1.2 General Modbus plug-in parameter detailed explanation
Below the first set of Modbus instruction setting bar as an example, describes the use of
generic Modbus plug-in.
16
As shown in Fig. 9, the setting items of each group of commands include whether to
enable, station number, target read / write position, function code selection, number of
addresses read and written each time, R value of data storage, read and write frequency
and trigger / Status R value and other parameters setting items.
Wherein, the target read / write location setting item refers to the start address of the read
/ write register corresponding to the slave station in Modbus; each time the read / write
address quantity setting item refers to the number of read / write registers corresponding
to the slave station; The initial value of R is the start register for storing read / write data in
the master. The trigger / status R value is the register for the group of Modbus command
trigger flags and status displays.
17
As shown in Figure 12: Read and write frequency setting is the Modbus command trigger.
When set to 0, it means that the system executes once when the system is powered on or
when "Enable Communication" is clicked. When set to 1, it indicates that it executes once in
100ms. The plug-in supports up to three 100ms ports. When set to 2, it indicates that 1s is
executed once; when set to 3, it is executed once when the specified trigger R value is set
to 1.
Due to technical limitations, when set to 0.1s or 1s once, the actual cycle may not be able
to achieve. Will be affected by the number of communication groups and the number of
data communicated by each group. At the same time, tests show that the plug-in read-
write failure rate of less than 30ms up to 80%. So in the cycle of less than 300ms or real-
time requirements of high circumstances, it is recommended to switch to PLC processing.
18
The plug-in installation process is as follows:
STEP1: According to the standard software installation, installation of common Modbus
plug-in software package.
STEP2: Set RS485 serial port parameters (Pr3941-Pr3950).
STEP3: [Maintenance] - [F10] - [F10] - [Modbus module] to enter the Modbus plug-in page.
According to actual demand, configure the parameters.
STEP4: Click [Test Communication] to confirm whether it is normal. If it is normal, click
[Modbus Communication On]. If communication error, please check [Status & Trigger R
Value] to check the error code.
3.1.4 Application examples
This section uses the Modbus communication between two HC-10B-Ss as an example to
introduce the usage of the SYNTEC generic Modbus plug-in.
Application Scenario: Take one HC-10B as master station, read the value of slave controller
R50-54 in real time with a period of 0.1s; write the value in master R60 into the slave
controller in real time in 1s cycle R60; The master writes the value of R70-79 to R70-74 of
the slave controller through the R value triggering mode.
Implementation process:
STEP1: According to the standard software installation, install the common Modbus plug-
in software package on the main station HC-10B.
STEP2: According to the principle of consistent Modbus communication parameters, set
the master and slave serial port parameters (Pr3941-Pr3950). At the same time, we need to
enable Modbus Slave mode for slave HC-10B. As shown in Figure 15.
19
Figure 16 Master Modbus parameter settings
STEP4: Click [Test Communication] to confirm whether it is normal. If it is normal, click
[Modbus Communication On]. If communication error, please check [Status & Trigger R
Value] to check the error code.
STEP5: Experimental verification.
First, let's analyze what the first set of Modbus instructions does. It mainly realizes that the
master controller reads the value of the slave controller R50-R54 and puts the data of the
slave into the master's R50-R59. As shown in Figure 17.
20
Why is the value from the station controller R50-R54 into the main station R50-R59? We
have already introduced before: The R register of SYNTEC controller is 32bits, however, the
register of standard Modbus communication is 16bit. Therefore, the SYNTEC of internal
controller will be an R value is split into high and low, and then communicate. For example,
R50 high 16bits communication address is 100; its low 16bits communication address is
101. Therefore, the master station to read from the station R50-R54 value, you have to
translate into 10 register addresses, and these 10 data once into the master designated R
value, in this case, these 10 data Put into the main station R50-R59. Among them, the main
station R50 is R50 high 16-bit data from the main station R51 R50 from the station low 16-
bit data.
Next we look at the second set of Modbus instructions, which mainly implements that the
master controller writes the value of R60 to the lower 16 bits of the slave controller R60.
Among them, according to the SYNTEC Modbus Slave specification, it can be seen that the
lower 16 bits of the Modbus communication address of the controller R60 is 121. However,
one might wonder if the master's R60 is a 32-bit register whose high 16 value is written to
the slave? The answer is no! SYNTEC of controllers in the Modbus communication, the
default 32-bit register as a 16-bit R value to use more than 16-bit value is not considered.
This needs to be taken into account when using it.
Finally, we look at the third group of Modbus instructions. It mainly implements that the
master controller writes the values of R70-R79 into the R70-R74 of the slave controller. By
the same token, the lower 16 bits of the master R70-R79 will be written to the slave
controller. However, it should be noted here that the 10 data will be placed in the R70-R74
of the slave controller. Why is this? Or because the SYNTEC R register is 32 bits. By default,
these ten 16-bit data will be written into the data from the first designated slave address. In
this case, the first address of the slave is 140 corresponding to the upper 16 bits of R70.
21
Figure 18 Three sets of Modbus instruction execution results
As shown in Figure 18, the results of three sets of Modbus instructions are as follows: After
the first group of master stations read the values of slave R50-R54, the master's R51 = R53
= R55 = R57 = R59 = 1; The group master controller writes the value of R60 to the lower 16
bits of the slave controller R60 and the slave R60 = 1. The third group of master controllers
writes the value of R70-R79 to the slave controller's R70. After R74, slave R70 = R71 = R72
= R73 = R74 = 65537. At the same time, we can find R65 / R66 / R67 three trigger / state R
values are 16 in the figure, which means that Modbus transmission is normal.
3.2 SYNTEC PLC in the Modbus components
If the SYNTEC controller is used as the master in the Modbus bus, then the read / write
commands to the slave devices can be realized through the Modbus components of the
PLC so that the data interaction with the slave devices can be realized. Before learning a
SYNTEC of Modbus components, we need to understand the SYNTEC Modbus related
flags.
The SYNTEC controller monitors the status of Modbus communication via Register R608.
As shown in Figure 19: R608.0 is Modbus communication reset flag, R608.10 is Modbus
communication complete flag.
22
Among them, if R608.0 is set to 1, it means that the SYNTEC system is in the transmission
standby state and the PLC can send data currently. If R608.10 is 1, then Modbus
communication is completed. If any error occurs during transmission, R608.31 is 1 and the
error is displayed on R5039.
3.2.1 Modbus read device
As shown in Figure 20, when the PLC module MODR is used to read multiple register data
from the specified slave device,
23
Modbus message content Detailed:
Slave Address 01 RS
Function 03
24
SLAVE RESPONSE Example
Slave Address 01
Function 03
Byte Count () 1E
...
25
Figure 22 Modbus write elements of the PLC
MODW writes to the MODBUS RTU16 component, only 1 data can be written. As can be
seen from Figure 23, the component parameters are in order: the address of the start
address of the slave data, the data content stored in the slave and the slave station
number. It is worth noting that all addresses are filled in decimal.
26
Modbus message content Detailed:
Slave Address 01 RS
Function 06
27
(Slave response message) (Hex)
Slave Address 01
Function 06
28
Figure 25 PLC MODRS component settings
Application Example 3: Master HC-10A uses MODRS module to write a 32bit data to R50 of
slave HC-10B via Modbus bus. Among them, the first 16 bits are written to the high bits of
R50 and the last 16 bits are written to the low bits of R50.
PLC example:
29
Modbus message content Detailed:
Slave Address 01
Function 10
No. of Registers Hi 00
No. of Registers Lo 02
30
Byte Count 04
Data Hi 00
Data Lo 00
Data Hi 00
Data Lo FF
Slave Address 01
Function 10
31
Application scenario: The customer wants to read the real-time current of the inverter
through MODBUS to detect whether the spindle is overloaded. Therefore, the SYNTEC PLC
module MODR read.
Implementation process:
STEP1: As shown in Figure 26, complete the SYNTEC system and Yaskawa V1000 inverter
RS485 serial port wiring.
33
STEP4: Experimental verification. As shown in Figure 29, when the PLC is triggered, the PC
can display the message sent by the controller as the master: 02 03 00 26 00 01 65 F2, the
response from the slave is 02 03 02 00 00 FC 44. According to the second chapter of the
message analysis results for the normal.
34
Figure 29 Serial debugging software monitoring
4 Common exception excluded
When the SYNTEC system as a Modbus master command, if R608 = 1, serial
debugging software monitoring no data sent, please check the SYNTEC parameter
Pr3234, check whether the master station starts the slave mode.
If found R608.31 = 1, it means Modbus communication error. R5039 can check the
error code to determine the cause of the error.
35
If R5039 = 0xFA, it means the communication has exceeded the specified time
(TimeOut error). This may be due to the setting of the master and slave error, master
and slave Modbus communication parameters are inconsistent.
The SYNTEC PLC system components using decimal programming instructions, and
serial debugging software to monitor the data using hexadecimal.
Prompt communications timeout, how to check?
36
2.
2. Check the communication parameters, master and slave devices to be exactly the
same, including the baud rate, data bits and parity.
5. If the write function, check whether there is written, if there is written, but shows the
communication timeout, that failed to return, please check the wiring and grounding.
6. Check the slave device manual to see if the address and range of this parameter are
the same as those set on the controller.
7. If the above spread is correct, it is recommended to use parallel mode, using the
serial debugging software to monitor, if the PC can receive packets, please return to
the wiring check and communication settings parameters.
2. Check whether the result of the previous communication, if yes, check the timeout
setting.
3. Monitor and analyze the message through the serial port debugging software.
5. If you receive the signal is normal, but the controller still states the error. Check for
interference, or check if the impedances do not match.
1. Check whether the machine leakage, and to ensure reliable machine grounded.
1. Check the timeout, may be set too short. Recommended set to 50-100ms.
3. 37
3. Check if the wire is disturbed and if the wire is twisted.
I always receive from the station to send more than 0x83 function code message.
2. Check if the function code or format sent by the controller does not match with the
slave.
3. Check the controller read and write position is correct.
Reference
新代Modbus應用入門
https://confluence.SYNTECclub.com.tw/pages/releaseview.action?pageId=19794314
https://confluence.SYNTECclub.com.tw/pages/releaseview.action?pageId=151860251
38