Modbus RTU multiple registers access

Topics about the Software of Revolution Pi
Post Reply
Fabrizio
Posts: 16
Joined: 24 Jan 2024, 09:44

Modbus RTU multiple registers access

Post by Fabrizio »

Hello. I'm using a RevPi Flat S to communicate with 2 different modbus channels.
To optimize the polling sequence, I would like to use the "Read Multiple Holding Register" and "Write Multiple Holding Register" function codes (3 and 16 respectively).
I saw that it is possible to configure these commands with Pictory, but I didn't found the sintax for example to write multiple registers using the "piTest" utility.

I tried to configure an output variable on "Pictory" in this way:
Config_B.png
Could you please indicate the correct sintax to write more than one register at a time?

I saw that "piTest" has the option "piTest -w <o>,<l>,<v>". In this case which value for offeset <o> shall I use to write at slave address 112 and register 1?
Whit this command I can use l=1,2 or 4. If I use 4, I'll effectively write register 1 and 2?

Note that if I read or write one register at a time, all correctly works.

Thank you.
Fabrizio
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: Modbus RTU multiple registers access

Post by dirk »

Hello Fabrizio,okay, I'm not sure if I understood correctly. But just in case you want to write multiple registers via Modbus then you are in the right place. Just configure the actions and the action intervals. You are using two different Modbus connections then you have to configure each action on the "Extended Data" dialogue of the appropriate Modbus module in PiCtory.

The heart of the data is the process image that can be accessed i.e. via the "piTest" tool.

So if I did not understand correctly and you just want to write multiple bytes at once to the process image and are having problems doing it I have that idea: With "piTest -v <Variable>" I get the information about the location inside the process image:

Code: Select all

pi@RevPi123834:~$ piTest -v Input_1
variable name: Input_1
       offset: 102
       length: 16
          bit: 0
So as I know the values that are following are Input_2, Input_3 and so on... Thus I am writing the four 2-byte register values like so:

Code: Select all

pi@RevPi123834:~$ piTest -v Input_1
variable name: Input_1
       offset: 102
       length: 16
          bit: 0
pi@RevPi123834:~$ printf '\x01\x02\x03\x04\x05\x06\x07\x08' | dd of=/dev/piControl0 bs=1 seek=102 conv=notrunc
8+0 records in
8+0 records out
8 bytes copied, 0.000121535 s, 65.8 kB/s
pi@RevPi123834:~$ piTest -1 -r 102,8,h
01 02 03 04 05 06 07 08 
So one register in modbus is defined as a 2 byte variable so the 1 and 2 go together to Input_1, 2 and so on. For example the content of Input_1 is that:

Code: Select all

pi@RevPi123834:~$ piTest -1 -r Input_1
2 Byte-Value of Input_1: 513 dez (=0201 hex)
But you can of course use other tools like Python with RevPiModIO2 to do the job - I mean that you are not bound to use either "piTest" or that kind of example tools I used here to access your data in the process image. ;)
Nol
Posts: 1
Joined: 11 Nov 2024, 13:14

Re: Modbus RTU multiple registers access

Post by Nol »

Can anyone help me with a solution. I have been working on a revolution pi compact for a while now. Connecting the Revolution Pi Compact to Codesys works fine. I want to get the I/O mapping that I configured on pictory also on codesys, but that doesn't work.
I am using Linuxarm 4.13.0.0 (linuxarm SL)

I keep getting an old configuration with version 1.0 of pictory.

Can anyone help me solve this problem?
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: Modbus RTU multiple registers access

Post by dirk »

Hi Nol, take a look at the CODESYS Checklist. There is also a nice little video that shows the steps to commission CODESYS with a Revolution Pi Module.

I have moderated your post and forgot to mention that you need to check if you post a new topic or if it fits to a existing topic ... have this in mind for the future please :|
Fabrizio
Posts: 16
Joined: 24 Jan 2024, 09:44

Re: Modbus RTU multiple registers access

Post by Fabrizio »

Hello Dirk.
I'll try to give you more details about my necessity.

To optimize the communication, I would like to send commands to read/write multiple registers at one time on every single slave (my modbus has a lot of slaves).
This will be useful to reduce the polling interval of every connected sensor (send a single command instead of a command for every register of the devices).

At the moment I have a configuration done with Pictory of this type (example of one slave device):
Config_A.png
In this case I update the values of Output_Word_1...4 and I can see that RevPi writes them on the device by sending 4 different commands (one for every register).
This configuration correctly work.

But I would like to use the Modbus feature that allows the sending of all the 4 register inside only one command.
The correspondent configuration on Pictory I did is the following:
Config_B.png
and I expected that writing Output_Word_1 with the correct values, RevPi send a single Modbus command with all the 4 registers.
But it seems to be not the case.

So the question is: is it possible to do what I would like? If yes, how can I do it?

Obviously I have the same necessity for reading purposes (possibility to read multiple consecutive registers from a slave, with only one command).

In the previous request I talk about the use of "piTest". This tool is very useful for me to preliminary check the solution that I'll implement with a C application I wrote.
So consider that for the production application, I have to implement all in my app (C examples you provide are very useful for this).

Thank you in advance.
Fabrizio
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: Modbus RTU multiple registers access

Post by dirk »

Hello Fabrizio,
Your considerations and the function code are correct. From the register onwards, simply write four in total.
  • Can you create a sketch of the structure?
  • Can you visualize the RS485 communication with an oscilloscope?
Unfortunately, this is the only reference that provides information about what is really happening. What is in the corresponding modbus status registers?
  • Modbus_Master_Status
  • Modbus_Action_Status_[1 ... 32]
Fabrizio
Posts: 16
Joined: 24 Jan 2024, 09:44

Re: Modbus RTU multiple registers access

Post by Fabrizio »

Thank you Dirk.
As soon I will be able to perform more tests, I'll be back with the information you requested.
(now I have to manage a bigger problem related to the maximum number of actions that can be performed by RevPI - refer to my post on the other thread related to this)

Thank you,
Fabrizio
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: Modbus RTU multiple registers access

Post by dirk »

hello Fabrizio, thank you for your positive feedback - I'm looking forward to your next steps here and have replied to you in the other post.
Post Reply