ModBus Write Node

I have a power meter that uses ModBus and I've figured out how to read data from the bus using the modbus read and getter node.

However, now I'm trying to write to the module to change the address and I'm not sure how the modbus write node should be configured. The data sheets (linked below) specifies that I should use function 6 (write single register) but I'm not seeing where I should be entering data (the address itself) into the node.

Datasheet:

I recently needed to configure a Novus DigiRail 4C Modbus counter, and I did this by wrting a simple function which generates the messages, passing these to a Modbus Flex Write node:

Screenshot_2019-09-16_09-58-38
The function looks like this:

// set the DigiRail to diagnostics mode before running
// this function will set unitid 6, 9600 baud, no parity

var id = 246;
var func = 6;
var addrs = [2,3,4];
var vals = [3,6,0]

for(var k=0; k<addrs.length; k++) {
    msg.payload = {
        "unitid":id,
        "fc":func,
        "address":addrs[k],
        "value":vals[k],
        "quantity":1
    }
    node.send(msg)
}

It produces three messages; the first one sets the Baud rate, second the Modbus address, and the third sets the parity. From the DigiRail manual:

Screenshot_2019-09-16_10-06-07

Screenshot_2019-09-16_10-01-50

In your case the device only allows changing the Modbus slave address (not Baud rate or parity), and this is held in register #2. And the default slave address appears to be 248, so I think your function should look something like this (with "123" being the new address):

var id = 248;
var func = 6;
var reg = 2;
var val = 123;

msg.payload = {
    "unitid":id,
    "fc":func,
    "address":reg,
    "value":val,
    "quantity":1
}
return msg;
2 Likes

@clickworkorange Thanks that function allowed me to change the address.

1 Like