LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding ASCII 2-,3- and 4-characters into decimals

My task is to decode ASCII characters into its decimal representation. The amount of ASCII code is 2-,3- or 4 characters depending upon the data size (<= 12 bits, <= 18 bits, <= 24 bit ) sent from the unit.

Following is a 4-characters decoding example in practice:

 

1. m2@0 = m 2 @ 0

 

2. ↓ Hexadecimal Equivalent

    6DH 32H 40H 30H

 

3. ↓ Subtract 30H

    3DH 2H 10H 0H

 

4. ↓ Binary Equivalent

    1111012 0000102 0100002 0000002

 

5. ↓ Merge

    1111010000100100000000002

 

6. ↓ Decimal Equivalent

    16,000,000

 

My problem is how to split the ASCII characters (step 1.) and process them separately (basically step 2. - 4.). I've done fundamental ASCII-2-Hexadecimal converting, but found that this problem is more complex. Anyone having any advices? Smiley Happy

0 Kudos
Message 1 of 6
(3,111 Views)

Hi hannes,

 

the decimal value of $3d021000 is 1023545344, while 16,000,000 is $F42400…

 

Try this:

check.png

 

As your "ASCII" seems to contain only 6 bits of information you should use some additional bit shifting:

check.png

Now your example data gives 16,000,000 as result!

 

Lessons learned: Provide all information needed in clear words and in the first place…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(3,089 Views)

Thanks for the support GerdW!

Sorry for the misleading example. It was provided from the Communication Protocol Specification.

In your solution, what does the symbol in front of the values in the numeric constant mean?

 

An example from the manual for the 3-character decode process:

 

1. 1Dh = 1 D h

 

2. ↓ Hexadecimal Equivalent

    31H 44H 68H

 

3. ↓ Subtract 30H

    1H 14H 38H

 

4. ↓ Binary Equivalent

    000001 010100 111000

 

5. ↓ Merge

    000001010100111000

 

6. ↓ Decimal Equivalent

    5,432 [mm]

 

I assume that your second solution will work for this process aswell because of the 6 bits interval of information transmitted?

 

Best regards,

 

Hannes

0 Kudos
Message 3 of 6
(3,072 Views)

Hi Hannes,

 

that symbol is the radix, made visible by right-click -> visible objects on the numeric constant. They are set to hex display as requested by your explanation…

 

In your new example you will get the number 347648 with my snippet from above. You need to apply an additional scaling factor of 64000, but this is not mentioned at all in your explanation between step 5 and 6…

 

Or you change the snippet to work with LSB first:

check.png

Now the number of bytes is not important anymore. For your example you will need a scaling factor of 1000 to scale 5432 down to 5.432!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 6
(3,064 Views)

Thank you!

 

Where do I find/how to create the "mix" of the numeric constants left of the bottom "Reverse 1D Array"?

 

Best regards,

 

Hannes

0 Kudos
Message 5 of 6
(3,042 Views)

Its a Numeric Array.

http://zone.ni.com/reference/en-XX/help/371361J-01/glang/array_constant/

http://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/creating_array_constants/

 

Also Click on the snippets link below to learn how to use snippets in your code.

 


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 6 of 6
(3,032 Views)