LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass a LV6.0.2 error struct into CVI?

I want to create DLL's from some CVI code and use them in Labviews. I would also like to pass into that DLL a LV error "cluster" and write CVI errors into that structure to be passed back to Labview.

Consider the Labview error structure..
#pragma pack(1)
typedef struct
{
LVBoolean status;
int32 code;
LStrHandle source;
} Error;
#pragma pack()

I can write to the boolean and the int32 with no problems. However, when I write to the LStrHandle Labview crashes.

So I can only sonclude that I don't understand what the LStrHandle is or how to write data into it. I have tried memcpy & strcpy, with casts but to no avail. Has anyone had success with this?

Kindest,
Warren
0 Kudos
Message 1 of 8
(2,961 Views)
Humm...the reason this is happening is that labview passes handles to the string and you need labview mem manager functions to resize that handle. Since you are not doing that, its crashing labview. You need to use "DSSetHandleSize" function to resize the string handle. here is sample code

DSSetHandleSize(Error->source,sizeof(int)+5*sizeof(uChar));
(*(errorin->source))->cnt=5;
StrCpy((*(errorin->source))->str,"hello");

you need to have extcode.h and labview.lib for this.
Hope this helps, For more details description consult the Code interface reference manual.

A Rafiq
National Instruments
0 Kudos
Message 2 of 8
(2,961 Views)
sorry i had some typos in the sample code. if i use your struct then

DSSetHandleSize(Error->source,sizeof(int)+5*sizeof(uChar));
(*(Error->source))->cnt=5;
StrCpy((*(Error->source))->str,"hello");
0 Kudos
Message 3 of 8
(2,961 Views)
Hi !

And thanks for helping me figure out the Labview string type struct. One problem still persists. Even though I can now write the error string into the Labview error struct..When I use the cluster tools to decompose the cluster (inside Labview of course) I can breakout everything BUT the string "source". Labview complains that it can't read the memory, and aborts.

I was under the impression that I didn't have to do anything special with memory inside a CIN (or in this case) a DLL. I thought if you declared a struct (or cluster) inside Labview, that memory was created, locked and passed to the DLL. Once inside the DLL you could write to that memory space and expect it to be passed out without problems.

If I comment out the code that writes to the "
source" string I can unbundle the error cluster with no crashes. Which leads me to believe that something weird is happening with that string.

Here's something else. If you write a DLL that just opens a COM port and then closes it. And run that DLL inside Labview with the performance monitor running, the execution time of that DLL will grow larger and larger each time you run it. So now..I'm wondering if something weird is happening at the driver level as well (This is on a WIN2K platform so far).

I'll attach my files.

Kindest,
Warren
0 Kudos
Message 4 of 8
(2,961 Views)
I've no time to look into this and may be completely off track here, but is
the string empty when you pass it? If so it has no size and no memory. Try
making sure the string is pre-initialised to as many characters as you need
before passing it into the CIN/DLL call.

wxfield wrote in message
news:5065000000050000008A330000-993342863000@exchange.ni.com...
> Hi !
>
> And thanks for helping me figure out the Labview string type struct.
> One problem still persists. Even though I can now write the error
> string into the Labview error struct..When I use the cluster tools to
> decompose the cluster (inside Labview of course) I can breakout
> everything BUT the string "source". Labview complains that it can't
> read the memory, and aborts.
0 Kudos
Message 5 of 8
(2,961 Views)
Hi Craig. Thanks for responding. The LStrHandle is a Labview struct, and it is "pre-inited" for 256 bytes. So it isn't an init problem. The memory goes in clean, gets populated with chars, then dies once inside Labview.

-Warren
0 Kudos
Message 6 of 8
(2,961 Views)
The following is how I do it in C++, and I think it may help you. I haven't test this code, so I can't guarantee it works (You may need to play a little bit with it)

Try to use the functions NumericArrayResize(), LStrLen() and MoveBlock(), defined in LabVIEW. You may need to include the file "extcode.h", which should be included in the cintools directory of LabVIEW. Then:

// resize errOut->source LV string to accomodate GetRS232ErrorString(result)
NumericArrayResize(uB, 1L,(UHandle *)&(errOut->source), strlen(GetRS232ErrorString(result)));

// update the length of the errOut->source LV string
LStrLen(*(errOut->source))=strlen(GetRS232ErrorString(result));

// move strlen(GetRS232ErrorString(result)) bytes
// from GetRS232ErrorString(result) to errOut->source LV s
tring
MoveBlock(GetRS232ErrorString(result), LStrBuf(*(errOut->source)), strlen(GetRS232ErrorString(result)));

I hope this help.

Best regards;
Vargas
www.vartortech.com
Message 7 of 8
(2,961 Views)
Bingo !

That's just what the Doctor ordered. Works great..no memory problems. Thanks for pointing out extcode.h

-Warren
0 Kudos
Message 8 of 8
(2,961 Views)