Page 1 of 1

Reading MODBUS holding register

Posted: 20 Jun 2021, 21:53
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.

Re: Reading MODBUS holding register

Posted: 25 Jun 2021, 13:32
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

Re: Reading MODBUS holding register

Posted: 26 Jun 2021, 13:58
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.