LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

leave visa session open

Solved!
Go to solution

Which is the better practice?

 

start program

-----open visa session

----------do stuff

-----close visa session

end program

 

OR

 

start program

-----REPEAT

----------do stuff

----------open visa session

---------------do stuff

----------close visa session

----------do stuff

-----END REPEAT

end program

 

0 Kudos
Message 1 of 6
(3,188 Views)

Kind of hard to compare because your first example doesn't have any REPEAT element to it.  So a program with a loop to one without is comparing apples to oranges.

 

In general, it is better to open a VISA session outside of a loop, do stuff in a loop, close the session outside of a loop.  Particularly, if the loop has a pretty quick iteration rate.

 

Now if the program was looping, but the VISA stuff was infrequent, such as querying an instrument for data once an hour, I would be inclined to do the VISA open and close inside the loop as well.

0 Kudos
Message 2 of 6
(3,163 Views)

What I'm doing is setting up a power supply. My question is, is it better to open a session at the beginning of a program and then use the reference that I create to do things to the power supply throughout the life of the program, or is it better to open a session each time I need to communicate with the power supply and then close as soon as I'm done. In this case, I will only reference the power supply occasionally and the time between calls will be at least several seconds.

0 Kudos
Message 3 of 6
(3,153 Views)

For accessing every few seconds, I would open once at the beginning of the program and close at the end.

0 Kudos
Message 4 of 6
(3,147 Views)
Solution
Accepted by topic author oyester

And remember that you do not have to do either. With NI-VISA, the Open has been optional for quite a few years. A session will be automatically created when you use any VISA function. You can also set it so that VISA is automatically closed. This is settable from Tools>Option>Environment.

 

That being said, the open and close are probably nice from a compatability issue. I do not know if other company's implementation of VISA work the same.

0 Kudos
Message 5 of 6
(3,143 Views)

Usually when I say open, I'm thinking of the VISA config VI where you set baud rate, termination character, parity, ...

0 Kudos
Message 6 of 6
(3,134 Views)