Modbus itself is a specification for information exchange, and Modbus Rtu is a way to implement Modbus via serial ports. Therefore, all information is transmitted through serial ports; the Modbus protocol belongs to the C/S architecture, and the Modbus Rtu Master can read and write the addresses of Rtu Slaves to realize data interaction.
Application Scenarios
Overall Architecture
Note: All Sinsegye software packages used in this manual can be obtained from the sub-pages of the official website. The version provided on the official website may be higher than the version mentioned in this manual. In general, this will not affect your execution of corresponding operations according to the examples in this manual.
Product Component | Description |
---|---|
simodbusmaster_1.0.9_amd64.deb | Modbus Rtu Master RTE component |
SF4100_ModbusMaster_1.0.0.2.library | Modbus Rtu Master Metafacture library file |
Installation Requirements
Installation Process
Installing Modbus Rtu Master RTE Component on iComputer
Installing the Library in Metafacture
Open Metafacture, click "Tools" -- "Library Storage".
Click "Install" -- select the Modbus master library file, click "Open".
Update Installation
Upgrading Modbus Rtu Master RTE Component on iComputer
Upgrading the Library in Metafacture
Open Metafacture, click "Tools" -- "Library Storage".
Click "Install" -- select the new Modbus master library file, click "Open".
Uninstallation Process
Uninstalling Modbus Rtu Master RTE Component on iComputer
Uninstalling Modbus Rtu Master Library on MetaFacture Side
On the MetaFacture interface, click "Tools" -- "Library Storage".
In the dialog box, select the installed Modbus master library and click "Uninstall".
Software and Hardware Configuration in This Example
Hardware:
Software:
Experimental Requirements and Principles in This Example
Experimental Principle
Experimental Operation Steps in This Example
Steps for Master Initialization of Serial Port Experiment
Steps for Reading Multiple Coils Experiment
Steps for Reading Discrete Inputs Experiment
Steps for Reading Holding Registers Experiment
Steps for Reading Input Registers Experiment
Steps for Writing Multiple Coils Experiment
Steps for Writing Multiple Holding Registers Experiment
Steps for Writing Single Coil Experiment
Steps for Writing Single Holding Register Experiment
The configuration of the slave COM port and serial port baud rate in Modbus Slave is subject to the actual situation:
Coil configuration: 21 bits
Discrete input configuration: 10 bits
Holding register configuration: 21 bits
Input register configuration: 10 bits
Introduction to Function Block FB_MBRtuSerialPortInit
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
PortName | STRING | Serial port number |
BaudRate | UINT | Baud rate setting; commonly used baud rates such as 9600, 38400, and 115200 are supported |
DataBits | UINT | Data bits |
StopBits | UINT | Stop bits |
Parity | STRING | Parity bit |
Execute | BOOL | Trigger execution |
Timeout | TIME | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuReadCoils
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
Quantity | UINT | Number of coils to read |
MBAddr | WORD | Starting position of the coils to read |
cbLength | UINT | Size of bytes to store the read data |
pMemoryAddr | POINTER TO BYTE | Storage address of the data to be read |
Execute | BOOL | Trigger the read action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuReadInputRegs
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
Quantity | UINT | Number of input registers to read; up to 125 at a time |
MBAddr | UINT | Starting position of the input registers to read |
cbLength | UINT | Size of bytes to store the read data |
pMemoryAddr | POINTER TO BYTE | Storage address of the data to be read |
Execute | BOOL | Trigger the read action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuReadInputs
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
Quantity | UINT | Number of discrete inputs to read |
MBAddr | UINT | Starting position of the discrete inputs to read |
cbLength | UINT | Size of bytes to store the read data |
pMemoryAddr | POINTER TO BYTE | Storage address of the data to be read |
Execute | BOOL | Trigger the read action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuReadRegs
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
Quantity | UINT | Number of holding registers to read; up to 125 at a time |
MBAddr | UINT | Starting position of the holding registers to read |
cbLength | UINT | Size of bytes to store the read data |
pMemoryAddr | POINTER TO BYTE | Storage address of the data to be read |
Execute | BOOL | Trigger the read action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuWriteCoils
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
Quantity | WORD | Number of coils to write |
MBAddr | WORD | Starting position of the coils to write |
cbLength | UINT | Size of bytes to store the written data |
pMemoryAddr | POINTER TO BYTE | Address of the data to be written |
Execute | BOOL | Trigger the write action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuWriteRegs
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
Quantity | UINT | Number of holding registers to write |
MBAddr | UINT | Starting position of the holding registers to write |
pMemoryAddr | POINTER TO WORD | Address of the data to be written |
Execute | BOOL | Trigger the write action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuWriteSingleCoil
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
MBAddr | WORD | Position of the coil to write |
Value | BOOL | Value of the coil to write |
Execute | BOOL | Trigger the write action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Introduction to Function Block FB_MBRtuWriteSingleReg
Parameter Introduction
Parameter Name | Parameter Type | Description |
---|---|---|
UnitID | UINT | ID of the slave |
MBAddr | WORD | Position of the holding register to write |
Value | WORD | Value of the holding register to write |
Execute | BOOL | Trigger the write action |
tTimeout | Time | Timeout |
Parameter Name | Parameter Type | Description |
---|---|---|
BUSY | BOOL | Set when the function block is active until confirmation is received |
Error | BOOL | Set to true if an error occurs during command transmission until the bBusy output is reset |
ErrorId | UINT | Provides the error number when the bError output is set |
Use simulation software to configure 32 RTU slaves (each with a different slave ID), refer to the following:
Configure the master project to connect to 32 slaves for read and write operations, and test that reading and writing work normally.