From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Valid VISA Session?

Solved!
Go to solution

Maybe this is a stupid questions but I can't seem to find out how to tell if a VISA session was already opened.  Any ideas?

 

Basically in my SubVI:

Check Validity

If Valid

-Write value to VISA Write

If Not Valid

-Open Session

-Write value to VISA Write

-Close Session

 

I need to return the opened session to TestStand or calling VI if it was valid before the VI was called.  Otherwise I cannot close it because that wold screw up the caller.

 

Thanks,

 

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 1 of 9
(6,478 Views)

Do you really care if the session was opened already. It has been years (LabVIEW 6.1?) since you needed to use the VISA Open. If a session is not open, one will be created when you use any VISA function. And if you do call VISA Open and a session has already been created, the existing one will be used unless you explicitly ask for a new one.

Message 2 of 9
(6,449 Views)

Thanks for the response Dennis!

 

I don't really care about the open as much as I do the close.  I wanted to check and see if the session was opened when the VI was called so that I can close it before returning to the caller.  This VI will be used by many developers and I just wanted built in cleanup as to avoid loose sessions all over.  However, if they had already opened a session I don't want to kill it because they may need it elsewhere in their app.

 

I guess to your point it doesn't matter if I close the session because when they go to do a read or write it will still just open the session again?  Let's say I use it in TestStand and a developer opens a session at the beginning.  Then they call my VI and it closes the session.  Then they try to call another VISA read or write using that handle they opened at the beginning.  Will it still work?  I thought it was a pointer to some memory location and if you closed it then you can't really use that again unless you create a new session? 

 

I guess I can just put in the description that they must close the session elsewhere in their code regardless of if they use the serial option or not.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 3 of 9
(6,439 Views)

I'll have to think about the consequences if you are passing the reference around in TestStand. What I do is pass the VISA Resource Name into each VI. Don't pass anything out

Message 4 of 9
(6,435 Views)
Solution
Accepted by topic author ~jiggawax~

Refnum to Session.vi will get the session for you and if there is a session number you know it is open or not.

 

It is hidden in the teststand VI pallet.

 

 

 

refnumtosession.png

Glenn Ellis
Message 5 of 9
(6,400 Views)

That sucks for people without TestStand but it works for me.

 

Thanks Glenn!

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 6 of 9
(6,387 Views)

 


@~jiggawax~ wrote:

That sucks for people without TestStand but it works for me.

 

Thanks Glenn!


Sorry for digging up an old thread but for those people without TestStand: 

 

"Refnum to Session" is used in visa probes which can be found in the VisaProbes.llb ("\Program Files\National Instruments\LabVIEW 2009\vi.lib\_probes\default\VisaProbes.llb") simply open the "VisaProbeSerialInstr.vi" and copy the subvi from there.

 

Message 7 of 9
(5,581 Views)

@WatWork wrote:

 

Sorry for digging up an old thread but for those people without TestStand: 

 

"Refnum to Session" is used in visa probes which can be found in the VisaProbes.llb ("\Program Files\National Instruments\LabVIEW 2009\vi.lib\_probes\default\VisaProbes.llb") simply open the "VisaProbeSerialInstr.vi" and copy the subvi from there.

 


 

 

There doesn't seem to be a subvi there anymore if opening with 2014x64  Any other ideas about how to find out if the port is open or not?

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 8 of 9
(5,070 Views)

This Knowledge Base article shows how to identify open VISA Sessions:

 

How Can I Get a List of Open VISA Sessions in LabVIEW?

http://digital.ni.com/public.nsf/allkb/6A9B4BA95EFA6C22862575080064D98F

0 Kudos
Message 9 of 9
(5,031 Views)