LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bynary array to number

Solved!
Go to solution

Hi,

 

I'm developing a program which would read serial port, capture packets, extract payload, convert the data in the payload and display. Now, everything until the last steps working fine. The problem is with the converting a byte array to number. In the serial communication, packets carry 16-bit unsigned integers (which basically means 2 bytes in the payload). Now the problem is how to convert these two bytes to an unsigned 16-bit integer in LabView. If I just try to convert the byte array using U16 converter, it outputs a 1-D array of unsigned 16-bit integers while I need only one. Is there any way to do this?

 

As an example, if I have two bytes 0x02 and 0x8C, and try to convert these to an unsigned 16-bit integer using U16 converter, it outputs an array [2, 140] while I need it to be converted to just 652.

Message Edited by Azzimuth on 03-04-2010 08:09 AM
0 Kudos
Message 1 of 9
(4,288 Views)

have you tried the "Scan From String" opeartor in the String palette?

 

See the help on that node to see if it may help.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 9
(4,275 Views)
How would that help? That works with strings while I need byte array...
0 Kudos
Message 3 of 9
(4,269 Views)

Also, on the Numeric >>> Data manipulation

 

palette you will find "Join Numbers" that will combine two byte into a U16.

 

Ben

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(4,266 Views)

Azzimuth wrote:
How would that help? That works with strings while I need byte array...

 

THat would help with the string coming from the serial port. If can be expanded and used to format multiple fields from a string.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 9
(4,264 Views)

Ben wrote:

Azzimuth wrote:
How would that help? That works with strings while I need byte array...

 

THat would help with the string coming from the serial port. If can be expanded and used to format multiple fields from a string.

 

Ben


Well that part is done and working fine. The only thing I need now is byte array to number conversion

0 Kudos
Message 6 of 9
(4,258 Views)
Solution
Accepted by topic author Azzimuth

use index array to pull out the two bytes (it can be expanded by dragging the bottm down to get two outputs).

 

Wire those two bytes to teh join and you are ready to go.

 

THere are other ways but I'll leave others to mention.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 9
(4,254 Views)
Join.PNG
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 9
(4,240 Views)
Thanks a lot! That worked just fine 🙂
0 Kudos
Message 9 of 9
(4,237 Views)