LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Closing Identical VISA Sessions

I have several sub VI's using VISA in my latest build.  By default they all use the same VISA session, but the user has the option to switch one or more sub VI's to a different device (different VISA session).

In my "Panel Close" event, I currently have it wired such that each sub VI's VISA session is closed separately.  It occurred to me that this may cause problems in the (normal) case that one or more sub VI's is using the same session; however, my main VI is somewhat of a mess, and it will be a couple days before I can actually test this.

Will it cause errors, program crashing, etc. for me to give a Close command on a VISA session that isn't open any more?
0 Kudos
Message 1 of 8
(3,293 Views)
Hi DJDDA,
if you use different VISA sessions, you should store these references in a shift register. Use a for loop to close all opened references. You can also check if a VISA session is already closed before you try to close it again.
 
Hope it helps.
Mike
Message 2 of 8
(3,268 Views)

@DJDDA wrote:

Will it cause errors, program crashing, etc. for me to give a Close command on a VISA session that isn't open any more?

In a word: no.
Message 3 of 8
(3,243 Views)
Hey DJDDA,

I have tested out the setup of closing a session after it was previously closed. There are not any errors produced and it will not crash your program. You are able to close a session as many times as you want. The problem you might run into is if you close the session before an alternate subVI is done using that. That will cause problems in your program.

Thanks
Sarah_S
Sarah S.
Applications Engineering
National Instruments
Message 4 of 8
(3,236 Views)
MikeS81: That's a good idea, I suppose, but it would require more modification of my functional global than I'm in the mood for right now; I'd prefer to just throw in an Undbundle By Name with a Close VISA for each subVI.  I just wanted to make sure it would be possible to do it this way.

Sarah_S: Thanks for the heads-up about closing sessions in use by other subVI's.  That saved me some trouble.
0 Kudos
Message 5 of 8
(3,220 Views)

I close all VISA Sessions /before/ they are used.
Much easier to do than closing at exit.

Especially during development and debugging it happens that the prog ends prematurely and unplanned.
When I restarted the program in these cases , I got VISA errors and even bluescreens.

 

Closing VISA sessions at the very beginning solved these problems for me.

 

0 Kudos
Message 6 of 8
(2,779 Views)

@PeterHeckert wrote:

Much easier to do than closing at exit.


But you really should be closing them when you are done with them.  If you try to close something that isn't open, it is not an issue.


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 7 of 8
(2,764 Views)

Yes it is true, closing everything at exit is good programming style.

 

However, it is sometimes difficult.

 

I test PCB boards which have an inbuilt USB to Serial interface. After each test a new PCB is inserted.

If the PCB is defective then the serial interface (e.g. COM 3) might malfunction or might not be present at OS (Windows) level. All trouble must be expected and the test must be aborted and the next PCB is inserted.
For example, the serial interface can vanish while the program is running.
 

I had a lot of crashes, before I inserted code to close and reset everything at program start.

0 Kudos
Message 8 of 8
(2,758 Views)