Reading MODBUS holding register

Topics about the Software of Revolution Pi
Post Reply
saardrimer
Posts: 18
Joined: 15 Jun 2021, 14:16

Reading MODBUS holding register

Post by saardrimer »

I have a Connect+ and I'd like to use it as a MODBUS TCP master to read a holding register from a MODBUS device. The holding register is, in this case, 40097. The MODBUS device is connected to my network and from a PC on this network I can read the register -- using a Python script -- and it always has a non-zero value.

I've followed the video and text to set this up:
https://revolution.kunbus.com/tutorials ... r-tutorial
https://youtu.be/VgMXEVCZDIc

In piCtory I've created a virtual device and in the extended data I have:

Code: Select all

1, 1, READ_HOLDING_REGISTERS, 40097, 1, 1000, Input_Word_1
(I've saved and clicked on 'Reset Driver'.)

When I run

Code: Select all

piTest -r Input_Word_1
I get

Code: Select all

2 Byte-Value of Input_Word_1: 0 dez (=0000 hex)
no matter what I try. In fact, even if I remove the Ethernet cable from the MODBUS device, I get the same result, which is odd; also the same if I try any other 'Name', like 'Input_Word_4'. Is this expected behaviour?

I've tried many different things but the result is always the same. I suspect that it's something trivial and I hope someone can point me to the problem so that I could proceed.

(Running latest Buster for RevPi ,and if it matters at all, connected to the network with a WiFi dongle.)

Thanks,
Saar.
User avatar
nicolaiB
KUNBUS
Posts: 1020
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Reading MODBUS holding register

Post by nicolaiB »

Hi Saar,

can you please share the log file of the modbus master?

Code: Select all

sudo journalctl -u pimodbus-master.service

What do the Status registers report?

Code: Select all

piTest -r Modbus_Action_Status_1
piTest -r Modbus_Master_Status

BR Nicolai
saardrimer
Posts: 18
Joined: 15 Jun 2021, 14:16

Re: Reading MODBUS holding register

Post by saardrimer »

Hello Nicolai

Many thanks for suggesting that I look into the log files and those registers. That gave me new ways to debug what I'm experiencing.

Code: Select all

sudo journalctl -u pimodbus-master.service

The log file indeed gave an error for reading the holding registers that I specified (40096/7 and others). This was a good clue.

Code: Select all

piTest -r Modbus_Action_Status_1

gave an error code '2' , which here

https://revolution.kunbus.com/tutorials ... rect=en_US

told me that the I have an 'ILLEGAL DATA ADDRESS'. Another clue.

There were two things that 'threw me off' trying to debug this:

[1] When I run a Python script on the RevPi (and on a PC on the network) that uses pymodbus

Code: Select all

from pymodbus.client.sync import ModbusTcpClient as ModbusClient

and that reads this range of addresses, it works just fine and I get non-zero values on some registers. I had assumed that it would be possible to read the same registers with the piCtory/piTest setup.

[2] When disconnecting the Ethernet cable from the MODBUS peripheral the data shown by piTest continues to be displayed as if nothing had happened.

As to point [1]:
I would still expect that reading holding registers in that range would work. I'm using the TRi nano-10 for testing

https://triplc.com/nano10.htm

and it is certainly possible that I misunderstood something.

As to point [2]:
I think that this might be a usability/functional issue that needs to be addressed. If there's no reading -- as shown in the pimodbus-master.service log -- then there should be no reading displayed while running piTest. I would think that an error should be returned, not the previously seen value.

As for now, I'm able to read and write registers in the 1-1000 range (problem [2] is still there even when things do work) which lets me cautiously proceed with my development. However, it would be good to know more about what can be done about both points above.

Thanks again,
Saar.
MedB
Posts: 4
Joined: 18 Feb 2025, 13:20

Re: Reading MODBUS holding register

Post by MedB »

Hi everyone,

I am experiencing similar problems that I still can't resolve.
I have a Janitza 509Pro setup as a Modbus Master (Gateway) and other Janitza 96RM chained to it each with its unique slave ID.
I can read out the registers using QmodMaster fine and the values seems to be correct but when I try to do this in pictory, I get nothing and/or errors.
I am using the virtual Modbus TCP master.
In the logs I see that " piModbusMaster[2648]: Modbus connection established to ip=137.183.199.73 port=502".

When I use SlaveID 5 for example to read out the frequency, I get no errors in the system log but also no values (I get 0000h which is not what I saw in QmodMaster).

When I use the ID of the Gateway 250, I get errors :

Code: Select all

10:26 AM
Set Modbus slave address for next command failed: Invalid argument
piModbusMaster
10:26 AM
Modbus TCP action IP: 137.183.199.73, Port: 502 function: 0x03, address: 8 failed -1/112345682
piModbusMaster
10:26 AM
Set Modbus slave address for next command failed: Invalid argument
piModbusMaster
10:26 AM
Modbus TCP action IP: 137.183.199.73, Port: 502 function: 0x03, address: 8 failed -1/112345682
and today I got an error that I couldn't resolve even with rebooting the system:

Code: Select all

Failed to start pimodbus-master.service - Revolution Pi Modbus master.
the error was resolved by deleting the pictory configuration and redoing it.

PS: I always deactivate QmodMaster before resetting the driver and testing the values using piTest -r.

Any assistance on how to debug this is much appreciated.
Post Reply