Modbus TCP Communication
Mech-MSR can communicate with external devices using the Modbus TCP protocol. Before you read the following content, make sure that the communication configuration has been completed in Mech-MSR.
About Modbus TCP
Mech-MSR can communicate with a PLC by using the Modbus TCP protocol. Under this communication mode, Mech-MSR acts as the server (slave) and the PLC acts as the client (master). All requests are initiated by the PLC and responded by Mech-MSR.
After the Modbus TCP communication is enabled in Mech-MSR, the software will begin listening for one or more Modbus clients on port 502 (the default listening port).
Communication Workflow
The workflow of Modbus TCP communication is shown in the figure below.
| You can check the table in Input and Output Signals to learn the meaning of each signal. |
Input and Output Signals
|
Mech-MSR supports the following standard Modbus function codes for accessing holding registers.
|
|
Holding register addresses are logical (or display) addresses, such as In actual Modbus TCP communication, the base address is 1, meaning that addresses start from |
| Input (from the PLC to Mech-MSR) | Output (from Mech-MSR to the PLC) | ||||||
|---|---|---|---|---|---|---|---|
Module |
Name |
Bytes occupied |
Holding register address (4x) |
Module |
Name |
Bytes occupied |
Holding register address (4x) |
Command enable |
1 byte |
40001 |
Heartbeat |
1 byte |
40065 |
||
Command trigger |
Trigger acknowledge |
||||||
Data read finished |
Data ready |
||||||
Reset |
Execution completed |
||||||
Reserved field |
Reserved field |
||||||
Reserved field |
Reserved field |
||||||
Reserved field |
Reserved field |
||||||
Reserved field |
Error |
||||||
Reserved field |
3 bytes |
First byte: 40001; last two bytes: 40002 |
Overall judge |
1 byte |
40065 |
||
Reserved field |
|||||||
Reserved field |
|||||||
Reserved field |
|||||||
Reserved field |
|||||||
Reserved field |
|||||||
Reserved field |
|||||||
Reserved field |
|||||||
Reserved field |
2 bytes |
40066 |
|||||
Command code |
2 bytes |
40003 |
Status code |
2 bytes |
40067 |
||
Command parameter 1 |
2 bytes |
40004 |
RESERVED |
Reserved field |
2 bytes |
40068 |
|
Command parameter 2 |
2 bytes |
40005 |
Judgment result of ID 1 Judgment result of ID 2 Judgment result of ID 3 ... |
8 bytes |
40069–40072 |
||
Command parameter 3 |
2 bytes |
40006 |
|||||
Command parameter 4 |
2 bytes |
40007 |
|||||
Command parameter 5 |
2 bytes |
40008 |
|||||
Command parameter 6 |
2 bytes |
40009 |
Measurement result of ID 1 Measurement result of ID 2 Measurement result of ID 3 ... |
256 bytes (4 bytes × 64) |
40073–40200 |
||
Command parameter 7 |
2 bytes |
40010 |
|||||
Command parameter 8 |
2 bytes |
40011 |
|||||
Command parameter 9 |
2 bytes |
40012 |
|||||
Command parameter 10 |
2 bytes |
40013 |
|||||
Variable 1 |
4 bytes |
40014–40015 |
|||||
Variable 2 |
4 bytes |
40016–40017 |
|||||
Variable 3 |
4 bytes |
40018–40019 |
|||||
Variable 4 |
4 bytes |
40020–40021 |
|||||
Variable 5 |
4 bytes |
40022–40023 |
|||||
Variable 6 |
4 bytes |
40024–40025 |
|||||
Variable 7 |
4 bytes |
40026–40027 |
|||||
Variable 8 |
4 bytes |
40028–40029 |
|||||
Variable 9 |
4 bytes |
40030–40031 |
|||||
Variable 10 |
4 bytes |
40032–40033 |
|||||
RESERVED |
Reserved field |
62 bytes |
40034–40064 |
||||
Input (from the PLC to Mech-MSR)
CONTROL_INPUT
| Address | Data | Description |
|---|---|---|
0.0 |
Command enable (Boolean) |
Only when the command enable signal is set to 1, other input signals take effect. |
0.1 |
Command trigger (Boolean) |
When the command trigger signal changes from 0 to 1 (a rising edge is detected), Mech-MSR reads command codes and command parameters. When Mech-MSR returns the trigger acknowledge signal, the command trigger signal can be set to 0. |
0.2 |
Data read finished (Boolean) |
When the PLC completes data reading, this signal can be set to 1. When the PLC is informed that the data ready signal changes to 0, this signal can be set to 0. |
0.3 |
Reset (Boolean) |
When this signal is set to 1, the PLC clears the received judgement result and measurement result. At this point, the PLC can send new commands and status code signals are reset. |
0.4 |
Reserved field (Boolean) |
A reserved field. |
0.5 |
Reserved field (Boolean) |
A reserved field. |
0.6 |
Reserved field (Boolean) |
A reserved field. |
0.7 |
Reserved field (Boolean) |
A reserved field. |
1.0–3.7 |
Reserved field (Byte) |
A reserved field. |
COMMAND & COMMAND_PARAM
The following table describes the commands supported by the Modbus TCP communication, the command codes (COMMAND), and the command parameters (COMMAND_PARAM).
| Command | COMMAND | COMMAND_PARAM | Description |
|---|---|---|---|
execute |
1 |
The project ID. Only one project ID can be set each time. |
Used to trigger the project and obtain project judgement result and measurement result. |
trigger |
2 |
Project ID. One to four project IDs can be set at a time. |
Used to trigger the project to run. |
return |
3 |
The project ID. Only one project ID can be set each time. |
Used to obtain the judgement result and the measurement result of the specified project. |
judge |
4 |
Used to obtain the overall quality judgment result of the specified project or the judgment results of individual measurement items. |
|
value |
5 |
Used to obtain the measured values of a specified project. |
|
recipe |
6 |
Project ID, parameter recipe ID |
Used to switch the parameter recipe used by the project. |
solution |
7 |
Solution ID. |
Used to switch the solution. |
SetNumVar |
8 |
ID of a global variable. Only one ID can be set at a time. |
Used to set values for global variables of numeric type. The value of the variable is passed through VAR_INPUT. |
GetNumVar |
9 |
ID of a global variable. Only one ID can be set at a time. |
Used to read the value of a global variable of numeric type. The result is returned by VALUE. |
|
VAR_INPUT
When SetNumVar is executed, the set value is set to VAR_INPUT.
| Holding register address (4x) | Data | Description |
|---|---|---|
40014–40015 |
Variable 1 (Float) |
The numeric input parameter is 1. |
40016–40017 |
Variable 2 (Float) |
The numeric input parameter is 2. |
40018–40019 |
Variable 3 (Float) |
The numeric input parameter is 3. |
40020–40021 |
Variable 4 (Float) |
The numeric input parameter is 4. |
40022–40023 |
Variable 5 (Float) |
The numeric input parameter is 5. |
40024–40025 |
Variable 6 (Float) |
The numeric input parameter is 6. |
40026–40027 |
Variable 7 (Float) |
The numeric input parameter is 7. |
40028–40029 |
Variable 8 (Float) |
The numeric input parameter is 8. |
40030–40031 |
Variable 9 (Float) |
The numeric input parameter is 9. |
40032–40033 |
Variable 10 (Float) |
The numeric input parameter is 10. |
Output (from Mech-MSR to the PLC)
CONTROL_OUTPUT
| Address | Data | Description |
|---|---|---|
0.0 |
Heartbeat (Boolean) |
System heartbeat. It toggles every second. Used to determine whether the PLC and Mech-MSR are connected or disconnected. |
0.1 |
Trigger acknowledge (Boolean) |
When Mech-MSR receives the rising edge for the command trigger signal, this signal is set to 1. When a falling edge is detected for the command trigger signal, this signal is set to 0. |
0.2 |
Data ready (Boolean) |
Mech-MSR writes data to output ports and waits for the PLC to read the output data. When the data read signal is set to 1, this signal is set to 0. |
0.3 |
Execution completed (Boolean) |
When the command execution completes, this signal is set to 1, which indicates that the command execution is completed. |
0.4 |
Reserved field (Boolean) |
A reserved field. |
0.5 |
Reserved field (Boolean) |
A reserved field. |
0.6 |
Reserved field (Boolean) |
A reserved field. |
0.7 |
Error (Boolean) |
If the status code returned by Mech-MSR is not 1, an error occurred and this signal is set to 1. |
1.0 |
Overall judge (Boolean) |
The overall judgement of the project. 1 indicates OK, and 0 indicates NG. |
1.1–1.7 |
Reserved field (Boolean) |
A reserved field. |
2.0–3.7 |
Reserved field (Byte) |
A reserved field. |
STATUS_CODE
The possible returned status codes for Mech-MSR are as follows:
-
Normal status code: 1, indicating that the command was executed successfully.
-
Error codes: -1, -2, -3, -4, -5. For more information, see Error Codes.
JUDGE
Judgement results were added for measurement items on the Communication output tab in the Output Management window. 1 indicates OK, and 0 indicates NG.
| At most 64 judgement results can be output for a single project at a time. |
VALUE
The VALUE module returns the following data:
-
Measurement results are added for measurement items on the Communication output tab in the Output Management window.
-
The values of numeric global variables are read when the
GetNumVarcommand is executed.
| At most 64 measurement results can be output for a single project at a time. |