Re: [node-red] IEEE 754 float conversion

929 views
Skip to first unread message

Dave C-J

unread,
Apr 26, 2017, 10:15:48 AM4/26/17
to node...@googlegroups.com

it uses the packet package - takes a bot of getting head around - but that has some useful capabilities that may be what you need... 

Dave C-J

unread,
Apr 26, 2017, 10:24:05 AM4/26/17
to node...@googlegroups.com
maybe

[{"id":"915b58eb.adf578","type":"debug","z":"2df73bf4.4747c4","name":"","active":true,"console":"false","complete":"false","x":598,"y":2710,"wires":[]},{"id":"f0b3a4c4.25e478","type":"inject","z":"2df73bf4.4747c4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":145,"y":2719,"wires":[["373e28f6.867c48"]]},{"id":"373e28f6.867c48","type":"function","z":"2df73bf4.4747c4","name":"","func":"msg.payload =new Buffer( [0x43, 0x68, 0x66, 0x66]);\nreturn msg;","outputs":1,"noerr":0,"x":308.5,"y":2718,"wires":[["53504610.e09ad8"]]},{"id":"53504610.e09ad8","type":"binary","z":"2df73bf4.4747c4","name":"","pattern":"l32f","x":441.5,"y":2712,"wires":[["915b58eb.adf578"]]}]

Csongor Varga

unread,
Apr 26, 2017, 10:55:16 AM4/26/17
to Node-RED
Sorry for the confusion, After I posted my question, I found a related thread. I deleted the question, but probably too late.

So, for anyone who does not understand the issue, I was asking how I can convert the 2 word IEEE 754 float value which is used for example in Modbus to a javascript float value.

Dave C-J

unread,
Apr 26, 2017, 11:26:50 AM4/26/17
to node...@googlegroups.com
I'd still use the binary node :-)

steve rickus

unread,
Apr 26, 2017, 12:22:19 PM4/26/17
to Node-RED
In trying to use the binary node, I've wasted a good bit of time doing something I think should take 15 secs.
I have inject nodes that pass 1. a single number, and 2. an array of two numbers

Both msg types cause "Error: invalid input", no matter what pattern I try to use. The node info says it accepts either a javascript object or a buffer, so I'm guessing it does not look at an array of integers as an "object". I've asked the author whether it could support these use cases but got no response. Am I trying to do something that makes no sense, or is this a reasonable request?

Incidentally, the node info really needs some simple examples of patterns to use for converting [int16, int16] -> flt32 and vice versa -- the packet docs seem to imply that double quotes are needed, but i'm sure the node input takes care of that...

Dave C-J

unread,
Apr 26, 2017, 12:35:28 PM4/26/17
to node...@googlegroups.com
It expects Buffers   not an array object  
(though a Buffer is of course an array of sorts ;-)

steve rickus

unread,
Apr 26, 2017, 1:36:24 PM4/26/17
to Node-RED
Granted... but i guess i was wondering more about the node's intent, and the best place to add new features.

I've seen several recent questions on slack and this group about converting a stream of int16s into flt32 numbers (or vice versa), so having a node to mangle the ArrayBuffers and do the conversion would be very handy. The javascript built-in support can clearly handle any combination of those, but having a syntax like "packet" uses to define the inputs/outputs could provide a reusable chunk of logic (a node), rather than writing custom function nodes. So I guess I'm wondering if you see any reasons why this could not be part of node-red-contrib-binary, or should it really be a separate node? Or could the change node provide that feature? I'd be willing to work on a new node (more so than the other two nodes), but wouldn't want to re-invent the wheel -- again.

This also raises another question -- could the inject node be extended to output a binary buffer? I could use them when setting up X10 command streams that I'd like to pass to my flow. Other than a function node, is there another good way to generate binary data? Sorry for all the questions, but I'm just trying to learn what tricks others have used.
--
Steve

Dave C-J

unread,
Apr 26, 2017, 3:39:44 PM4/26/17
to node...@googlegroups.com
Well I "think" this node is fairly clear (but obviously isn't) - in that it converts a binary buffer to/from a javascript object - both ways - based on a template defined by the Packet format. Effectively aimed at similar function to Perl pack/unpack - or C struct  etc - to help with devices that expect some binary chunk of data - that needs a template to help conversion....

So how could it be changed to do what you want - what would need to be different, as presumably your x10 needs a binary buffer that could be assembled by this as-is ?

Re adding Buffer to inject - yes probably worth looking at ... 
Reply all
Reply to author
Forward
0 new messages