08-26-2010 01:18 PM - edited 08-26-2010 01:22 PM
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
Solved! Go to Solution.
08-26-2010 01:45 PM
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.
08-26-2010 01:59 PM - edited 08-26-2010 02:03 PM
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.
08-26-2010 02:07 PM
For accessing every few seconds, I would open once at the beginning of the program and close at the end.
08-26-2010 02:14 PM
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.
08-26-2010 02:36 PM
Usually when I say open, I'm thinking of the VISA config VI where you set baud rate, termination character, parity, ...