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: 

Calling VISA Close from a DLL

Solved!
Go to solution

Well, I need to do some finalization tasks with LabVIEW objects inside my DLL. One of such objects is VISA serial port session. In LabVIEW I can simply call VISA Close VI and everything goes OK. But in DLL it comes to complex things because I can not see source codes (or block diagram) of VISA Close. I found some information that one could use viClose function of visa32.dll in system32 directory or LabVIEW folder. But when I try to use it with simple casting to INT32 and passing to int32_t viClose(int32_t objectHandle); it goes to error on the next program launch. So look at this diagram:

viClose

 

First time the program works allright. Second time it throws the following error:

 

error

 

The whole program works fine with standard VISA Close VI. But it's impossible to use it inside my C++ library. So I started to think, calling simple viClose is not enough for correct cleanup of VISA resource. I tried viTerminate before viClose but the problem remains the same.

 

So, how can I close VISA session correctly in DLL? Maybe, it's better not to close it at all? There may be memory leaks though...

0 Kudos
Message 1 of 3
(2,659 Views)
Solution
Accepted by topic author dadreamer

Hi Dadreamer,

 

I looked up that error and we might be able to fix it by closing the VISA sessions automatically. See this knowledge base article for instructions from within the LV environment:http://digital.ni.com/public.nsf/allkb/A2561CDE98B66DD4862566510078264F?OpenDocument. The relevant section: 

 

"

  • In LabVIEW 8.x, select Tools»Options to display the Options dialog box and select Environmentfrom the Category list page. To disable the option, remove the checkmark from the Automatically close VISA sessions checkbox and click the OK button."

Let me know if that works.

 

 

 

Regards,
Basil
Applications Engineering
National Instruments
0 Kudos
Message 2 of 3
(2,607 Views)

Basil-B


Thanks for the answer! Yes, that works, even after pressing red button called Abort. VISA Session is cleaned up correctly. I have also found a workaround for the case when Automatically close VISA sessions checkbox isn't checked. I simply created wrapper DLL in LabVIEW around VISA Close VI: VISA Session is first parameter, Error Cluster - the second. So, I can call this library inside my own DLL or directly from LV block diagram.

 

I wonder, why NI writes about using visa32.dll by typecasting VISA session to integer number but is not fully supporting it. I read it here, for instance. Also tried Refnum To Session VI, but it gave me nothing. It seems, LabVIEW is doing some inner (intrinsic) operations before it calls viClose from visa32.dll. The last function is even wrapped by VisaClose, exported by labview.exe. And it gets not the same int32 number, that is obtained by Refnum To Session or Type Cast VI.

0 Kudos
Message 3 of 3
(2,596 Views)