Node-red-contrib-modbus - Errors when polling numerically high registers

Implementing Node Red on Raspberry Pi 4 Model B, 2GB RAM, using latest, generic Raspberry Pi OS. Nothing special.
RPi connected via ethernet to air-gapped network with ~15 total IP devices. Using Modbus TCP/IP

I am integrating to a device with several registers in the 4x,xxx category.
The registers start at 40,001 and continue to 40,052 for the first chunk. It picks up again at 40,100 to 40,150. It then jumps to 42,050 and ends at 42,100

When polling the first chunk (40,001 to 40,052), everything works perfectly.
When polling anything beyond that, it gives an error along the lines of "expected 7, got 6"
I've tried tinkering with many settings and no luck.

I have already integrated the 'server' devices into an automation system, all registers working properly. The RPi is for purposes of creating a dashboard and is experiencing these issues.

Have you tried a different Modbus master software like QModMaster to see if you get any errors ?

Did a quick test with a Modbus simulator ( pyModSlave ) and the Modbus-Read node works ok for me with those high register values

Error: Data length error, expected 7 got 6

I have not tried any other software. I'm not familiar with QModMaster, although I may try it.
I am using this RPi to create a simple dashboard for values polled over Modbus.

Through lots of tinkering, I discovered the solution.
For the specific register(s) I was trying to poll, they are 32-bit registers, split into 2 16-bits, with upper register first (sequentially lower) and lower register second.
For example, upper register: 42097; lower register 42098.
For this specific data, the upper register would always be irrelevant (always 0), so I discarded it.
Not sure if it is for the specific device I'm dealing with, but it only worked when I started at the upper register address with # of registers polled of 2.
So I get an array of [0, xxxx].

Previously I was inputting 2098 for starting address, with 1 addresses polled. <- ERROR
Now I have to do 2097 starting, 2 addresses polled.

1 Like

Im glad you found the solution to the problem :+1:
now that you mention it i read a couple of times on the forum that some devices start their register numbering with an offset of 1 (example)

does that mean you need to make corrections to all reads you were making ?
even the lower number register ones ? For example 40,001 you should have actually started reading from 0 ?

Ah I spoke too soon.
I had gone into the Modbus-serial module folder and modified the index.js file to comment out the error checks. When I got it working, I thought I figured out the issue, so I went back and put everything the way it was. Then the issue returned.
I checked each individually and this is the one causing problems. If I comment it out, it works fine.
Starting at line 382, index.js in modbus-serial folder.

if (!transaction.lengthUnknown && data.length !== transaction.nextLength) {
        error = "Data length error, expected " +
            transaction.nextLength + " got " + data.length;
        next(new Error(error));
        return;

Yes, the device I'm connecting with starts its registers (At least the 40,000's) at 40,001. So it's 1-start, not 0-start.

Further question, now that I'm in the heat of implementing this Raspberry Pi solution, what do you think the best method would be?

Polling modbus devices, incorporated in a Building Automation System, to show certain values on a large TV/display. Using RPi with Node-Red to poll devices and dashboard module to display.

There are 8 sets of RPi's & TVs in total. Originally, the plan was for each TV to display a different collection of data. Now, it is for all 8 TVs to be identical.
Before, each RPi would poll 2-3 of 8 of the modbus devices, now all 8 RPI's will poll all 8 devices.
I will extend the poll interval to hopefully avoid any potential issues or backoffs, but I was thinking if there might be a better way to do this?
Maybe have one master device, polling for the modbus values, then propagate the date to the other 7 RPIs via HTTP or MQTT?
I'm obviously ignorant here, but looking for input.

Hi .. are those 8 TVs going to be in the same building ?
if yes then you may not even need another 7 RPis .. just the one being modbus master with Node-red and Dashboard and the TVs can be smart TVs on the same network with their Browsers open pointing to that single Pi's Dashboard.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.