07-17-2013 09:08 AM
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?
07-17-2013 09:46 AM - edited 07-17-2013 09:48 AM
@AMP12 wrote:
Where can I find
these or is therean othermethod to check for validity of a reference?
This seems to be helpful for you:
07-17-2013 10:31 AM
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.
07-17-2013 01:02 PM
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...