LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Are control refnums persistent?

I have a VI which comes up ("Show Front panel when called" is set).
Part of its initialization includes gathering a bunch of nested control refnums (arrays of clusters within clusters, etc.), so that I can do some manipulation of the on-screen appearance (when comparing two files, I highlight the background color of items in file B (shown on one tab) which are DIFFERENT from file A (shown on another tab).

The collection of these refnums takes about 500 mSec, which delays the responsiveness of the VI to the user (it's not the only delay thing, but I'm working on all of them).

So the question comes up: Do I need to collect the refnums every time? Or could I collect them once, and stash them somewhere, and use them from the stash the next time it comes up?

In other words, If I get a refnum to a particular item on a particular panel, and that panel closes, then opens again later, is the refnum still valid?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 7
(3,064 Views)
AFAIK,

(and that's not very far sometimes) it's only true when the reference is within the same VI as the object it's referring to.  If you want to reference across VIs, I think you need to gather them each time.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 2 of 7
(3,060 Views)
it's only true when the reference is within the same VI as the object it's referring to. If you want to reference across VIs, I think you need to gather them each time.


Well, I know that's not quite true, as you can pass them via connector or global variable, and have one VI work on another VI's controls.


My question is, if the VI is closed, then opened up AGAIN, are the refnums the same? I understand they will not be valid while the thing is closed.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 7
(3,053 Views)
"Well, I know that's not quite true, as you can pass them via connector or global variable, and have one VI work on another VI's controls."

That's quite something else than what I am trying to say.  References (constants) located within a VI linked to an object within the same VI will always be valid.  A reference from an object outside the current VI will NOT be valid upon re-loading (unless it's updated of course which is where your variable passing comes in).

If you want to work on another VIs controls or indicators, you need to pass the references each time the VI is opened at least.  What you can't do, however, is expect to be able to drop a reference constant on a block diagram which refers to a control in a different VI and have it work after closing and opening again (if it's even possible in the first place).  I understood you were talking about absolute values (not parameters being passed via connector pane).

In other words, you can't treat cross-VI references as constants as each closing or opening can invalidate the reference.  Passing references from one VI to another is of course fine (as long as you're passing valid references of course).

To answer your new question, I don't think the refnums are the same, no.


Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 7
(3,050 Views)
References (constants) located within a VI linked to an object within the same VI will always be valid.


--- Right. Since the code that uses them is in the same scope, all is well.



What you can't do, however, is expect to be able to drop a reference constant on a block diagram which refers to a control in a different VI and have it work after closing and opening again (if it's even possible in the first place).


--- Well, sure. If you copy a reference constant from diagram 1, and paste it into diagram 2, you get a new control on front panel 2, as well. That's nothing to do with my question.



A reference from an object outside the current VI will NOT be valid upon re-loading


Well, that's the heart of my question. Since the refnum was obtained whil the VI's FP was open, it's valid at least until the FP is closed. Obviously it can't be used while the FP is closed. When the FP is opened again, there is a refnum to this same control. Is it the same refnum as before?


Your answer is "no". I ran a test (which perhaps I should have done earlier) which says "yes". If I close the main VI, the numbers are different the next time I run it, but as long as the main VI is open, the refnums for the subVI's controls remain the same, no matter how many times I open and close it. This is true on LV 7.0 (win2k) and 7.1 (OS X).


Whether it's guaranteed behavior, or just happenstance, is debatable, but in fact it does work. I'm debating whether I can rely on it.



If you see holes in my thinking, let's hear them.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 7
(3,040 Views)
I said previously "you can't treat cross-VI references as constants as each closing or opening can invalidate the reference".  I can understand how this may be misunderstood.  When I wrote "close" I meant unloading from memory, not just closing the front panel.  AFAIK, the VI won't be unloaded just because its FP is closed and the calling VI is still loaded (same calling chain).

