Modbus - Flex Write node - Parameters

Hey Guys (hopefully @Steve-Mcl is listening !)

I am using the Modbus nodes extensively and not having any troubles - except i now want to pass two parameters through the Flex-write node and can not figure out the setup - here is my current code snippet from my function node

var values = [0x001,5000];
msg.payload = { 'value': values, 'fc': 16, 'unitid': 247, 'address': 0xb997, 'quantity': 2 }

and that works fine

I want to try and combine that with a 2nd write - as such

var values = [1,10];
msg.payload = { 'value': values, 'fc': 16, 'unitid': 247, 'address': 0xb995, 'quantity': 2 }

Is it possible to set two different registers by stacking the values in a variable ? If so what should the syntax look like - i have been playing with many options today but feel like i am going around in circles.

Both writes work - and if i issue them as two sequential commands i.e. Function 1 > Modbus-write > function 2 > Modbus write it works fine - just hoping to tidy it up a bit more

regards

Craig

Hi Craig, unfortunately the modbus protocoldoes not support non-sequential reads or writes. Whether the node actually supports multiple write operations internally (doing sequential writes itself), I can't remember. But it is simple enough to simulate using link-call.

Btw, if you are are working with a PLC, the better solution is to move the addresses adjacent to one another and send a write with contiguous data - that will result in a single network packet & consistent data.

Hi Steve

Thanks (as always !) for the speedy response. !

Yeah i am working with a GoodWe Solar Inverter rather than PLC gear so pretty much stuck with what i have been given.

OK just have to tidy up my spaghetti code now from playing and learning on this new unit and live with having to do a couple of writes.

regards

Craig

We made a subflow to handle one or more requests (or ranges of requests), send requests individually then join them back into a single output message. It was worth it as it allows much more flexibility without having to manage multiple messages in the flow (outside the subflow). I think the built-in way to send requests is extremely granular and way too detailed.

Here you can see how it may look when generalized, sending 1 request with 2 ranges (adjusting address number off-by-one compared to device documentation):

msg.payload = {
  fc: 4,
  startAddressModifier: -1,
  addresses: [
    {
      power_production:     { address: 3005, type: "uint32be",  scale: 0.001,              },
      dc_voltage_1:         { address: 3022, type: "int16be",   scale: 0.1,                },
      dc_current_1:         { address: 3023, type: "int16be",   scale: 0.1,                },
      dc_voltage_2:         { address: 3024, type: "int16be",   scale: 0.1,                },
      dc_current_2:         { address: 3025, type: "int16be",   scale: 0.1,                },
    },
    {
      fault_code_01:        { address: 3096, type: "int16be",                              },
      fault_code_02:        { address: 3097, type: "int16be",                              },
    },
  ]
};

We did the same thing with modbus write, so can send multiple requests in a single msg like this:

msg.payload = {
  topic1: {
    address: 123,
    value: 20
  },
  topic2: {
    address: 456,
    value: 30
  },
};

Here with default fc 6 and quantity 1 (otherwise it can be specified per request).