02-24-2014 04:08 AM - edited 02-24-2014 04:25 AM
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?
02-24-2014 05:10 AM - edited 02-24-2014 05:14 AM
Hi hannes,
the decimal value of $3d021000 is 1023545344, while 16,000,000 is $F42400…
Try this:
As your "ASCII" seems to contain only 6 bits of information you should use some additional bit shifting:
Now your example data gives 16,000,000 as result!
Lessons learned: Provide all information needed in clear words and in the first place…
02-24-2014 06:23 AM
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
02-24-2014 06:47 AM - edited 02-24-2014 07:16 AM
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:
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!
02-24-2014 08:48 AM
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
02-24-2014 09:04 AM
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.