Simple (should be) buffer parser question

Hi. I'm reading serial data and its a bunch of hex encoded numbers. For example I might get 30,44,30,33 which is 0x0D03 or 3,331. Seems like a simple matter for buffer parser but I cannot get it to work.

My simple example below gives me a confusing error message: ""RangeError: The value of "offset" is out of range. It must be >= 0 and <= 0. Received 4" How could it be greater and less than zero?

Here is my flow, seems pretty simple but it's got me confused.

[{"id":"257ad45cdf54c5f2","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"c6494528af2baa59","type":"inject","z":"257ad45cdf54c5f2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[48,68,48,51]","payloadType":"bin","x":170,"y":120,"wires":[["f908186aec31e041"]]},{"id":"f908186aec31e041","type":"buffer-parser","z":"257ad45cdf54c5f2","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int32le","name":"Cell1","offset":0,"length":4,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":410,"y":120,"wires":[["371baf5d5bde9dfb"]]},{"id":"371baf5d5bde9dfb","type":"debug","z":"257ad45cdf54c5f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":610,"y":120,"wires":[]}]

The error is a bug (fixed in my dev copy) but its just a visual/status issue. The problem is you are asking buffer parser to create 4 32bit values out of 4 bytes (30,44,30,33). To generate 4 32bit values, your input buffer would need to be 16 bytes (32/8*4=16)

Your main issue is the buffer is essentially an ASCII string (30=0, 44=D, 30=0, 33=3)

In order to make sense of that, you need to first convert it to a hex string of 0d03 then you can use that to do the conversion
image

[{"id":"28293bf6287fc342","type":"inject","z":"257ad45cdf54c5f2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[48,68,48,51]","payloadType":"bin","x":366,"y":208,"wires":[["6d9ce84d4c1901a6"]]},{"id":"a9dffa4e428e7cf7","type":"debug","z":"257ad45cdf54c5f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":758,"y":208,"wires":[]},{"id":"6d9ce84d4c1901a6","type":"buffer-parser","z":"257ad45cdf54c5f2","name":"hex string to string","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"string","name":"data","offset":0,"length":-1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":550,"y":208,"wires":[["a9dffa4e428e7cf7","5c8c4cae8aaa81d9"]]},{"id":"5c8c4cae8aaa81d9","type":"buffer-parser","z":"257ad45cdf54c5f2","name":"","data":"payload.data","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"Cell","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":566,"y":272,"wires":[["9db7a892d862e3c7"]]},{"id":"9db7a892d862e3c7","type":"debug","z":"257ad45cdf54c5f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":746,"y":272,"wires":[]}]
1 Like

That works perfect. Node-Red is amazing and the people on this forum are the best. Where else can you get an answer in 15 minutes on a Sunday morning that is spot on. Thanks again!!

3 Likes

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