LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW thinks my hex string is ASCII

Solved!
Go to solution

Hello, I've got a problem with the "Number to Hexadecimal string" function in LV 2019. I'm controlling a stepper motor by sending it a hex string. The last two characters of the string are twice the PWM command in hex. For example, if I want to send the motor a 50% PWM command, the last two digits of the hex string should be "64" ( dec2hex(2*50)=64 ). As you can see from the screenshot, "64" is what's travelling through the wire after the number to hex function. However, when I concatenate the strings to form the entire string to send to the motor, LV thinks "64" is ASCII so it converts the 6 and the 4 to hex, which are 36 and 34, respectively (as you can see from the front diagram indicator). I've tried a lot of things to fix this, (ASCII to hex converter, scan value, format value, etc) but no luck. It works fine when I replace all that with just a hex string constant where I type in "64", so I am confused why LabVIEW is concatenating it as ASCII normally. Does anyone know what's going on here?hexstrings.png

0 Kudos
Message 1 of 5
(4,018 Views)
Solution
Accepted by topic author Akaf24

Of course.  Hex strings (or any string for that matter) are always ASCII (or Unicode).

Do you need the last byte of the string to have a character whose value is 64hex?

If so, convert the double to a U8, then cast it to a string (see attachment).

"If you weren't supposed to push it, it wouldn't be a button."
Message 2 of 5
(4,004 Views)
Solution
Accepted by topic author Akaf24

So I'm confused, do you need to send the value "64" as a string to your device, or do you need to send it as hex to your device? Right now, you're sending it as a text string. Whether you consider it to be the string "64" or the hex values 0x36 0x34, the actual information going to the device is the same. Note that the display mode of indicators and constants doesn't change the underlying data, just the display.

 

If you want to send 0x64 (which is "d" according to http://www.asciitable.com/), just use Type Cast on a U8 (you can't use a Double here, so convert it to a U8 before sending).

 

Conversion.png

Message 3 of 5
(3,999 Views)

Thank you Paul and Bert. I need to send "64" as a string, so that's an excellent idea that works. 

0 Kudos
Message 4 of 5
(3,985 Views)

@Akaf24 wrote:

Thank you Paul and Bert. I need to send "64" as a string, so that's an excellent idea that works. 


If you really needed to send "64" as a string, then your original code would have worked.

By converting 64 to U8 and casting it to a string, you are sending 64 as binary.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 5
(3,954 Views)