LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Do we still need to close VISA sessions?

I know it sounds like a silly question but do we?

 

Back in my early days (LabVIEW 5.1) I used to have a set of favorite VI's for my instruments that opened a VISA session, performed a task (like taking a measurement), then closed the VISA session. I used these a lot as I could drop them in and throw a program together without having to worry about wiring the VISA sessions. Fact this speed of test development really sold our company on LabVIEW...

 

Well later on I was having an issue with a larger program crashing. After spending some time on the phone with a NI Engineer troubleshooting he told me that the constant opening and closing VISA sessions was not a good idea and could be the cause of my issues. So I rewrote the program opening a VISA session once for each instrument and closing it at the end. This cured the crashing and forced me to abandon my library of drop-in VI's that had served me so well for so long, totally changing the way I was writing my programs.

 

Now fast forward to a couple years ago when my company made the jump from Labview 5.1 to 8.0 (that was a big step) now we are at LabVIEW 2009

 

Among the many other changes from 5.1 to 8.0 most notably VISA had changed, I/O wire types, VISA Open was gone, VISA Close was deprecated, all my old programs have the (old) tag on the VISA blocks... AND there was a Automatically close VISA sessions in the advanced options

 

The fact that VISA Close was deprecated kind of leads me to believe that we are being guided to used the auto-close option. It certainly makes programming faster not having to drag the VISA wires out and close them... But often I still do just out of habit.  

 

This also has me wondering if we even still have to open a VISA session and wire it all the way through?

 

So take a look at the attached overly simplified examples and explain what is the "best method"?

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 1 of 4
(3,729 Views)
When the option is checked, VISA sessions are only closed automatically when your VI stops running.  My understanding, based on this, is that your two auto-close VISA examples are identical.  The session is opened the first time a resource is used and remains open until it is explicitly closed or until your VI stops running (if the automatically close VISA sessions option is checked).  If you don't automatically close VISA sessions and you do not close them explicitly, they will stay open even when your VI is not executing, which means they will open faster when you restart your code but will not be available to other applications.  Of course, exiting LabVIEW closes all VISA sessions.
Message 2 of 4
(3,704 Views)
Also note that VISA Open is still available under the Advanced VISA palette.  If you are using a larger VI, more complicated VI, then its usually a good idea to go ahead and close those references to free up resources. 
Marti C
Applications Engineer
National Instruments
NI Medical
0 Kudos
Message 3 of 4
(3,678 Views)

I agree with nathand. Last year I was working on a VI that controlled a stepper motor using the VISA application. The first time i wrote the code my motor would rotate a certain amount of degrees and the program would stop running; however the motor kept rotating for the next two seconds or three seconds. I asked a coworker if he knew what the problem was and he told me that i needed to close my VISA in order to completely stop sending the signal. So I do think it is important to close VISA once the program is done running. 

 

0 Kudos
Message 4 of 4
(3,664 Views)