Cloud-Automation / node-modbus

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

Modbus RTU slave address in serial stream constantly = 0x01 #50

Closed SuperJojo2001 closed 8 years ago

SuperJojo2001 commented 8 years ago

Using node-red-contrib-modbus which is based on "node-modbus" I have no chance today to send any serial request to an address other than 1. So whatever I do on the serial line I see always a value 0x01 as first byte sent to the serial line.

I went to the source code and in the current onSend function...

var onSend = function (pdu) {

        var pkt = Put()
            .word8(1)
            .put(pdu),

buf = pkt.buffer();

... I see that the first byte is set to value 1 always. This shall be change to enable the possibility to sent to different slave addresses other than 1.

watch Modbus RTU spec here http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf

SuperJojo2001 commented 8 years ago

Instead we are using the following code var pkt = Put() .word8(this.unitId) .put(pdu), buf = pkt.buffer()

and now we are able to select the slave address the command is addressed to using the unitId known from Modbus TCP already.

SuperJojo2001 commented 8 years ago

Created the pull request #56