Got issue in buffer parser node with Mc-protocol node

Hi there,
I was having issue When i tried 520000 it gives this error

"Error: Exception preparing the write buffer for item 'D28': RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -32768 and <= 32767. Received 520000"

using this Flow

[
    {
        "id": "2675d77db8276e1c",
        "type": "inject",
        "z": "c9566eb69956fe5d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "D28",
        "payload": "520000",
        "payloadType": "num",
        "x": 230,
        "y": 1900,
        "wires": [
            [
                "3aa7ae60ba13a900"
            ]
        ]
    },
    {
        "id": "3aa7ae60ba13a900",
        "type": "MC Write",
        "z": "c9566eb69956fe5d",
        "name": "",
        "topic": "",
        "connection": "8c926f873226d344",
        "data": "payload",
        "address": "topic",
        "addressType": "msg",
        "dataType": "msg",
        "errorHandling": "throw",
        "outputs": 1,
        "x": 340,
        "y": 1760,
        "wires": [
            [
                "6bc305555dbb14cb"
            ]
        ]
    },
    {
        "id": "6bc305555dbb14cb",
        "type": "debug",
        "z": "c9566eb69956fe5d",
        "name": "debug 9",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 1700,
        "wires": []
    },
    {
        "id": "5a0ee7502a26083d",
        "type": "MC Read",
        "z": "c9566eb69956fe5d",
        "name": "JobID",
        "topic": "",
        "connection": "8c926f873226d344",
        "address": "topic",
        "addressType": "msg",
        "outputFormat": 0,
        "errorHandling": "throw",
        "outputs": 1,
        "x": 390,
        "y": 1620,
        "wires": [
            [
                "6bc305555dbb14cb"
            ]
        ]
    },
    {
        "id": "7696f023cd4a497e",
        "type": "change",
        "z": "c9566eb69956fe5d",
        "name": "D28,1",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "D28,1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 250,
        "y": 1580,
        "wires": [
            [
                "5a0ee7502a26083d"
            ]
        ]
    },
    {
        "id": "e45cbab16188f3a2",
        "type": "inject",
        "z": "c9566eb69956fe5d",
        "name": "Jobid D28",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "D28,2",
        "payload": "",
        "payloadType": "date",
        "x": 170,
        "y": 1640,
        "wires": [
            [
                "7696f023cd4a497e"
            ]
        ]
    },
    {
        "id": "8c926f873226d344",
        "type": "MC Protocol Connection",
        "name": "",
        "host": "192.168.2.20",
        "port": "5001",
        "protocol": "TCP",
        "frame": "1E",
        "plcType": "Q",
        "ascii": false,
        "PLCStation": "2",
        "PCStation": "255",
        "PLCModuleNo": "2",
        "network": "2",
        "octalInputOutput": false,
        "timeout": "5000"
    }
]

and with buffer parser node

[
    {
        "id": "2675d77db8276e1c",
        "type": "inject",
        "z": "c9566eb69956fe5d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "D28",
        "payload": "520000",
        "payloadType": "num",
        "x": 230,
        "y": 1900,
        "wires": [
            [
                "3aa7ae60ba13a900"
            ]
        ]
    },
    {
        "id": "3aa7ae60ba13a900",
        "type": "MC Write",
        "z": "c9566eb69956fe5d",
        "name": "",
        "topic": "",
        "connection": "8c926f873226d344",
        "data": "payload",
        "address": "topic",
        "addressType": "msg",
        "dataType": "msg",
        "errorHandling": "throw",
        "outputs": 1,
        "x": 340,
        "y": 1760,
        "wires": [
            [
                "6bc305555dbb14cb"
            ]
        ]
    },
    {
        "id": "6bc305555dbb14cb",
        "type": "debug",
        "z": "c9566eb69956fe5d",
        "name": "debug 9",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 1700,
        "wires": []
    },
    {
        "id": "5a0ee7502a26083d",
        "type": "MC Read",
        "z": "c9566eb69956fe5d",
        "name": "JobID",
        "topic": "",
        "connection": "8c926f873226d344",
        "address": "topic",
        "addressType": "msg",
        "outputFormat": 0,
        "errorHandling": "throw",
        "outputs": 1,
        "x": 390,
        "y": 1620,
        "wires": [
            [
                "81499fcc262083ba"
            ]
        ]
    },
    {
        "id": "7696f023cd4a497e",
        "type": "change",
        "z": "c9566eb69956fe5d",
        "name": "D28,1",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "D28,1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 250,
        "y": 1580,
        "wires": [
            [
                "5a0ee7502a26083d"
            ]
        ]
    },
    {
        "id": "e45cbab16188f3a2",
        "type": "inject",
        "z": "c9566eb69956fe5d",
        "name": "Jobid D28",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "D28,2",
        "payload": "",
        "payloadType": "date",
        "x": 170,
        "y": 1640,
        "wires": [
            [
                "7696f023cd4a497e"
            ]
        ]
    },
    {
        "id": "81499fcc262083ba",
        "type": "buffer-parser",
        "z": "c9566eb69956fe5d",
        "name": "Convert array to named values",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16le",
                "name": "JOB ID",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "swap16",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload1",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 490,
        "y": 1660,
        "wires": [
            [
                "6bc305555dbb14cb"
            ]
        ]
    },
    {
        "id": "8c926f873226d344",
        "type": "MC Protocol Connection",
        "name": "",
        "host": "192.168.2.20",
        "port": "5001",
        "protocol": "TCP",
        "frame": "1E",
        "plcType": "Q",
        "ascii": false,
        "PLCStation": "2",
        "PCStation": "255",
        "PLCModuleNo": "2",
        "network": "2",
        "octalInputOutput": false,
        "timeout": "5000"
    }
]

