LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview crashing when calling labview-built dll

Hello

I need some help with regard to calling a LabVIEW-built DLL in LabVIEW.

I have created a vi in LabVIEW. I made the DLL for this vi. I called this VI as a re-entrant in another vi.

This vi(calling DLL) has been working fine till yesterday. Since yesterday, it started crashing LV.

I need some help in this regard.

I am attaching the screenshots of the Application Builder configuration window, the B.D of the vi using DLL and that of the configuration window which pops up when i call the DLL.

I made a vi which performs FRA. I built its DLL.
I have around 10 inputs. I output 3 one-dimensional arrays, and a string from the DLL.
When i build the DLL, the builder defines the outputs 'gain', 'phase' and 'frequency' as arrays of 8-byte double.
When i call this DLL in my vi, the configuration window sets them as 'numeric' outputs.

Why does this happen? What is the solution to this?

When i try to set them as 'array' in this configuration window, i get a warning that i am trying to change the data types which do not match with the data type found in the DLL.

Is this the problem with my code or with the Application Builder?

Now, after i change the 3 output datatypes to Arrays, and set their minimum length(i assumed that this value means the size of the array ), the vi runs and crashes LV. I am nto sure when it crashes, why it crashes. It runs fine at one time. It crashes at another time. I am nto sure if these arrays are teh reason why LV crashes. If that is the erason, why is it happening only sicne yesterday and not earlier?

Also, the string output can is a maximum of 412 characters. Will this play a role in LV crashing?

Kindly someone help me!!

I have checked multiple times for the data types of the otehr inputs and ouputs. My only doubt is on these arrays.

I have posted this message here, already. Kindly continue the thread there.

Download All
0 Kudos
Message 1 of 14
(2,692 Views)
LabVIEW version used will be helpfull. I myself also have some trouble with crashes when calling a LabVIEW built DLL. I will dig into this first thing monday morning with my collegue. Maybe we find something in our case that could explain your problem.
Regards,
André (CLA, CLED)
0 Kudos
Message 2 of 14
(2,682 Views)
Thank you sir!

I am using LV 8.2.1
0 Kudos
Message 3 of 14
(2,658 Views)


I made a vi which performs FRA. I built its DLL.
I have around 10 inputs. I output 3 one-dimensional arrays, and a string from the DLL.
When i build the DLL, the builder defines the outputs 'gain', 'phase' and 'frequency' as arrays of 8-byte double.
When i call this DLL in my vi, the configuration window sets them as 'numeric' outputs.



The problem is actually here but not as you describe it. The DLL node seems to be configured right since you wire an array of doubles to these three parameters. The problme is about memory allocation.

Having the parameter configured as Array data pointer means it is a simple C data pointer and not an LabIVEW array handle. This is good if you ever intend to have this DLL called by some other program than LabVIEW since it is rather hard to make other applications deal right with LabVIEW handles.

However for C data pointers the caller is responsible to allocate the memory for these parameters. This means that you can't just wire an empty array constant to the input side of these parameters in the Call Library since this points to a memory aray of 0 bytes length. The function then will attempt to write into that memory area and overwrite memory it is not supposed to overwrite.

Replace that array constant with an Array Initialize node that creates an array of sufficient length.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 14
(2,644 Views)
Thank you very much sir!

I shall try it and get back!!
0 Kudos
Message 5 of 14
(2,638 Views)
Sir,

I tried using a initialize array function in place of array constant, but in vain.

LV is still crashing.

Also, what is the difference in using an 'initailize' function and an 'array constant'? I am finally getting a 1-D array.

The other doubt i had was : why does the 'call library function node' configuration window detect the outputs 'gain','phase' and 'frequency' as numerics and not arrays?


0 Kudos
Message 6 of 14
(2,636 Views)


@MScap wrote:
Sir,

I tried using a initialize array function in place of array constant, but in vain.

LV is still crashing.

Also, what is the difference in using an 'initailize' function and an 'array constant'? I am finally getting a 1-D array.

The other doubt i had was : why does the 'call library function node' configuration window detect the outputs 'gain','phase' and 'frequency' as numerics and not arrays?


You do need to make sure to initialize the arrays to the length indicated by your len1, len2, len3 parameters that you also pass to the DLL. An array constant contains only as much elements as you explicitedly enter into it (usually 0, which means it points to a memory area of 0 bytes length). Initialize Array will create a memory block that is large enough to contain the number of elements you specify as length parameter.

In C a parameter by reference or an array of that parameter type are syntactically the same. I think the type library LabVIEW adds to the DLL to describe the parameter and also uses on import into the Call Library Node if available, should be able to distinguish between that but I'm not sure.

Rolf Kalbermatter


Message Edited by rolfk on 05-26-2008 09:11 AM
Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 14
(2,634 Views)
Thank you sir!
I got the point.

I made sure that the no.of elements is same as that of len1,len2 and len3. All these three values are same as the input 'no.of steps'. So, I connected them all together.

Now, it runs fine when i pass all the inputs.
I have a validation process in my code, which gives an 'error message'(as a string) when any input is not valid ( usually out of data range).

LV is crashing, now, only if there are any empty inputs passed to it.
When i run the vi without passing any values to the controls, its crashing.

Also, its crashing when i enter few inputs and leave others empty.

Actually, when no data is passed to the vi, the vi must return a string (of max 412 characters) that the values are not valid.

I am gettign this string as the output and then LV is crashing. I am not able to find out the reason.

Kindly  look into this!
0 Kudos
Message 8 of 14
(2,628 Views)


@MScap wrote:
Thank you sir!
I got the point.

I made sure that the no.of elements is same as that of len1,len2 and len3. All these three values are same as the input 'no.of steps'. So, I connected them all together.

Now, it runs fine when i pass all the inputs.
I have a validation process in my code, which gives an 'error message'(as a string) when any input is not valid ( usually out of data range).

LV is crashing, now, only if there are any empty inputs passed to it.
When i run the vi without passing any values to the controls, its crashing.

Also, its crashing when i enter few inputs and leave others empty.

Actually, when no data is passed to the vi, the vi must return a string (of max 412 characters) that the values are not valid.

I am gettign this string as the output and then LV is crashing. I am not able to find out the reason.

Kindly  look into this!


Same issue probably. When you pass a C data pointer (string or array) you need to make sure to allocate the necessary memory for that parameter in the caller (here your LabVIEW diagram). The DLL has no way of allocating that memory and returning it to the caller.

For strings I usually do this by intializing an array of u8 of the necessary size and then using a Byte Array To String function convert it into a string before passing it to the Call Library Node. In LabVIEW 8.2 and higher you also can configure in the Call Library Node a minimum size for array and string parameters. LabVIEW will then make sure to allocate the necessary memory before passing the pointer to the DLL. You can either use an explicit number to allocate a fixed size buffer for statically sized parameters or the name of a different parameter that indicates the number of data elements the array should be resized to.

Personally since I still work sometimes in pre 8.2 LabVIEW versions I prefer to do the explicit allocation with Initialize Array myself.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 14
(2,623 Views)
Sir,

I have made sure that the strings are defined with a minimum length. The array size is connected to an other input(no of steps).


As i said earlier, the vi runs fine, without crashing, when all the input parameters are passed. If i do not pass even one parameter, i should get an error message (of max 412 characters). I get this error message and then LV crashes.



0 Kudos
Message 10 of 14
(2,605 Views)