From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate a reference?

I have a VI which can be used as a standalone VI or a subVI.  I'd like to determine which instance it is being used in by determining if there is a reference wire into the control or not.  So if ref empty, use as a subVI, create a ref, run code , close ref, then stop.  If ref is present, use existing ref, run, don't close ref and pass back to main VI, stop.

 

Starting from scratch it is easy,  the ref is either zero, or not.  But if if has been used in either state, I now run into a potential error of using an invalid reference.  I found a post a few days ago recommending to check the validity of reference before using it, but couldn't find any VIs or prop nodes to do so.

 

Where can I find these or is there an other method to check for validity of a reference?

0 Kudos
Message 1 of 4
(2,630 Views)

@AMP12 wrote:

Where can I find these or is there an other method to check for validity of a reference?


 

This seems to be helpful for you:

 

Not A Number/Path/Refnum? Function


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 2 of 4
(2,624 Views)

What has been found is that the best way to test a reference is to just use it and handle any errors occur from it.

 

NI ran into a race condition where somebody checked to make sure a reference was valid before using it.  But somewhere along the way, the reference was closed by another process between the check and the actual use, generating an error.  From that, it was stated that you are better off just using the reference and handle the error as need be.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 4
(2,610 Views)

Moderator,  No it doesn't.  It only works after initially opening when the refnum value value is zero.  After that, there can be a value in the refnum, that the VI will consider it a refnum (correctly), but that refnum is no longer valid since is has been closed then throw an error.  And it seems to me that it is closed by LV automatically, and not by me programatically in those cases.

 

Crossrulz, That makes sense to me, but I assumed there were VIs out there somewhere based on the other post I read.  If your method is the direction NI is recommending, I guess that explains why I couldn't find anything out there...

0 Kudos
Message 4 of 4
(2,586 Views)