LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ASCII string to decimal string and its sum

Solved!
Go to solution

Hello All,

 

I am a beginner in Labview and this is my first post on the forum.

 

I am receiving a serial packet "1200F" on the COM port from an MCU. These are all ASCII characters.

I want to convert all these ASCII characters to decimal numbers and add up their decimal values to get the sum. So I have taken the ASCII string into an array using "String to Byte Array" and then type cast this using constant type U8. I have put this in for loop and collecting the decimal value using Build Array function. Then I am "Add array elements" function to add these decimal values to get the sum.

 

The problem is that for input string I am able to get sum of "1200" only. The moment I type the last ASCII character F, the sum goes wrong. I see that when the sum goes above 255 it again resets from 0 onwards. I have attached the VI for reference.

 

Any help would be appreciated.

0 Kudos
Message 1 of 4
(3,483 Views)

hi

     you can change your dispaly numeric data type.

0 Kudos
Message 2 of 4
(3,468 Views)
Solution
Accepted by topic author knikhil

Sum ASCII.png

 

Convert to U32 to avoid the 255 limitation of U8.

0 Kudos
Message 3 of 4
(3,467 Views)

Thanks JB, this works and more simpler than I was thinking.

0 Kudos
Message 4 of 4
(3,431 Views)