Tags: case, consequently, detect, labview, port, programming, run, time, unless

How to detect first time a vi is run?

On Programmer » LabVIEW

2,621 words with 3 Comments; publish: Thu, 01 May 2008 22:47:00 GMT; (20046.88, « »)


I have a vi that need to open a com port, unless it's already open in which

case it should just read the com port.

Consequently I would need either a way of detecting if this is the first tim

e a vi runs or a way of checking (very quickly) if a com port is open. Since

the first functionality is very universally useful I'd very much like a sug

gestion here in any case. W

iebe mentioned such functionality in one of his post, a vi that returns this


I have tried to use a while loop that runs once to detect if its the first r

un, for some reason I decided this worked yesterday but today it doesn't. (A

ny explanation on that anyone?)

I am programming a cFP-2120.

First run - initialize.jpg:

http://forums.ni.com/attachments/ni/170/298762/1/First run - initialize.jpg

All Comments

Leave a comment...

    • Rodnebb wrote:

      I decided this worked yesterday but today it doesn't. (Any explanation on th

      at anyone?)

      The USR keeps its value as long as the VI is in memory, even if the entire h

      ierarchy stops running, so if you ran your code once and then ran it again w

      ithout unloading the VI, it will return T even on the first call.

      #1; Thu, 01 May 2008 22:48:00 GMT
    • Here is the path to a vi that I use to check to see if any ports are op

      en you can then use the refnum you need from the array if the port is open.

      It is also useful if you need to make sure all ports are closed, just run th

      e array into a for loop wit

      h a VISA Close.

      vi.lib\Utility\visa.llb\Open Sessions.vi

      Buddy Haun

      CLA, Certified Trainer

      #2; Thu, 01 May 2008 22:49:00 GMT
    • The only problem I have with the "detect first time" method is that it is ve

      ry easy to leave a COM port in an unknown state especially if you have impro

      perly terminated a program and have not exited the LabVIEW system you get a

      "hung" port. LabVIEW has th

      e port reserved as open but the program no longer has the session. I am atta

      ching a program that should provide the functionality Rodnebb is looking for

      . I am also attaching another quick vi that I have found very useful and tha

      t one is for resetting all

      open COM ports.





      #3; Thu, 01 May 2008 22:50:00 GMT