LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use LStrHandleArray in CVI

Hello,

 

I have compiled LabVIEW drivers as a dll and am calling them from LabWindows CVI. One of my drivers has an arrray of strings. Each element will contain a 16 bit Hex number (0 - FF). I need to know how to define the LStrHandleArray in CVI, and also how to set it equal to a defualt value which will be passed to the LabVIEW driver. I also have another driver that is returning an array of the same format. Please keep in mind my C experience is minimal.

 

This code will build:

 

LStrHandleArray  TXBuffer[10] = {0,0,0,0,0,0,0,0,0,0};

 

This code will not build:

 

LStrHandleArray  TXBuffer[10] = {CA,0,0,0,0,0,0,0,0,0};

 

I get a build error: " 28, 34   Undeclared identifier 'CA'."

0 Kudos
Message 1 of 2
(2,295 Views)

You might want to post this in the CVI forum, you are more likely to get useful advice about C there. That said, you need to understand what you're trying to do. It might help to upload the LabIEW code to show the functions you need to call.

 

Only 8 bits (a byte or a char) are needed to store hex 00-FF. Why do you need to store 16-bit values?

 

An array of strings is not the same as an array of characters. Are you trying to store 10 characters, or 10 strings?

 

If you only need to store 10 characters, it will be much easier to use a standard C array than an array of LStrHandle, although you will have to modify the LabVIEW code.

 

There are several possible problems with the LStrHandleArray initializer, depending on how the data type LStrHandleArray is defined (extcode.h defines LStrHandle, but not LStrHandleArray). I'm going to guess that you intended LStrHandle, and not LStrHandleArray since the [] defines it as an array. You would then have an array of pointers to memory locations, so assigning constant values to them doesn't make any sense (however, it is allowed by C syntax, and 0 is acceptable as a null pointer). Assigning an initial value to an LStrHandle is much more complicated because the correct way to do it is to allocate the memory with a call to the LabVIEW memory manager, then copy the constant string into it.

 

To use the hex value CA as a numeric constant, you would instead write 0xCA. Or, as a character constant, you could use '\0xCA' (in single quotes). However, assigning the value 0xCA to a handle is meaningless and likely to cause crashes, because it assigns a pointer to the memory at address 0xCA rather than pointing at a memory location that contains that value.

 

I apologize if the above isn't clear given your level of C experience.

 

Suggestion: it appears that you just want to pass an array of 10 bytes from CVI to a LabVIEW application. Do this by defining an array of 10 characters and pass that to LabVIEW as an array of bytes, which you can convert to a string in the LabVIEW code if necessary.

char TXBuffer[10] = {'\0xCA', 0, 0, 0, 0, 0, 0, 0, 0, 0};

0 Kudos
Message 2 of 2
(2,269 Views)