Digital Multimeters (DMMs) and Precision DC Sources

Showing results for 
Search instead for 
Did you mean: 

What is the proper way to close all open sessions of a NI PXI-4110 for a given Device alias?

I've found that, when programming the NI PXI-4110 that, if a the VI "niDCPower Initialize With Channels VI" (NI-DCPower pallette) is called with a device
alias that all ready has one or more sessions open (due to an abort or other programming error) a device reference results from the reference out that has a (*) where "*" is post-fixed to the device reference where and is an integer starting that increments with each initialize call. In my clean up, I would like to close all open sessions. For example, let's said the device alias is "NIPower_1" in NI Max, and there are 5 open sessions; NIPower_1, NIPower_1 (1), NIPower_1 (2), NIPower_1 (3), and NIPower_1 (4). A simple initialize or reset (using niDCPower Initialize With Channels VI, or, niDCPower Initialize With Channels VI, etc.) What is the proper way to close all open sessions?


Thanks in advance. Been struggleing with this for days!

0 Kudos
Message 1 of 3

When you Initialize a session to a device that already has a session open, NI-DCPower closes the previous session and returns a new one. You can verify this very easily: try to use the first session after the second session was opened.


Unfortunately, there is a small leak and that is what you encountered: the previous session remains registered with LabVIEW, since we unregister inside the Close VI and this was never called. So the name of the session still shows in the control like you noted: NIPower_1, NIPower_1 (1), NIPower_1 (2), NIPower_1 (3), and NIPower_1 (4), etc.


There may be a way to iterate over the registered sessions, but I couldn't find it. However, you can unregister them by calling "IVI Delete Session". Look for it inside "niDCPower". If you don't have the list of open sessions, but you have the device name, then you can just append (1), (2) and so forth and call "IVI Delete Session" in a loop. There's no problem calling it on sessions that were never added.


However - I consider all this a hack. What you should do is write code that does not leak sessions. Anything you open, you should close. If you find yourself in a situation where there are a lot of leaked sessions during development, relaunching LabVIEW will clear it out. If relaunching LabVIEW is too much of an annoyance, then write a VI that does what I described above and run it when needed. You can even make it "smarter" by getting the names of all the NI-DCPower devices in your system using the System Configuration or niModInst APIs.


Hope this helps.

Marcos Kirsch
Chief Software Engineer
NI Driver Software
0 Kudos
Message 2 of 3

Hi Marcos,


First thank you for the quick response. I really appreciate your time. The soutions you provided will work, although, I agree, it would be nice to have the ability to itterate through all open session and tidy up in the clean section (I am using TestStand with this VI). I'm not familiar with the niModInst APIs, but that can be remidied with the find manual.I'll take a look at that.


As an asside, part of my problem is failing to realize that the outpu of the initialize VI is an "Instrument Handle" not simply a copy of the resource name. In an edit step setting (Again, with respect to TestStand) I was taking the setting output and storing it in a global variable for succedding steps. When a step in TestStand fails and the user aborts the sequence, I was left with the session name in the global variable due to my bo boo. In a nutshell, I believe stroing a user selected resource and not the handle followed by proper clearn up should resolve this mess. 


Thanks again,



0 Kudos
Message 3 of 3