Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behaviour when reading starting at odd and even addresses #496

Open
stefangeorgescu970 opened this issue Mar 15, 2023 · 1 comment

Comments

@stefangeorgescu970
Copy link

G'day!

I am experiencing, as the title suggests, some weird behaviour when accessing registers from a PLC. As a disclaimer, there might be something extremely easy that I am missing, having close to no experience with this protocol.

The code I am using is the following

// create an empty modbus client
const ModbusRTU = require("modbus-serial");
const client = new ModbusRTU();

// open connection to a tcp line
client.connectTCP("localhost", { port: 20001 });
client.setID(1);

// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function () {
    client.readHoldingRegisters(0, 10, function (err, data) {
        console.log(data.data);
    });
}, 1000);

When reading registers from address 0, the data received is the following:

[ 0, 0, 0, 0, 0, 0, 0, 16968, 0, 16968 ]

However, when reading from address 1, as opposed to the expected result (seeing the non zero values move to the left one place), we receive:

[ 0, 0, 0, 0, 16968, 0, 16968, 0, 0, 0 ]

When reading from address 2, the addressing is correct relative to reading from address 0:

[ 0, 0, 0, 0, 0, 16968, 0, 16968, 0, 0 ]

Reading from address 3 is correct relative to reading from address 1:

[ 0, 0, 16968, 0, 16968, 0, 0, 0, 0, 0 ]

This behaviour continues as we move forward through the addresses. I am using package version 8.0.9

Having searched through the issues I could not find anything, so my assumption is I am doing something wrong. Is it something completely wrong that I am doing? Could it be something related to the modbus server I am reading from?

@stefangeorgescu970
Copy link
Author

Something that perhaps is worth mentioning about the code snippet setup. I use localhost since I have a TCP tunnel from my machine to the remote PLC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant