Need assistance converting serial input buffer to numbers

Hi.

I have a serial input node and are reading data from a device. Its a binary input and i split the data in the serials node on eight characters. I get the following data from the serial input:

4/5/2021, 1:57:03 PMnode: 1e6025fa.f87f7amsg.payload : buffer[8]

[ 1, 1, 1, 1, 0, 0, 0, 0 ]

etc

I then use the bitreloader node and convert the data to numbers:

4/5/2021, 1:57:03 PMnode: 77acceeb.dff82msg.payload : number

31

etc

The questions is how do i switch these numbers into separate nodes so that i can use and convert each number individually? I have tried the switch node but with no success.

Will someone be so kind enough to help me.

Hi, what you have written doesnt realy make a lot of sense.

Are you certain you get 31 from [ 1, 1, 1, 1, 0, 0, 0, 0 ] ?

I was going to suggest the buffer-parser node but I cant make sense of your data.

Here is a quick demo of buffer-parser output options...

(note i simply cannot get 31 from [ 1, 1, 1, 1, 0, 0, 0, 0 ] no matter how i do the conversions)


Demo

The input is a buffer containing [ 1, 1, 1, 1, 0, 0, 0, 0 ] (to simulate your data)

flow 1 - output an object of key/value (ideal for further calculations where you need all values in same message)
flow 2 - output multiple values (with topic) from one output (ideal for sending to MQTT)
flow 3 - output multiple values from individual outputs (ideal for sending values down different paths)

Demo flow...

[{"id":"f0cabe4a.c6b24","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[ 1, 1, 1, 1, 0, 0, 0, 0 ]","payloadType":"bin","x":1250,"y":192,"wires":[["259d1e83.d42762"]]},{"id":"259d1e83.d42762","type":"buffer-parser","z":"942b70c6.58cc6","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"int16_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_2","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_3","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_4","offset":6,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32le","name":"uint32_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32le","name":"uint32_2","offset":4,"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":1448,"y":192,"wires":[["333dafcd.a18d9"]]},{"id":"333dafcd.a18d9","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":192,"wires":[]},{"id":"47648ca4.4108d4","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[ 1, 1, 1, 1, 0, 0, 0, 0 ]","payloadType":"bin","x":1252,"y":364,"wires":[["ddd70f53.3e54f"]]},{"id":"ddd70f53.3e54f","type":"buffer-parser","z":"942b70c6.58cc6","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"int16_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_2","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_3","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_4","offset":6,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32le","name":"uint32_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32le","name":"uint32_2","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":true,"setTopic":true,"outputs":6,"x":1448,"y":364,"wires":[["b849e846.3c03c8"],["bab2dca5.0d18c"],["6b293bc3.521c14"],["276b03ee.b9adac"],["fa1a116c.b604c"],["bee97cc7.7118"]]},{"id":"b849e846.3c03c8","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":288,"wires":[]},{"id":"856625c2.6c7a38","type":"buffer-parser","z":"942b70c6.58cc6","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"int16_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_2","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_3","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16_4","offset":6,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32le","name":"uint32_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32le","name":"uint32_2","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1448,"y":240,"wires":[["30c500dc.3dc7b"]]},{"id":"d8144dca.9f29a","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[ 1, 1, 1, 1, 0, 0, 0, 0 ]","payloadType":"bin","x":1250,"y":240,"wires":[["856625c2.6c7a38"]]},{"id":"30c500dc.3dc7b","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":240,"wires":[]},{"id":"bab2dca5.0d18c","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":320,"wires":[]},{"id":"6b293bc3.521c14","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":352,"wires":[]},{"id":"276b03ee.b9adac","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":384,"wires":[]},{"id":"fa1a116c.b604c","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":416,"wires":[]},{"id":"bee97cc7.7118","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1656,"y":448,"wires":[]}]

Many thanks. I really appreciate.

On initial testing it looks like it could work.

