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

How to reading multiple register in single call #7

Open
vishalb747 opened this issue Nov 8, 2017 · 2 comments
Open

How to reading multiple register in single call #7

vishalb747 opened this issue Nov 8, 2017 · 2 comments

Comments

@vishalb747
Copy link

Hello Sir,

     I am trying to read multiple register in single call. For this I have done one change in modbus-rtu > master.js file.

Master.prototype.readHoldingRegisters = function(slave, start, length, dataType) {
var packet = this.createFixedPacket(slave, constants.FUNCTION_CODES.READ_HOLDING_REGISTERS, start, length);
return this.request(packet).then(function(buffer) {

    if (!buffer.error) {
        var buf = packetUtils.getDataBuffer(buffer);
        var arr = [];

        for (var i = 0; i < buf.length;) {
            arr.push({ '0': buf[i], '1': buf[i + 1], '2': buf[i + 2], '3': buf[i + 3] });
            i = i + 3;
            i++;
        }

        if (_.isFunction(dataType)) {
            return dataType(buf);
        }
        return arr;
    } else {
        return buffer;
    }
}, function(error) {

});

};

I want to read 8 registers at a time and the register series as below
2999,3001,3003,3005,3007 and each registers data type is float.

readHoldingRegisters(1, 2999, 8, null).then(function(response) {
console.log(response)
})

I have done register values conversion using nodejs buffer. I am not using any datatype in above function for conversion.

Is any other way to do multiple read in single call?

@timofei-iatsenko
Copy link
Owner

Hello, as far as I remember reading multiple registers support exists out of the box.

You don't need change anything in library files.

Actually I don't clearly understand what you want to do.

@vishalb747
Copy link
Author

vishalb747 commented Nov 12, 2017 via email

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

2 participants