You can use your RevPi base module as Modbus RTU Master. This way you could e. g. connect slaves such as temperature sensors, push-buttons, motion detectors via Modbus RTU and process the data of these slaves in your RevPi .
You need:
- RevPi base module
- Slave
- Matching cables with D-Sub 9 connectors
- Adapter (e.g. shop article 200018 or 200019)
- Internet connection
Requirements:
- A web browser, e.g. Google Chrome or Mozilla Firefox.
- RevPi base module is located in your network.
Let’s go!
- Connect a USB port of the RevPi base module to the adapter.
- Connect the adapter to the slave via the D-Sub 9 socket.
- Specify the address of the slaves and make a note of it. If necessary, you can find information on this in the manufacturer’s operating instructions.
- Start RevPi Status.
- Click tab SERVICES.
- Enable Modbus Master.
- Click button Save All.
You can also activate the Master function on the command line.
Enter the following command: sudo revpi-config enable pimodbus-master
.
- Start PiCtory.
- In the Device Catalog, open the folder Virtual Devices.
- Select Modbus-RTU Master.
- Hold down the left mouse button and drag the Modbus RTU Master to your RevPi.
Your Modbus-RTU Master will now appear on the far right of the Configuration Board.
- Select Modbus RTU Master.
- Set the basic settings for your adapters in the “Device Data” window. This entry is optional. If you use a lot of devices and want to process the data later in another program, this input can be very helpful.
- In the “Value Editor” we define the settings for the connection:
Parameter | Description |
Input | This is where you can configure your inputs. A total of 32 values can be used for each master. A value has a width of 16 bits |
Output | This is where you can configure your outputs. A total of 32 values can be used for each master. A value has a width of 16 bits |
device_path | The file path to the Linux device file, default: /dev/ttyRS485.
Important! If you are using multiple devices of the same type, the paths to the Linux device files may change when you reboot. This can be prevented by setting udev rules that have e. g. assignments of Linux device file paths to device serial numbers. |
baud rate | The baud rate determines the speed of the serial connection. default: 19200 |
parity | Configuration of the parity bit.
None: no parity bit Even: even parity (default) Odd: ungerade Parität |
data_bits | Number of data bits default:8 |
Stop_bits | Number of stop bits default:1 |
- Right-click on the Modbus RTU Master on the Configuration Board.
- A context menu opens.
- Select the entry “Extended Data”.
An input mask opens.
- This is where you can set the Modbus commands.
We use the first register address 1 for our products. Some manufacturers use 0 as the first register address for their products. Check how the addressing is specified at your slave. If the slave you want to use uses 0 as the first register address, you must add a 1 to the specified value during configuration.
Example: The documentation for your slave states a register address 30053. The addresses start at 0 according to the documentation. You use address 30054 for this register when configuring a Modbus command.
Parameter | Erklärung |
Slave Addr. | Slave address
This address is set directly at your slave. For information on how to do this, please refer to the manufacturer’s instruction manual. Important!If you are using more than one slave, make sure that each slave has its own address. If 2 or more slaves have the same address, communication errors occur. “0” must not be used as slave address. It is reserved for Modbus for broadcast. |
Function Code | Modbus has function codes that allow access to data in a certain way. We use the following function codes:
READ_COILS Read single bits
READ_DISCRETE_INPUTS Read single input bit
READ_HOLDING_REGISTERS Read whole 16-bit input/output register Read whole input register (16 bits)
WRITE_SINGLE_COIL Write single bit
WRITE_SINGLE_REGISTER Writing whole register
WRITE_MULTIPLE_COILS Write several consecutive bits
WRITE_MULTIPLE_REGISTERS Write several consecutive registers |
Register Address | The Modbus register address or bit address of the data you want to access. You will find information on how the registers of the slave are assigned in the operating instructions of the slave.
The register addresses are always valid in conjunction with the respective function code. This means, for example, that a read holding register no. 17 accesses a different value than a read input register no. 17. |
Quantity of Registers | Number of registers (or bits) that are read/written. |
Action Interval | The interval at which the command is sent (in milliseconds).
Note that very short intervals cannot be adhered to if the system load is too high. The commands are then sent as quickly as the circumstances allow. |
Device Value | The variable name in the RevPi process image in which the first word or bit of the Modbus command is read or written.
Make sure that the different commands do not overlap. |
Click on “Add Row” to add another command.
Tip: You can delete commands by setting the checkmark at the beginning of the command and clicking on “Remove Selected Rows”.
- Click on „File>Save“ to save the file.
- Click on “Tools>Reset Driver”. This activates the changes for the adapter.
Do you want to continue using the settings in logiCAD3 or C?
- Click on „File>Export“.
A window opens. You can specify the format of the file and the filename.
You can choose from 2 file formats:
Export 01 creates a file that is suitable for use in logiCAD3.
Export 02 creates an offset list which you can use as basic information for your own C-program
- Select a format you want to continue working with.
- Specify a file name.
- Click „Ok“.
Tip!: 32 values are not enough for your project? No problem, just take another master and access the same slave with it. Now you got 64 values.
Help! Error!
The Modbus master has predefined Modbus registers for status messages.
If a communication error occurs, the error code is written to the Modbus register “Modbus_Master_Status”.
The error remains in this register until the Modbus register “Master_Status_Reset” is manually written to the value “1”.
Error Code | Meaning |
0x10 | The configured device was not found.
Check if the wiring is correct. |
0x11 | The configured device does not respond or you use a register address not allowed at the slave (see note above!).
Check if the configuration is correct. |
The Modbus master can perform up to 32 tasks. For each task there is a register for status and status reset. If an error occurs in a task, the error code is written to the Modbus register “Modbus_Action_Status_[1… 32]”.
The error remains in this register until the Modbus register “Action_Status_Reset_[1… 32]” is manually written to the value “1”.
The error codes correspond to the Modbus exception codes as specified in the Modbus specification.
The following table shows the most important error messages.
Fehlercode | Name | Bedeutung |
1 | ILLEGAL FUNCTION | The used Function Code is not allowed. Check, if you are using the Right Function Code. |
2 | ILLEGAL DATA ADDRESS | The used Modbus Register Address is not valid. The Register is rather write-protected or invalid. Check the Register Address. |
3 | ILLEGAL DATA VALUE | At least one part of the data values is invalid. Perhaps you have specified too many registers. Check your values. |
11 | RESOURCE TEMPORARILY UNAVAILABLE | |
12 | INVALID CRC | A faulty packet was received from the slave. This can occur after the connection has been interrupted, for example. Check your wiring. |
13 | INVALID DATA | The slave has answered my incomplete packet. This can occur after the connection has been interrupted, for example. Check your wiring. |
104 | CONNECTION RESET BY PEER | |
110 | CONNECTION TIMED OUT | The slave didn’t respond fast enough or not at all. Check your configuration and wiring. |
Read more about this topic in the Modbus specification.