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 Nathan

Thansk for involvment in this problem. I know that IVI is a complete new way of developing drivers and that is the reason why I did not stress too much the IVI side of things in this post. The IVI questions(State Cache, Range Check, Simulation etc) are outside my current problem and I could consider them as not being a part of this specific problem.

I am using NI-VISA 4.0.0.49152 as software and a NI GPIB chip for our instrument.

I already pointed that this problem is confined to keeping VB IDE debug environment open somehow affect the closing of the vi sessions when my client application closes but this happens only when I am calling the InstallHandler from the IEventManager of the VISA COM library pointed above. So I will be investigating more on this specific condition.

Thanks

Sorin

0 Kudos
Message 11 of 17
(2,070 Views)
Hello Sorin,
    Thanks for the additional information.  I don't think that I can be of much help, since IVI is my focus.  We will have to hear from the VISA experts.

Cheers,

Nathan
0 Kudos
Message 12 of 17
(2,053 Views)
Hi Sorin,

Are you using viUninstallHandler later in your code?  If not, try using that and see if the behavior changes.

Syntax:
ViStatus viUninstallHandler(ViSession vi, ViEventType eventType, ViHndlr handler, ViAddr userHandle)

There is a full description in NI-VISA Help.

Gavin Fox
Systems Software
National Instruments
0 Kudos
Message 13 of 17
(2,044 Views)
Sorry, I posted the syntax before remembering you're using COM.  Here's the correct syntax:

HRESULT IEventManager_UninstallHandler(EventType type, LONG userHandle, LONG customEventType);

Gavin Fox
Systems Software
National Instruments
0 Kudos
Message 14 of 17
(2,041 Views)

Hi Gavin

Yes I call the corresponding viUninstallHandler when my VB6 application closes and I use the same user  handle that I used to call viInstallHandler.

The customEventType is not used (NULL) and the event type is SERVICE_REQ

For more information I attach my driver internal code of these two methods:
So in my driver I wrap the VISA InstallHandler call inside a method defined 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;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
USING my COM Driver from the VB6 client application side

Now from VB6 client application my driver wrapping InstallHandler method is called like this:
Get the ISRQEventManager interface associated with a valid, active working session opened with my COM driver and call the InstallSRQHandler wrapper of the VISA viInstallHandler method.

 lUserHandle = 1000
 ISRQEventManager.InstallSRQHandler Me, lUserHandle

After calling this I could see the NI Spy properly installed an EventHandler trough VISA with my remote
VXI-11 instrument on the TCP/IP network

Next setp in my VB6 client application I will enable one type of event SRQ only
ISRQEventManager.EnableSRQEvent
which is again properly passed trough VISA as I sse that with NI Spy tool.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
For uninstalling my SRQ event handler I have in my driver another wrapper to VISA UninstallHandler that is also defined in my COM driver as below:
HRESULT MAP200_OPM::IMAP200_OPMEventManager_UninstallSRQHandler(long UserHandle)
{
IVisaSession* pVisa = NULL;
IEventManager* pEventManager = NULL;
IMAP200_OPMEventHandler* pEventHandler = NULL;

hr = ioprvGetIVisaSessionPointer(&pVisa);
//Try to get IEventManager associated with our device session
hr = pVisa->QueryInterface(__uuidof(IEventManager), (void**) &pEventManager);
//Uninstall VISA EventHandler for SRQ requests
hr = pEventManager->UninstallHandler(EVENT_SERVICE_REQ, UserHandle, NULL);
pEventManager->Release();
pVisa->Release();
return hr;
}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I am Calling the UninstallSRQHandler from my VB6 client application when application closes in the
Form.Unload will properly call VISA viUninstallHandler and then viDisableEvent with the same parameters
used for viInstallHandler and viEnableEvent. These calls are visible in NI Spy.

Last step I call myDriver Close that is calling VISA close trough IVI driver IO close
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I reapeat again that in Release mode the viClose from VISA is called properly when my VB6 client application closes but not called in VB6 debug environment IDE when the same application closes.
If I started 10 times the same VB6 client application in VB6 IDE debug mode 10 different VISA sessions would be opened but noe of this will be closed when application closes.
Instead when I finally decided to close VB6 IDE debug environmnet only now the VISA will close all 10 previous opened sessions by isussuing 10 viClose with all 10 previous sessions numbers.

So my feeling is that this problem is closely realted to callling viInstallHandler trough my COM wrapper and calling the corresponding viUninstallHandler will prevent the VB6 client application to close properly when this is run in debug mode under the VB6 IDE debug environment. Any other calls in my COM drivers will pass without affecting the normal driver close from VB6 IDE debug environment as I may see with the NI Spy.

I hope that this extra information helps

Thanks

Sorin

0 Kudos
Message 15 of 17
(2,033 Views)
sorinvalea,
 
With your permission I would like to retrieve your email address from your forum account so we can work on this issue offline.
A_Ryan
AES
National Instruments
0 Kudos
Message 16 of 17
(2,024 Views)

Hi Ryan

Is OK to get my email address for further offline investigation

Sorin

0 Kudos
Message 17 of 17
(2,023 Views)