■Explanation
This is a sample program of Modbus/RTU master.
Modbus/RTU communication can be executed by specifying the COM port, setting the baudrate and parity etc.
■Execution example
For python
python3.10 rtumaster.py
For gcc
./rtumaster
■Screen Image
■Step to Use
1. Enter "0" and press the enter key.
2. In Init, enter the COM port to be used, baudrate, parity bit, data bit, stop bit, and slave ID to connect with the device.
3. To input or output via Modbus communication,
please click the button after setting the parameters of each function code.
* Please refer to the following for the function code corresponding to each button.
Function Code |
Function Name |
---|---|
ReadCoils (FC 1) |
modbus_read_bits |
ReadDiscreteInputs (FC 2) |
modbus_read_input_bits |
ReadHoldingRegisters (FC 3) |
modbus_read_registers |
ReadInputRegisters (FC 4) |
modbus_read_input_registers |
WriteCoil (FC 5) |
modbus_write_bit |
WriteRegister (FC6) |
modbus_write_register |
WriteMultipleCoils (FC15) |
modbus_write_bits |
WriteMultipleRegisters (FC16) |
modbus_write_regsiters |
Data format for sending and receiving is as follows.
- Send Data (Hex)
Example) 01 0D AD
- Receive Data (Hex)
Example) 01 0D AD
- Send Data (Bin)
Example) 0 1 1
- Receive Data (Bin)
Example) 0 1 1
In this sample, the maximum number of reading is 2000 bits / 125 words,and the maximum number of writing is 1968 bits / 123 words.
* This is the maximum value of the Modbus specifications.
4. To exit, enter "9" and press the Enter key.