LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[QUES] moveblock problem?

Solved!
Go to solution

I have a LabVIEW and C DLL combination of code.

 

The C DLL takes a large array of UINT16 values and decodes it into a meaning form.  The resultant data is stored in a static array structure inside the DLL.  The Structure consists of integers, floats, strings and arrays.

 

The DLL also has a function to return the elements of the structure.  Each structural element is returned as a separate parameter entry.  Some of these are arrays for example:

  

void GetMyData (..., unsigned char*      myArray[], ...);

 

I know how big "myArray" is.

 

In LabVIEW I have a "Call Library Function Node" for the above function.  For the arrays I have used "Numeric, Signed 32-bit Integer, Pointer to Value".  The "Address" that is returned from this call I pass to "LabVIEW:MoveBlock" call as defined in the examples on this forum.  i.e. Pre-allocating the array the correct size and then copying the bytes into it from the "Address".

 

If I just run my VI LabVIEW crashes.  If I step through it however (stepping over the DLL Library Function Node calls) then I get the data out from the DLL as expected.  However if I then close LabVIEW it crashes.

  

Is MoveBlock safe to use?  Is there an alternative way to get arrays of data from a DLL?

 

Thanks.

 

Christopher Povey

Principle Test Systems Engineer for BAE Systems.
0 Kudos
Message 1 of 5
(3,191 Views)

Can you post your code, and a link to the documentation for your DLL function?  Why are you trying to use MoveBlock?  If the GetMyData function returns array parameters, then configure call library node to return an array directly.

Message 2 of 5
(3,182 Views)

I cannot post the code as it is company restricted.  😞

 

This morning I have written a test harness in C for the DLL functions I am using.  As a result I have modified the header as follows:

 

void GetMyData (..., unsigned char      myArray[], ...);  

 

i.e I have removed the pointer.

 

I have also modified my LabVIEW as follows:

 

The "Call Library Function Node" for the above function for the array I have used "Array, Unsigned 8-bit Integer, Array Data Pointer”.

 

However running this crashes LabVIEW!!!  What should “Call Library Function Node” parameter setting be for “unsigned char      myArray[]”?

 

----------------------

 

In addition the function also returns strings.  I have declared these as "String, C String Pointer" in the "Call Library Function Node".  The C header is as follows:

 

void GetMyData (..., char aString []...);  

 

I have initialised the inputs to the "Call Library Function Node" with the "Empty String Constant".  Is this correct or should I pass it an initialised array of characters of the correct size?

 

Thanks.

Christopher Povey

Principle Test Systems Engineer for BAE Systems.
0 Kudos
Message 3 of 5
(3,157 Views)
Solution
Accepted by topic author ChristopherPovey

It sounds like you have the Call Library Node set up properly, but are you initializing the array you're passing into it?  You need either to initialize an array of sufficient size, or set the minimum array size in the Call Library Node so that LabVIEW can do it for you.  If you pass a too-short array you'll probably get a crash since your DLL will attempt to write to that memory location and overwrite something else.

 

You should similarly initialize the string that you pass to your DLL if you expect the DLL to fill it in.

 

You may also find it helpful to set the Call Library Node error checking level to maximum for debugging purposes; this can help catch memory problems.

Message 4 of 5
(3,141 Views)

Turns out it was the strings causing the problems.  I had passed in empty strings to the Call Library Nodes that passed out strings.  I swapped all these out for I8 arrays of the correct size and Type Cast them back into strings and the crashing has stopped.

 

Smiley Happy

 

Thanks.

Christopher Povey

Principle Test Systems Engineer for BAE Systems.
0 Kudos
Message 5 of 5
(3,112 Views)