Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Close Session is not called after InstallHandler API is used

Hi everybody
 
I have an issue with a VISA API that I need to use trough my IVI driver. Basically my driver wraps the NI VISA COM InstallHandler API into a specific method of my IVI interface.
 
I start my IVI, Initialize, do some work and then Close my IVI driver. This automatically call VISA Close session and everything goes fine,
 
The problem start when I am using the VISA InstallHandler API as in the code below.
 
I have initilaized a VISA connection to my instrument, I get the VISA session associated with this connection and call the EventManager interface on VISA to install a new EventHandler as in the code below.
 

HRESULT OPM8000::IOPM8000EventManager_InstallSRQHandler(IOPM8000EventHandler* EvHandler,

long UserHandle)

{

HRESULT hr = S_OK;

IVisaSession* pVisa = NULL;

IEventManager* pEventManager = NULL;

IOPM8000EventHandler* pEventHandler = NULL;

hr = ioprvGetIVisaSessionPointer(&pVisa);

if ( pVisa == NULL) return ReportError(IDS_E_IVI_NOT_INITIALIZED);

//Get the VISA IEventManager associated with this device session

hr = pVisa->QueryInterface(

__uuidof(IEventManager), (void**) &pEventManager);

//install VISA event handler for SRQ requests

hr = pEventManager->InstallHandler(EVENT_SERVICE_REQ,

this, UserHandle, NULL);

pEventManager->Release();

pVisa->Release();

return hr;

}

 

The problem is that after I call this function that install a new EventHandler with the VISA session the closing of my application IVI driver does not call VISA close anymore!

What could be the reason of failing to close the VISA session later?

Seems that for any VISA API interface that I got to use in my internal code I call the corresponding Release on the same interface!!!

 

Thansk

 

 

Sorin

 

 

 

0 Kudos
Message 1 of 17
(5,142 Views)

sorinvalea,

Unfortunately you can't use VISA and IVI in the same session.  When an instrument driver is an IVI driver it calls upon a DLL made for that instrument that has the functions necessary to communicate with that instrument, while VISA uses the VISA32.dll. In the instance where there is an IVI driver, IVI Session Open and Close are used, so a VISA Write or Read will not communicate with the instrument.

Since the IVI driver uses a specific instrument DLL, it will have to use the functions from that DLL to communicate with the instrument. For that reason, many IVI drivers contain VIs for reading and writing that make that call for you.

In the case a VISA instrument driver, the Open and Close functions for that driver contain VISA Open and Close. This is the case where you can use VISA Reads and Writes because they all use the VISA32.dll to communicate with the instrument.

If you are going to use both, please follow this:

1.Open the VISA session
2. Use VISA functions to communicate with the instrument
3. Close the VISA session
4. Open the IVI session
5. Use the IVI instrument driver VIs to communicate with the instrument
6. Close the IVI session

A_Ryan
AES
National Instruments
0 Kudos
Message 2 of 17
(5,124 Views)

Thanks Ryan

I know that IVI driver sit on top of NI-VISA COM library and is calling Open, Close, Write and Read of the NI-VISA library.

This is visible when I am using NI Spy and intercept all communication to my IVI instrument.

Also the InstallHandler function code is first getting the session handle of the IVI driver session currently running so I expect that the same underlying DLL ( the current one opened for IVI ) must be used in this case.

I want to give you my understanding of this IVI and/or VISA calls sequence. As long I stay in IVI the same DLL and connection is opened and closed as only one path is used all time.

But when I am starting IVI and then in the midlle of the IVI calls I start calling VISA directly these calls use another path and DLL such that the previous IVI calling path is lost and as result of this the IVI close will fail to execute?

Thansk

 

Sorin

 

 

 

 

 

 

 

 

0 Kudos
Message 3 of 17
(5,120 Views)
sorinvalea,
 
To the best of my understanding this is correct.  If you open a VISA session while an IVI session is currently open a conflict with the dll will arise. For instance, if you open an IVI session and then add a VISA write, the VISA write will reference the IVI dll and not the VISA32.dll, which is not correct.  This is why it is recommend to open an IVI or VISA session, take action, then close the session.  This will help guarantee correct command is working with the appropriate dll.
A_Ryan
AES
National Instruments
0 Kudos
Message 4 of 17
(5,112 Views)

Thanks for feedback

