Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
471 stars 175 forks source link

ReadHoldingRegisters offset #42

Closed lfernando-silva closed 8 years ago

lfernando-silva commented 8 years ago

Well, here I am again, thanks for your atention.

So, I need to read from de 40001 to 40344 holding register, and I have understood that , to do this, I need to call readHoldingRegisters three times.

But the interval doesn't make sense for me. After some time testing the reads, I could read it make the follow call:

//after client configurations
client.on('connect', function () {

var reads = [
        client.readHoldingRegisters(0, 127), //40001 to 40127
        client.readHoldingRegisters(127, 255), //40128 to 40254
        client.readHoldingRegisters(254, 346) //40255 to 40344
    ];

Promise
        .all(reads)
        .then(function (data) {
            console.log(data);
        }).error(function (err) {
            console.log(err);
        }).finally(function () {
            client.close();
        });
});

I tried to use Simply Modbus TCP Client 7.1.2 to simulate the calls, but it doesn't work well, so I don't know if it's a modbus protocol problem, just a bug in the module or just I didn't understand the protocol... what can it be?

lfernando-silva commented 8 years ago

My mistake again. The second param is, actually, the bytes quantity and not the last modbus adress in the offset.

So the right read is something like

    var reads = [
        client.readHoldingRegisters(0, 127), //40001 to 40127
        client.readHoldingRegisters(127, 127), //40128 to 40254
        client.readHoldingRegisters(254, 89) //40255 to 40344
    ];

sorry about this, again!