LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Node: internal LV data operations

Hello!

I want to refresh the front panel control (array of clusters) after my custom DLL call. But I dont want to pass the Pointer to the Array Handle every time into the DLL-functions. I share the pointer to array handle in the DLL as a global variable once. Other DLL-function calls presents the operations under this handle.

So, the question is: if it is possible to force the Block diagram to refresh data without direct recording into the array control?

0 Kudos
Message 1 of 6
(2,762 Views)

I'm a bit confused.  Why would you want to?

 

You can make your DLL output the required components and wire them into your array.

 

But, what would you gain here?

0 Kudos
Message 2 of 6
(2,735 Views)

Not really! The LabVIEW data is dynamic.

 

There is absolutely no guarantee that the handle that you pass into the Call Library Node will stay the same after the Call Library Node call returned control to the diagram. LabVIEW reserves the right to (re)allocate, deallocate, resize and change data handles at any time and only gives guarantees that handles that you pass into a Call Library Node will never change as long as that Call Library Node doesn't return. Expecting anything else is at best a Russian roulette play that will at some point cause you to shoot your feet, and at worst cause real causalities, depending where your application is used.

Rolf Kalbermatter
My Blog
Message 3 of 6
(2,731 Views)

Thank you for your reply! 

It comes out, if I allocate memory for handle explicitly, inside a DLL (using Memory Manager functions)  - LabVIEW can also manage this memory and operate with handles? 

0 Kudos
Message 4 of 6
(2,670 Views)

Thanks for your reply! 

 

My situation is:

1) I have main VI and SubVI

2) In main VI I have a global array of clusters

3) I pass Reference to this global Array into the subVI

4) In SubVI Call Library function node calls the DLL-function, The DLL-function recises the Array and strores the pointer to the hanlde.

I want to change the array content inside the DLL, but I don’t want to pass every time the array handle into the Call Library Function node and then stores it again into global array Reference 

0 Kudos
Message 5 of 6
(2,666 Views)

LabVIEW data is ALWAYS dataflow controlled. What you attempt to do is not dataflow and therefore will not work.

 

When you want to have a memory pool that is controlled by you you have to allocate it, manage it and deallocate it.

 

When you want to use a LabVIEW data handle you can ONLY manipulate it during the call to your Call Library Node function. After your function returned, LabVIEW takes over control of that handle again and reserves every right under the sun to resize, relocate and/or deallocate this handle at its own will. So storing a pointer to that handle and hoping to read and/or write it later on after your function has returned control to the LabVIEW diagram is simply creating a crash to happen sooner or later.

 

As another contributor on this forum keeps saying: Think dataflow!

Forgot those text programming techniques of storing some (static) global somewhere that is accessed all over the place by various routines, possibly even in different code modules, and creates all kinds of trouble requiring extra access control through mutexes or other such things once you happen to start up at least one other thread that also happens to call those functions. LabVIEW has 5 execution systems with each containing by default 8 threads that all can be active in parallel and a DLL trying to tweak its own memory management paradigma in there is simply creating a chaos. You either follow LabVIEW data management rules or create your own memory space that you then have to manage yourself from start to end. Mix and match between the two is not advisable and creates all kind of trouble that make your VIs very difficult to use and totally counter-intuitive to what a normal LabVIEW programmer is used to. Even if you think you know exactly how you have to call your library and wire the wires in the diagram to make sure the handles stay artificially in place until your DLL is truely done with them. I can almost guarantee you that even you will somehow create trouble if you revisit the same application a half year from now to make this last simple feature addition that makes it complete.

 

A seemingly small change will suddenly cause the DLL to try to access this pointer after your LabVIEW diagram has already ceased to run this wire through the whole state machine or whatever you have, to make sure the handle stays alive, and LabVIEW consequently deallocated or resized it (and resizing can mean that a handle is relocated to a different memory space). In addition even if the handle is still valid you would still have to add extra protection to it to make sure that you are not modifying it asynchronously in the DLL while your LabVIEW diagram somewhere tries to access it, to prevent inconsistent data, or in the case of a resizing on either side even an invalid handle.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(2,660 Views)