LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a number to string like chr$ does

I'm trying to send a checksum out in a serial message. The checksum calculation result is a number (i.e. 42 hex) but I need to send it as the letter"B". All the string conversions I have tried send the characters "42". Any idea how to do this?
0 Kudos
Message 1 of 7
(3,419 Views)
You can typecast a number to a character.

typecast is under the advanced/data manipulation menu in the tools palette.

See attached picture
0 Kudos
Message 2 of 7
(3,419 Views)
If the checksum is a single byte, you can use build array to get an array of 1 byte, then byte-array-to-string to get the desired string.

Les.Hammer@CompleteTest.com
Message 3 of 7
(3,419 Views)
That's pretty clever.
0 Kudos
Message 4 of 7
(3,419 Views)
I think this is the right solution but I can't figure out how to set the variable type on the typecast vi (I'm a new user). How did you generate the "Char" variable in your example? I'm using version 6.1 if that makes any difference. Thanks for your response!
0 Kudos
Message 5 of 7
(3,419 Views)
The string at the top with the word "char" in it is not the key to his solution. Any string on top will work, the type cast is just using the data type (string). The key to John's solution is setting the data type of the input correctly. The data type of the value being cast in John's solution is U8, which matches the size of two hex digits (i.e. 42 hex or 66 decimal), hence the code knows to convert one numeric byte to a one character string. If you were converting a 4 hex digit number (e.g. 0042 hex), you would need to ensure the data type of the input was set to U16.
0 Kudos
Message 6 of 7
(3,419 Views)
Ah! The light goes on! Thank you for your help.
0 Kudos
Message 7 of 7
(3,419 Views)