I have 13 bytes of data to switch and convert. How do i adapt you flow to cater for 13 numbers.

No sorry i just cut and pasted.......the numbers wont match :slight_smile:

4/6/2021, 8:37:58 AMnode: b0b55f5d.4d34dmsg.payload : buffer[8]

[ 0, 0, 0, 0, 0, 1, 1, 1 ]

4/6/2021, 8:40:19 AMnode: 9f53c77a.5fc4a8msg.payload : number

7

Is that direct from serial port? Can you show a screenshot of debug node output (connected direct to serial node)

You didint answer.

Can you show your flow?

yes thats direct from serial port

From bitreloader i get the actual value but are unable to switch it seperate nodes so the i can convert and display it

Can you disconnect everything (except 1 debug) from the serial input node and capture data from serial port one more time please (I have some doubts)

serial port and debug only

That is most odd (and very very wasteful) use of bytes.

What is transmitting this data? Are you in control of the format of data being sent?

It comes from an engine management system. I want to use the data to make myself a dashboard display. The following is what i have on the data:

Ver 3.5 Protocol Real time values

You need to poll each block of data by sending a 252 value on the serial port. After the block is returned, an end code of 252 will follow to confirm legit table length.

Serial port is UART and run 19200 baud.

Real Time Data - 252

Byte0 – Revs 23=2300 rpm

Byte1 – MAP Sensor 0-255 = Full Scale. Graph scale depends on Vacuum sensor scale selection. If it is set at 2.1 bar means 255=2.1 bar. 128 means 1.05 bar

Byte2 – TPS 0-255 = Full Scale 255=100% 128=50%

Byte3 – Lambda narrow band 100= 1.00V. wide band 250=5 volt

Byte4 – Water Temperature 63 = 23°C scale is -40 to 140 with 40 count offset.

Byte5 – Air Temperature 63 = 23°C scale is -40 to 140 with 40 count offset.

Byte6 – Pot Position 0-255 = Full Scale 255=100% 128=50%

Byte7 – Battery Volts 127 = 12.7

Byte8 – Injector Time 120 = 12.0 milliseconds

Byte9 – Error Code 0 to 250)

Byte10 – Altitude Sensor 0-255 = Full Scale 255=1.1 Bar.

Byte11 – Fuel pressure 0-255 = Full Scale depends on Sensor selection. If 5.5 bar sensor is selected, then 255=2=5.5 bar

Byte12 – Spark Timing Value 15 = 15 Degrees BTDC

ok, well that is nothing like the data samples you have sent.

i would expect to see something like [23,128,128,250,63,63, ..., ..., etc]

The fact you are getting [0,0,0,0,0,1,1,1] and attempting to convert that to 7 is the reason i am confused. If this [0,0,0,0,0,1,1,1] was once more "made up by you" then you have it wrong and again the reason I was confused.

I now suspect you WILL get data like [23,128,128,250,63,63, ..., ..., etc] And yes, buffer parser is ideal for splitting out those bytes into named items.

Byte13 – End Code 252 is the end code

Apologies for he delay. For some reason I can only send 4 messages a day. The "serial port and debug only" data that i send is the real data from the serial input. If I change the serial port to ascii I only get questions marks as an output?

The serial port outputs the data really fast so it is difficult to match the input to the converted data if that makes sense. Hence the data is confusing as you states.

I will really appreciate if you can help me. I am beyond confused and very frustrated with this problem at the moment :smiley: :smiley:

I haven't used the buffer parser before and are battling to understand how it works and how to configure it. I don't understand what offset does?

Read the built in help. It is a byte offset from the input data.

So if you(or a serial port) sends [10,11,12,13] and you set up buffer parser to read a byte from offset 0 you will get 10, if you ask for an unsigned int16 from offset 2, it will use bytes 2&3 (values 12&13)

It is clearly explained in the built in help.

The problem is your data. From your explanation of the bytes, the data you have shown coming from the serial port is NOTHING like expected.

Can you show me your serial port config?