01-14-2008 10:48 AM
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 requestshr = 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
01-15-2008 10:05 AM
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
01-15-2008 10:50 AM
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
01-15-2008 11:19 AM
01-15-2008 11:36 AM
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
01-15-2008 05:17 PM
01-16-2008 08:50 AM
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
01-16-2008 12:03 PM
01-16-2008 12:14 PM
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
01-16-2008 03:51 PM