Tutorial Modbus RTU Master (Jessie)

You can use your RevPi Core 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 Core.

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.

PLEASE NOTE

If you are using several slaves, you have to make sure that each slave has its own address. If 2 or more slaves have the same address, communication errors occur

Open your web browser.

Enter the IP address of your RevPi Core in the address bar of your web browser.

The login window appears.

Log in with the username „admin“.

Enter the password. You can find it on the sticker on the side of your RevPi Core.

Click „Login“

You can now see the current device status of your RevPi Core.

Click “Services” tab.

Click “Enabled” in the Enable/Disable Modbus Master line.

Click the “Save All” button.

Note!: You can also activate the Master function on the command line. Enter the following command: “sudo revpi-config enable pimodbus-master”.

Click the „Apps“ tab.

Click the start button behind the entry “PiCtory”.

PiCtory starts.

Open the folder “Virtual Devices”in the device catalog.

Select Modbus-RTU Master.

Hold down the left mouse button and drag the Modbus RTU Master to your RevPi Core.

Your Modbus-RTU Master will now appear on the far right of the Configuration Board.

PLEASE NOTE

Your Modbus RTU Master is always arranged on the far right. If you use a RevPi Gate, which you are only allowed to arrange on the far right/left outside, it will still work as before. The RevPi Gate is a device that is physically present and can only be mounted on the outside of the DIN rail. However, virtual devices such as the Modbus RTU Master are not physically present. Therefore, you don’t have to create a separate slot for these devices and PiCtory automatically arranges them outside of the devices that physically exist.

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/ttyUSB0

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.

PLEASE NOTE

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_INPUT_REGISTERS

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.
Example: 4 bytes from “Output_1” also occupy “Output_2″,”Output_3” and “Output_4”. To avoid overlapping, in this example you have to set the next command to “Output_5”.

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.

Sign up to our newsletter and be among the first to hear about the latest development.

We use double opt-in for our newsletter subscription so we are 100% sure we aren't spamming anyone. Please pay attention to the confirmation email, you get after your signup. If you don`t confirm your email address, your newsletter subscription won`t be activated. If you don`t get any confirmation email, it may be in your Junk or Spam mailbox. If not, please email us at admin@kunbus.de to confirm your email subscription.