NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass Hex String to DLL

Hello there,

I have a Visual Studio compiled DLL that expects the following:

CHAR command[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};

How do I express this as a TS Local? Can I express this a String as "0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06" or do I need to segment and convert each char in the string - this would seem laborious.

And yes... I'm rusty!

-Chroma
0 Kudos
Message 1 of 7
(3,972 Views)

You can set the value of the local string to be:

"\xAA\xBB\xCC\xDD\xEE\xFF\x00\x01\x02\x03\x04\x05\x06"

Below I have pasted the Description for string constants supplied by the expression browser...

Enclose string constants in quotes.
You can use the following escape sequences in string constants:
 \\ Backslash
 \n Line Feed
 \r Carriage Return
 \xNN Hexadecimal character code
 \NN LabVIEW style hexadecimal character code
 \" Quote
 \t Tab

0 Kudos
Message 2 of 7
(3,947 Views)
Many thanks! I'll give this a try.
0 Kudos
Message 3 of 7
(3,940 Views)
I tried the above but it does not correctly pass the values to my DLL. The suggested method exports the "\", backslash character, the lower case "x" and then 0x41 for "A" repeated. To illustrate more clearly:

Hex                     ASCII

5c 78 41 41        \xAA

What I require is the following:

Hex                     ASCII

AA                       (usually unprintable or extended char set - I've confirmed this looking at Visual Studio memory window and in LabVIEW (for the conversion))

Is their a TestStand  function that  can process my entire char array or would I have to do the correct operation per char?

Can anyone point me in the right direction here, before I loose all my marbles?
 
Regards,
Chroma
0 Kudos
Message 4 of 7
(3,882 Views)

Chroma,

I gave this a try again and noticed that if you define the string as a local (as I suggested) it doesn't account for the escape characters as I thought.

It only accepts escape characters in the statement step or other expressions.

If you create a statement step and set the statement to be:

Locals.string = "\xAA\xBB\xCC\xDD\xEE\xFF\x00\x01\x02\x03\x04\x05\x06"

The string will equal the hex values.  So, the solution I origionaly proposed is not exactly correct and adding an extra step to format it is not as clean as hoped.

 

Another option I just came up with is to convert an array of numbers to a string.  What I did was to set a statement step that converts one character at a time and then loop it with the loop options tab.  I'll attach it...

 

Message 5 of 7
(3,873 Views)
Thanks for the reply! I tried your original suggestion, with the local being set in a statement. On calling my DLL via Visual Studio, the following buffer was passed (see attached .jpg):

IN
Locals.string = "\xAA\xBB\xCC\xDD\xEE\xFF\x00\x01\x02\x03\x04\x05\x06"
                                                                  

OUT (Visual Studio DLL source)
aa bb cc dd ee ff 5c 78 30 31 02 03 04 05 06

It's interesting to note that the "\" and "x" chars have been added in and the "\x00" and "\x01" have not been correctly converted. I tried the different command string, which is more representative of our application (see attached .jpg):

IN
Locals.string2 = "\x03\x00\x00\x00\x00\x00\x05\x00\x05\x03\x00\x01\x00"

OUT (Visual Studio DLL source)

03 5c 78 30 30 5c 78 30 30 5c 78 30 35 5c 78 30 35 03 5c 78 30 31 00


It looks like this approach perhaps(?) highlights an issue with TS, when a "\x00" is encountered. On another note, I think the
array of numbers to a string example is useful but thinking this through, I believe we'll be using the Property Loader to bring in the locals as strings.

Any other thoughts?

Regards,
-Chroma



Download All
0 Kudos
Message 6 of 7
(3,864 Views)

Chroma,

I did a search and it looks like Teststand doesn't like NULL characters in a string.  See this article...

http://digital.ni.com/public.nsf/allkb/0B1D4EFE0D2B529D86256BC100737142

Message 7 of 7
(3,868 Views)