where are you seeing 2 hexadecimal strings? I see a Data
object with 2 16 bit values and an equivalent buffer containing the byte values.
So you want to "display" ( i assume on a dashboard) the hexadecimal value of the 16 bit integer returned from the PLC? So, if you read the readme you will see there is a companion node node-red-contrib-buffer-parser
that can do pretty much everything you need to do with data.
As a tip, if you click the value msg.data[0]
in the debug window, it will show you the hexadecimal equivalent of the decimal value 8721
.
The readme has some info with regards PLC data formats...
Data formats and conversion
As I use multiple PLCs and didn't want to write boolean / 32bit / float / double functionality into each node (it's best to keep things atomic and good at what they do) so I wrote a separate second node for handling data conversions.
This node "node-red-contrib-buffer-parser" node-red-contrib-buffer-parser (node) - Node-RED is capable of pretty much anything you will need for this or any PLC that returns 16bit data or a NodeJS Buffer.
In essence, you pull a bunch of data from the plc in one go & convert it all in the buffer-parser node to almost any format you could wish for (bits, floats, 32bit signed / unsigned, byteswapping etc etc). It can do 1 or many conversions all at once. It can send a grouped item (object) or individual items with a
topic
ready for pushing your data directly from the PLC to MQTT.
Here is a demo...
[{"id":"e655a6aea0634b73","type":"buffer-parser","z":"6061813d087d6df4","name":"","data":"payload.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"asInteger1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"asInteger12","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"asHex1","offset":0,"length":2,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"asHex2","offset":2,"length":2,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1830,"y":160,"wires":[["4ea4b17021893a18"]]},{"id":"fdee6645fb2c9d53","type":"inject","z":"6061813d087d6df4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1510,"y":100,"wires":[["be79f96065e17c75"]]},{"id":"be79f96065e17c75","type":"function","z":"6061813d087d6df4","name":"Faking your PLC data","func":"msg.payload = {\n Data: [8721, 8721],\n buffer: Buffer.from([0x11,0x22,0x11,0x22])\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1590,"y":160,"wires":[["e655a6aea0634b73","4dfdc0a13fb6675b"]]},{"id":"4ea4b17021893a18","type":"debug","z":"6061813d087d6df4","name":"Parsed Data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1910,"y":220,"wires":[]},{"id":"4dfdc0a13fb6675b","type":"debug","z":"6061813d087d6df4","name":"PLC Data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1680,"y":220,"wires":[]}]