Error: data is not an array or a buffer

so what is the issue i am not understanding

That appears to be coming from the MC Write node, not the parser. It says that you cannot write that value to D28.

But then how to write 520000 to D28
and you missed this

Error: data is not an array or a buffer
which came from buffer parser

I don't know about the mc protocol. Does it allow writing that value?

Add a debug node showing what is coming out of the MC Read node.

@Steve-Mcl

it does allow to write

but the issue is about read node in range of >= -32768 and <= 32767 due to int16

and therefore i cant see the value from mc-protocol read node give error

Error: Exception preparing the write buffer for item 'D28': RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -32768 and <= 32767. Received 520000

so i am using buffer parser node to change type int32 for range increase but the issue is it gives error

Error: data is not an array or a buffer

Which node is that coming from and which flow?

I presume that is from the parser node, so, as I said add a debug node showing what you are feeding to the buffer parser.

Also which mc package are you using? There are at least three on the node-red flows page.

node-red-contrib-mcprotocol

Looking at the demo example they provide (select Import then Examples) it looks as if you need to pass the data in an array.

The problem with the parser node is that it too expects an array or a buffer.

What does the D in the address signify?

Hi there,
as per my pervious topic regarding mc-protocol node

if you can read you will know that @Steve-Mcl Helped me a lot in this and I appreciate about it but as per his example i worked out but the issue i faced is this only

Does that answer my question?

The data going into the buffer-parser is not an array (of 16 bit integer) or a Buffer (of bytes)

By adding a debug to the output of the MC Read that is clear to see it is neither of those 2 requirements:

Ok, first thing first; You are only asking for 1 value from address D28 by setting D28,1. I wrote a LOT of help info here and here but I guess you didnt bother to learn that?

Ok, once more. To make a 32 bit value, you NEED 2x16bit data values. E.g. Request D28,2

Now, with the address correct, lets look at the MC-Read setting:

You have NOT changed the output to Array Lets try that...

Close, but no cigar. You had the buffer parser set to convert the value to an int16 - AND, the output set to msg.payload1 Lets correct those (select uint32(le) type and set the output to msg.payload)

And it works...



As I said in the last post, you really should read the help.

Working Example:

A sidenote, I get that these devices are extremely low level, dealing with bits and bytes. But why can't the tools take care of all that? Not sure if this is a completely different case, but I recently dug down into modbus and buffer parser. And then discovered, the only thing you need to supply is the address of the value and the type! However the tools where all divided like here, so you had to connect the dots with offsets and so forth.Why?

That being said, if you don't know what a byte is, a 16-bit value or 32-bit value, you have no business doing these kind of tasks...

Many reasons. Here are some

I wrote the MC Protocol node and the OMRON fins node. I did NOT want to write the same logic (including any bugs/mistakes I made) into both. I could have made a lib and imported that into both of them but I'd still have to do the parsing UI. Mitsi and Omron protocols are similar to modbus in that you read WORD or BIT values. Then, there are the other contrib nodes I did NOT write. Should I request them to do what I did?

If every node package implemented their own version of bit/byte/word/float/etc they would all do it differently and all have their own subtleties. The common denominator of every computer data is the byte. Buffer parser provides a unified approach. It fits well with the mantra a node should do one thing and do it well.

Modbus deals with 16 bit values (and bit/bool). that's it. If you want to read a string, sure, grab the 16 bit values and convert it. But is it big or little endian? is it ascii/utf8?

Some PLC nodes will return floats and signed integers but they may be in an object.data.value or in an array under payload.data or ... - Now you then have to pull them out and manipulate into the format you want for sending to MQTT or another system.

Data at the wire level (TCP/Serial) etc can be byte swapped. You might not be using a dedicated PLC type node and have to request and parse the data yourself.

That is the crux of the matter. A person who doesn't understand byte swapping / endianess, byte level access, bit manipulation, etc really should not be reading and writing to PLCs. Full stop. However, even seasoned PLC folk may struggle with computer coding so the buffer parser is designed to minimise the boilerplate code you would have to write every time you want to interface disparate systems with differing data types and formats.

Having the parser stand-alone is perfectly justifiable. Having the reader standalone (returning low-level bits & bytes) seems niche or situational. Having both in a single "package" (metaphorically speaking here) is what I'd use every day all day. And judging by all the people who struggle with it, I'd guess what they'd want to use as well. Now I didn't mean to criticize the parser. Instead, it's the reader who seems half-baked. Yes, you get the dependencies. But isn't that what node.js is all about? Dependencies everywhere!


I think having to skip all the bits and bobs dwarfs the drawbacks you point out. And regardless, you need to set the types correctly. No avoiding that. That's true whether you split the task in 2 or combine them in 1.

Now I made my combo for modbus, so I don't have to deal with it anymore. I know I'd like to get that done already so I didn't have to deal with it (by whoever made the modbus node). And I'd like that to be done by whatever other reader I'd need to use.

@Steve-Mcl ,
Thanks a lot for the Help you provide to me by giving your time,
i appreciate that you gave me a solution on this and i need the example flow if you can provide me the JSON

I cannot. The changes I made were detailed above & I did not keep the flows.

@Steve-Mcl ,
As you declared it as DDWORD28 would i need to use it like that and why as other address i use D990 etc

D990 is 1 data memory. The size of 1 data memory is 16 bits in a mitsi PLC.
DDWORD28 is addressing a DWORD (double word i.e. 2x16 bit) BECAUSE you wanted to write 520000.

Only YOU know if D990 is a 1WORD/16bit or 2WORD/32bit!

1 Like