LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Where is a VI-Ref valid?

Hi,

I've got a kind of mystic problem:
A main UI process starts some child processes from a template.
To do this, it opens a Ref to the vit (instantiates it), loads some data (including 'its' VI-Ref) into it and starts it as a new process (run VI-method).
This seemed to work, when I instantiated a whole bunch of those processes and started them later, whenever a new process was needed. I have changed this behaviour to instantiate _and_ start 'em when needed, because this way main can run continuously.

Now with this change, the VI Ref that is sent to the newly instantiated process is invalid, causing error -1026 when I try to do anything with it (for example opening the FP).
Any clue?

Of course I can obtain a Ref to the new instance inside it, but than there is nor 'connection' from main to the new instance?!!!

Confused ;-()
0 Kudos
Message 1 of 3
(2,812 Views)
A VI Ref is valid as long as it hasn't been Closed (either explicitly or implicitly). They have Global scope inside the LV execution engine.

Do note that creating eight copies of a VI Ref is not the same as Opening the same ref eight times. When you create eight copies, it only needs to be closed once to make the other seven invalid. When you Open a ref multiple times, it must be closed the same number of times.

Good Luck.
0 Kudos
Message 2 of 3
(2,796 Views)


@LuI wrote:
Hi,

I've got a kind of mystic problem:
A main UI process starts some child processes from a template.
To do this, it opens a Ref to the vit (instantiates it), loads some data (including 'its' VI-Ref) into it and starts it as a new process (run VI-method).
This seemed to work, when I instantiated a whole bunch of those processes and started them later, whenever a new process was needed. I have changed this behaviour to instantiate _and_ start 'em when needed, because this way main can run continuously.

Now with this change, the VI Ref that is sent to the newly instantiated process is invalid, causing error -1026 when I try to do anything with it (for example opening the FP).
Any clue?

Of course I can obtain a Ref to the new instance inside it, but than there is nor 'connection' from main to the new instance?!!!

Confused ;-()




A VI reference is closed automatically by LabVIEW as soon as the top level VI of the hierarchy which created (opened) that refnum gets idle. This means if you have two independant VIs A and B, with A opening a VI refnum and doing some stuff on it and then writing the refnum to a global and B accessing that global to use the VI refnum, B will see an invalid refnum as soon as A stops executing (goes idle).
In order to avoid that you would need to either make A also part of the hierarchy of B by including it as some subVI or keep A running until B is also finished with the refnum.

That said, sharing refnums over globals is in almost all cases a bad idea anyhow. Better would be to open a new VI reference in the second hierarchy of VI B before VI A goes idle.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 3
(2,784 Views)