Modbus itself is a specification for information exchange. Modbus RTU is a way to implement Modbus via serial ports, so all information is transmitted through serial ports. The Modbus protocol belongs to the C/S architecture. Modbus Rtu Slave is a server used to store all industrial equipment data to be read.
Application Scenarios
Overall Architecture
Modbus Tcp is a way to implement Modbus via serial ports. The Modbus Rtu Master can send read or write commands to the Rtu Slave. After receiving the command, the Slave will reply with confirmation information. The entire Modbus communication is based on the round-trip message exchange.
The following table outlines each product component
Product Component | Description |
---|---|
modbusslave_0.0.5_amd64.deb | Modbus rtu slave RTE component |
modbusslave.library | Library file used by the host computer program |
Installation Requirements
Sinsegye's factory-produced iComputer;
The iComputer can access the Internet;
Familiarity with basic Linux operation commands;
Installation Process
Install Modbus Tcp Slave RTE Component on iComputer
Upload the deb package to the /home/sinsegye directory of the iComputer's Linux environment
After the upload is complete, execute the command on the iComputer to install (refer to the screenshot below; if the module file name changes, modify the file name in the command line accordingly)
cd $HOME
sudo dpkg -i modbusslave_0.0.5_amd64.deb
sudo nano /usr/local/etc/SinsegyeRTE/SinsegyeRTE.cfg
ComponentManager]
Component.0=retainDeamon
Component.1=CmpCanBusUtils
Component.2=CmpSinsegyeLibs
Component.3=SinsegyeCmp
Component.4=modbusslave
sudo systemctl restart sinsegyerte.service
Install Library on Metafacture
Open Metafacture, click "Tools" -- "Library Storage"
Click "Install" -- select the modbus slave library file, click "Open"
In the project, click "Library Manager" -- "Add Library" -- select the modbus library and click "OK"
Update Installation
Upgrade Modbus Tcp Slave RTE Component on iComputer
Upload the deb package to the /home/sinsegye directory of the iComputer's Linux environment
After the upload is complete, execute the command on the iComputer to install (refer to the screenshot below; if the module file name changes, modify the file name in the command line accordingly)
cd $HOME
sudo dpkg -i modbusslave_0.0.5_amd64.deb
sudo systemctl restart sinsegyerte.service
Upgrade Library on Metafacture
Open Metafacture, click "Tools" -- "Library Storage"
Click "Install" -- select the modbus slave library file to be upgraded, click "Open"
In the project, click "Library Manager" -- "Add Library" -- select the modbus library and click "OK"
Uninstallation Process
Uninstall Modbus Tcp Slave RTE Component on iComputer
sudo dpkg -r modbusslave
sudo nano /usr/local/etc/SinsegyeRTE/SinsegyeRTE.cfg
sudo systemctl restart sinsegyerte.service
Uninstall Modbus Tcp Slave Library on MetaFacture
On the MetaFacture interface, click "Tools" -- "Library Storage"
In the dialog box, select the installed modbus slave library and click "Uninstall"
Quick Start
Software and Hardware Configuration in This Example
Hardware:
SX5100 iComputer MetaOS V24.08.15_SX5
Win10 PC
Software:
MetaFacture V1.0.6.3
Modbus Poll master tool
Experimental Requirements and Principles in This Example
Experimental Principle
A third-party Modbus Rtu master sends requests to the Metafacture Modbus Rtu slave via a serial port connection, which mainly includes: function code, address and quantity of target registers, and data for write operations. After receiving the request, the slave first checks the validity of the data, then executes the requested operation and responds to the master's request.
The host computer and the iComputer are connected via Ethernet.
On the host computer, Metafacture downloads the project to the iComputer. The project will include the configurations in the experimental operation steps below.
The iComputer is connected to the third-party Modbus Rtu master via a serial port.
Experimental Operation Steps in This Example
The experimental steps for creating a Modbus tcp slave project are as follows:
PROGRAM rtu_slave
VAR
FB_Modbus_Com_Slave_0 : ModbusSlave.FB_Modbus_Com_Slave;
bxEnable : BOOL:=TRUE;
pbyCoilA : ARRAY [0..2048] OF BOOL;
pbyDiscreteInputA : ARRAY [0..2048] OF BOOL;
pbyInputRegisterA : ARRAY [0..2048] OF WORD;
pbyHoldingRegisterA : ARRAY [0..2048] OF word;
bBusy : BOOL;
bActive : BOOL;
bError : BOOL;
eError : BOOL;
ulRecvCounter : UDINT;
ulSendCounter : UDINT;
END_VAR
FB_Modbus_Com_Slave_0(
bEnable :=bxEnable ,
uiSlaveId :=1 ,
comPort :=ModbusSlave.COM_PORT.ttys6 , //SX5 ttys6、 SX58 ttyS0、SX2 ttyS0;
baudrate :=ModbusSlave.SERIAL_BAUDRATE.baudrate_115200 ,
byteSize :=ModbusSlave.SERIAL_DATABIT.databit_8 ,
parity :=ModbusSlave.SERIAL_PARITY.parity_no , //The master should also be set to this
stopBits :=ModbusSlave.SERIAL_STOPBIT.stopbit_1 ,
udiTimeOut :=10000 ,
psMbTest := ,
pbyCoil :=ADR(pbyCoilA),
pbyDiscreteInput :=ADR(pbyDiscreteInputA),
pbyInputRegister :=ADR(pbyInputRegisterA),
pbyHoldingRegister :=ADR(pbyHoldingRegisterA),
udiRwBitSize :=SIZEOF(pbyCoilA),
udiInBitSize :=SIZEOF(pbyDiscreteInputA),
udiInWordSize :=SIZEOF(pbyInputRegisterA),
udiRwWordSize :=SIZEOF(pbyInputRegisterA),
bBusy=> ,
bActive=> ,
bConnect=> ,
bError=> ,
eError=> ,
ulRecvCounter=> ,
ulSendCounter=> );
Input Parameters
Parameter Name | Parameter Type | Description |
---|---|---|
bEnable | BOOL | Start modbus rtu slave |
uSlaveId | UINT | Slave ID information |
comPort | COM_PORT | Serial port number, e.g., COM_PORT.ttys6 |
comPortStr | STRING | The comPort parameter only supports up to /ttys8; if encountering serial port devices larger than 8 or other serial port devices, please use the comPortStr variable, e.g., comPortStr := '/dev/ttys9; |
baudrate | SERIAL_ | Baudrate setting, with two configurations: baudrate_9600, baudrate_115200 |
byteSize | SERIAL_DATABIT | Serial port transmission data bits, configurable with five configurations: databit_4, databit_5, databit_6, databit_7, databit_8 |
parity | SERIAL_PARITY | Serial port communication parity mode, with three types: parity_no, parity_odd, parity_even |
stopBits | SERIAL_STOPBIT | Serial port communication stop bits, with three types: stopbit_1, stopbit_1_5, stopbit_5 |
udiTimeOut | UDINT | Timeout time |
psMbTest | INT | Default 0, data for Modbus test, no configuration needed by default |
pbyCoil | POINTER TO BYTE | Slave coil, readable and writable |
pbyDiscreteInput | POINTER TO BYTE | Slave discrete input, read-only |
pbyInputRegister | POINTER TO BYTE | Slave holding register, writable and readable |
pbyHoldingRegister | POINTER TO BYTE | Slave input register, read-only |
udiRwBitSize | UDINT | The maximum number of bits that can be read and written, used for coils |
udiInBitSize | UDINT | The maximum number of bits that can be read, used for discrete inputs |
udiInWordSize | UDINT | The maximum number of words that can be read, used for input registers |
udiRwWordSize | UDINT | The maximum number of words that can be read and written, used for holding registers |
Output Parameters
Parameter Name | Parameter Type | Description |
---|---|---|
bBusy | BOOL | Set to True when the function block is activated, and remains until an acknowledgment signal is received |
bActive | BOOL | Modbus slave activation flag |
bConnect | BOOL | Modbus connection success flag |
bError | BOOL | Error flag. True indicates an error, False indicates no error |
eError | BOOL | Error feedback ID |
uIRecvCounter | ULINT | Data receive counter |
uISendCounter | ULINT | Data send counter |