LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is Visa Open / Close needed?

Hello,

when sending scpi commands to an instrument then i can simply use the Visa_Write and it works.

Why is there also a Visa_Open and Visa_Close?

Thanks

0 Kudos
Message 1 of 7
(6,441 Views)

I know one element is VISA open and close will manage the reservation of hardware ports.

 

If you run the application just with VISA write then the port get reserved. I think if you then try and access it from another application you will find that the reservation is held and it can't be accessed. This can also happen between runs of VIs. For this reason it is good practice.

 

Open will allow you to make configuration changes on the port before the write if needed and also reduce the work done when you have write. i.e. if you have no open then any "open" operations must happen for every write where as if you have a separate open you can do it once at the start of your application and reduce overhead (as well as making sure you have the hardware reserved properly so there will be no errors once your application is running._.

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
Message 2 of 7
(6,427 Views)

Hi OnlyOne,

 

when trying to allocate/use a shared resource (like a communication port with an external device) you should open/request that resource and close/free it afterwards! (Additionally you might want to set parameters of the communication port when opening it.)

 

Even when LabVIEW does this work for you in the background it will not arrange things for you in a magical way when it comes to things like parallel access to the same shared resource!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(6,425 Views)

Is it possible that each "write" creates a new session and that there is a "maximum number of sessions"?

It looks like that after running ~10-20 time the vi (without open/close) that it suddenly does not work anymore. After closing/opening labview everything runs fine again. Looks like there is a max number of sessions reached after that the write does not run anymore.

 

There is also a parameter in labview "auomatically close visa session" - perhaps this would solve this problem. (If there is a value for "max number of sessions")

0 Kudos
Message 4 of 7
(6,415 Views)

I dont think there is a maximum number of sessions other than 1 when the hardware is reserved. 

 

It could be a race condition if you are using this port in more than one place. On 90% of connections there is no conflict but then in the 10% case two places access the port at the same time.

 

I would look to incorporate the open close so you can more explicitly managed the connection and go from there.

 

Cheers,

James

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 5 of 7
(6,394 Views)

I think the Open is done behind the scenes with the first thing that accesses the port.  So for serial ports, we just use the VISA Configure Serial Port and that somehow opens (reserves) the port (nothing explicit inside of the VI to open it).  Then when done with the port, use VISA Close in order to release the hardware.  I hate the "auto close" and "auto error handling" options in LabVIEW because it makes people lazy and not think about these important things (resource management and error handling).

 

In conclusion: You really should be closing your resource when you are done with it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(6,368 Views)

@crossrulz wrote:

 

In conclusion: You really should be closing your resource when you are done with it.


I have also noticed on some instruments if you do not close the VISA session the instrument is left in the "remote" state and all of it's front panel controls are locked out.

 

This can be a bad thing for instance on my AC source there is no "Local/Remote" button on the instrument so you have to power cycle it to regain control.

========================
=== Engineer Ambiguously ===
========================
Message 7 of 7
(6,341 Views)