If is is unloaded, then the list of VIs in memory must change when you close the VI in question.  Try listing the VIs in memory in a loop while opening and closing the VI in question.  If it doesn't disappear from the list, it isn't being really "closed", so the discussion is a different one.

Additionally, the ability to drop a reference constant produces the same behaviour in LV 6.1, but not knowing if this is the same in LV above 6.1 I mentioned it anyway.  Sorry for wasting your time with that.. 😮

I still maintain that if the VI is really closed (i.e. unloaded from memory, not just a closed front panel) then upon reloading (even if the calling VI remains loaded in the mean time) the references will have changed.  According to my knowledge of LV, this is only really possible when launching via VI server where parallel running VIs can be properly closed and unloaded while the main VI runs continually.  So maybe that's where our discussion is falling apart.

Recap:

  • If you unload and re-load a VI it's references will change (You have confirmed this in your last mail).
  • If a VI is loaded within a calling chain and the front panel is closed, the VI is NOT unloaded and thus the references don't change (can you verify this? - list of VIs in memory).
  • In your example (closing and opening a front panel) the references should remain constant as the VI isn't being unloaded from memory.  I don't think it's "happenstance" at all, it's the way LV does things.  I would say you can rely on it.

Check if closing the front panel really unloads the VI.  This is the key to your question.  It seems I was answering a different question than the one you wanted answering.

Hope this helps

Shane.

PS as I only have LV 6.1, I can't test your code, sorry.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 6 of 7
(3,027 Views)
AFAIK, the VI won't be unloaded just because its FP is closed and the calling VI is still loaded (same calling chain).
--- This I know to be correct. If you look at how CINs operate, you'll see there is a LOAD and UNLOAD operation, performed on them, when the parent VI is LOADed and UNLOADed. That is distinct from OPEN and CLOSE.



I still maintain that if the VI is really closed (i.e. unloaded from memory, not just a closed front panel) then upon reloading (even if the calling VI remains loaded in the mean time) the references will have changed.
Well, yes, but like you say, that's only possible when calling the thing indirectly, via the VI Server. That's not my case, as I hinted at (but didn't directly say) by the "Open Front Panel when Called" statement. That only works with direct calls, not VI SERVER calls.


If you unload and re-load a VI it's references will change.
--- True, but not pertinent to my situation.


If a VI is loaded within a calling chain and the front panel is closed, the VI is NOT unloaded and thus the references don't change (can you verify this? - list of VIs in memory).
--- This is the heart of it - I knew the VI would not be unloaded (things like uninitalized shift regs and local variables would lose their values if it was). But I didn't know if references would be unchanged or not. If references were simply memory pointers or handles, then they could be changed, simply by using memory in between the first opening and the second. If the controls were truly objects (in the C++ sense), then they could be destroyed upon closing, and re-created upon opening. In that case they might change. If the control ref was some sort of code that described "the third component of the fourth cluster on the panel", then it wouldn't ever change.


In your example (closing and opening a front panel) the references should remain constant as the VI isn't being unloaded from memory.
--- This is indeed what I see.


Now that I think about it, this is the way it has to work. The "local variable" thought above provides a clue. The UI element (HWND on Windows) is probably destroyed on closing and re-created on re-opening. But a control is known to retain its data value if the front panel is closed, and re-opened. This means that the control is more than just the UI element, it's a LabVIEW element. The control reference is a pointer/handle to the LabVIEW element, which exists as long as the FP is loaded. Part of the LabVIEW element is a connection to the UI element, but that's immaterial.



Check if closing the front panel really unloads the VI.
--- This is already known: it unloads the VI ONLY if there are no references to it from VIs still in memory. This is why the SAVE CHANGES? stuff works the way it does - when you close the FP of a changed subVI, you get a message about saving the changes. If you choose not to, the front panel is CLOSED, but the changes are still in memory. If you close the last calling parent, you get ANOTHER warning about the subVI, because this time it's about to be UNLOADed. Last chance.



Thanks for your discussion.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 7
(3,010 Views)