node-modbus-rtu icon indicating copy to clipboard operation
node-modbus-rtu copied to clipboard

How to reading multiple register in single call

Open vishalb747 opened this issue 8 years ago • 2 comments

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?

vishalb747 avatar Nov 08 '17 05:11 vishalb747

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.

timofei-iatsenko avatar Nov 12 '17 10:11 timofei-iatsenko

Hello sir, I want to read multiple registers data at a time from energy meter using modbus rtu protocol. I have tried to get multiple registers data from modbus rtu protocol by doing some changes in library and it works same as Modbus-tcp protocal. I want to know if any other way is there for reading multiple registers data.

On 12-Nov-2017 4:04 pm, "Timofey Yatsenko" [email protected] wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/thekip/node-modbus-rtu/issues/7#issuecomment-343727494, or mute the thread https://github.com/notifications/unsubscribe-auth/AbR4ykLkxfEV-H-hSMak2jzP_vgsQasEks5s1smmgaJpZM4QV29s .

vishalb747 avatar Nov 12 '17 11:11 vishalb747