# Modbus flex getter + buffer parser = true

**URL:** <https://discourse.nodered.org/t/modbus-flex-getter-buffer-parser-true/95435>\
**Category:** General\
**Created:** [15 February 2025 23:56 UTC](https://discourse.nodered.org/t/modbus-flex-getter-buffer-parser-true/95435 "2025-02-15T23:56:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThingsTinkerer](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)\
**Post date:** [15 February 2025 23:56 UTC](https://discourse.nodered.org/t/modbus-flex-getter-buffer-parser-true/95435/1 "2025-02-15T23:56:54Z")

</div>

Managed to make a subflow that combines modbus read requests with the brilliant buffer parser!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b55d6563d227fd7d492a64fa1926adc5b0c33fa.png)  
Which means every read request can now be simplified to this format:

```javascript
msg.payload = {
  fc: 4,
  value: 0, // optional, default 0
  byteswap: [], // optional, default []
  quantity: 1, // optional, default is automatically calculated from addresses
  startAddressModifier: -1, // optional, default 0
  address: [
    [
      { name: "dc_voltage_1", type: "int16be", address: 3022, scale: 0.1, },
      { name: "dc_current_1", type: "int16be", address: 3023, scale: 0.1, },
      { name: "dc_voltage_2", type: "int16be", address: 3024, scale: 0.1, },
      { name: "dc_current_2", type: "int16be", address: 3025, scale: 0.1, },
    ],
    [
      { name: "fault_code_01", type: "int16be", address: 3096, },
      { name: "fault_code_02", type: "int16be", address: 3097, },
    ]
  ]
};

```

Some optional args here that is best to skip unless needed, so all I really need to make a modbus read request is this:

```javascript
msg.payload = {
  fc: 4,
  startAddressModifier: -1, // optional, default 0
  address: [
    [
      { name: "dc_voltage_1", type: "int16be", address: 3022, scale: 0.1, },
      { name: "dc_current_1", type: "int16be", address: 3023, scale: 0.1, },
      { name: "dc_voltage_2", type: "int16be", address: 3024, scale: 0.1, },
      { name: "dc_current_2", type: "int16be", address: 3025, scale: 0.1, },
    ],
    [
      { name: "fault_code_01", type: "int16be", address: 3096, },
      { name: "fault_code_02", type: "int16be", address: 3097, },
    ]
  ]
};

```

The payload above will result in 2 separate queries, everything not specified here will be handled automatically. Such as quantities and offsets. Finally, all successfull responses are merged into a single object, so you end up with something like this:

```javascript
msg.payload: {
  dc_voltage_1: 12,
  dc_current_1: 34,
  dc_voltage_2: 56,
  dc_current_2: 78,
  fault_code_01: 1,
  fault_code_02: 2,
}

```

Now I'm not a modbus expert, but the standard way of going about specifying start address, quantity, then get the list of bytes to be sent to buffer parser, only to again deal with offset seems much more complicated. I think the original modbus flex-getter would benefit greatly from incorporating the buffer parser. Perhaps there is a need to keep them separated, but so far all of my usage can be summarized by the examples shown here.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2025 00:57 UTC](https://discourse.nodered.org/t/modbus-flex-getter-buffer-parser-true/95435/2 "2025-02-16T00:57:52Z")

</div>

> [@ThingsTinkerer](#):
>
> with the brilliant buffer parser

Glad you like it. I'm rather proud of it. It's not perfect but it is flexible. I think this is one of the first posts I've seen where it's being used programmatically. Cool.

---

<div class="post-metadata">

**Author:** ![ThingsTinkerer](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)\
**Post date:** [19 February 2025 13:21 UTC](https://discourse.nodered.org/t/modbus-flex-getter-buffer-parser-true/95435/3 "2025-02-19T13:21:35Z")

</div>

Would it be possible to get a list of how many bytes each type is?

Noticed that buffer parser doesn't support scale. It will be something I add on top, so if type is bigint, and scale is not default "1", then I move scale to scaleBig. Reset scale to "1". And after buffer parser, check if scaleBig exists, then do scale there. With the normal cautions for bigint.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 May 2025 13:22 UTC](https://discourse.nodered.org/t/modbus-flex-getter-buffer-parser-true/95435/4 "2025-05-20T13:22:15Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