The problem in my InstallHandler function is closed related to the IEventManager interface provided from the VISA COM library to the IVI open connection(session).

In my code I get the IEventManager interface from the current session opened in the IVI driver so no new VISA session is required. In doing this I am sure that I keep using only one session and that is the IVI session.

No contradiction or conflict is expected here I suppose. I am doing a similar call by using IFormattedIO488  interface of the current IVI session and I don't have trouble closing IVI session from a direct call to the same IVI drive close method.

Maybe the reason of this behaviour is specific to IEventManager interface only?

Sorin

0 Kudos
Message 5 of 17
(5,106 Views)
sorinvalea,

Continuing with your last thought, "Maybe the reason of this behavior is specific to IEventManager interface only"  a possible reason why the command(IFormattedIO488) works and the EventHandler doesn't, is because the IFormattedIO488 is not in the VISA Programming Manual.  The EventHandler is part of the VISA Progamming manual.  Here is the link to the VISA Programming Manual.
 
Based upon your particular situation one choice would be to make a change to the IVI driver.  By changing the driver, you could implement what you want to do without having to use VISA directly.  This would allow you to use only IVI.  I have a some additional questions for you:
1.  What environment are you developing this code in?
2.  What is your application?
3.  What is the ultimate end goal of what you are trying to do?
A_Ryan
AES
National Instruments
0 Kudos
Message 6 of 17
(5,085 Views)

Hi Ryan

My IVI driver is talking to some VXI-11 instruments trough VISA TCP/IP resource. The user does not see the specifoc of VISA calls as viWrite, viRead and others as all this are hidden by IVI methods but every IVI method is calling this VISA calls to talk to the instrument.

For event handling in order to hide the specific of VISA calls that are required to get this working I am wrapping the event managing interfaces inside my IVI driver and I expose to outside user only the SRQ request as this is the only event I am interesed.

Mi IVI is wriitten in C++ but the application calling this IVI driver could be in any language includin LabVIEW, VB, VC++ etc.

The viClose is called whenever I am using my application in Release mode or if my VB debug environment is closed. The only problem is when I run in VB IDE debug environment and even If I close my VB application there( when application closese it calls IVI driver close) without closing the VB IDE the VISA Spy shows me that viClose is not called.

It has something to do with the VB 6 in debug mode environment being open prevent somehow the call to viCLose when I am using the specific InstallHandler in my IVI driver. So this is a very specific case when viClose is not working as expected but could be related to the way VB debug environment is dealing with COM interfaces.

Thansk

 

Sorin

 

0 Kudos
Message 7 of 17
(5,074 Views)
sorinvalea,
 
If you don't execute your code in the debug mode, does the viClose work?  Or is there any case when the viClose works properly?
A_Ryan
AES
National Instruments
0 Kudos
Message 8 of 17
(5,063 Views)

Hi Ryan

Yes viClose is called properly when  I am runing and closing the IVI application in Release mode.

viClose is also called properly after I am closing the VB IDE environment and what is important is called for all the VI open sessions that happened in the VB IDE. So If I started my IVI application for 10 times and closed for 10 times without closing VB IDE then when I am closing the VB IDE I could see how VISA Spy call viClose on all 10 different viSessions opened for the 10 times running of my application.

Of course that something related to VB IDE in debug mode prevent VISA to close properly the viSession but this happens only after I use InstallHandler call. If I use any other IVI methods but not the InstallHandler method then viClose is called and the session is closed even in VB IDE debug mode enviroment is left open.

 

Thansk

 

Sorin

 

 

0 Kudos
Message 9 of 17
(5,061 Views)
Hello Sorin,
    I would like to help you with this issue and have a couple of questions for you:

1.  What other National Instruments Products (Hardware and/or Software) are in this application?
2.  Do your VXI-11 instruments fall under one of the IVI Classes?
       If yes, are you writing your driver to be class compliant with the most recent version of the applicable Class Specification?
                   Go to ivifoundation.org for more information about the Class Specifications and other Specifications
3.  Please indicate which of the following you are implementing:
    a.State-caching
    b.Range-checking
    c.Simulation
4.  What are some of the IVI engine calls that you are making in your IVI driver?
5.  What version of the IVI Compliance Package are you using?
6.  Have you had a chance to look at IDNet (ni.com/idnet) to see if there are already IVI drivers for your instruments?

Cheers,

NathanT
0 Kudos
Message 10 of 17
(5,047 Views)