03-22-2012 09:46 AM
I have an Agilent 34972 connected by USB to a Windows 7 machine. I am using LabWindows/CVI and the VISA drivers.
I cannot find a way to setup a callback which will react to an ALARM event on the Agilent, ie. the Agilent is set up so that certain signal combinations generate an alarm (it could be any other event in the instrument for that matter - it ends up in the STB register, similar to that on a GPIB instrument) and I want my LabWindows program to react to this event (e.g. run a callback routine). With GIPB I have the ibnotify() etc., but I cannot find the equivalent on this combination (USB/VISA).
Any ideas?
Solved! Go to Solution.
03-23-2012 03:59 AM
Hi HDJ
Have you seen this documentation on how to do VISA Event handling?
VISA Events in NI-VISA
http://www.ni.com/support/visa/vevents.pdf
In the buttom of page 4 there is some things to consider when using the Callback Mechanism. Most important is that you have to install a handler function, viInstallHandler(), before you enable the event viEnableEvent().
Also you should notice that it is only allowed to have one callback per session.
Agilent also have som information about using the event and callback here (from page 46):
Agilent IO Libraries Suite
http://www.htest.cz/download/IO_Libraries_Suite_15_visa.pdf
Best Regards
Anders Rohde
Applications Engineer
National Instruments Denmark
03-23-2012 04:03 AM
Well, it always help formulating ones problem into a question. Sometimes it get you out in corners of the documentation you didn't see the first round. So I solved my problem with the following snippets - if anyone else ends in the same alley as I. AM I doing to much, or should things be arranged differently? At least it works.
In the main program I have:
vierr = viOpenDefaultRM (&sesHandle);/* open a VISA session */
vierr = viOpen (sesHandle,
"USB0::0x0957:: .......::0::INSTR",
VI_NULL, VI_NULL, &agHandle);/* connect to the instrument */
bufferHandle = (ViBuf)malloc(MAX_CNT+1);/* I don't know what this is for ... MAX_CNT is 1024 */
vierr = viInstallHandler(agHandle, VI_EVENT_SERVICE_REQ, myCallback,
bufferHandle);/* Tell the driver what function to call on a SRQ event */
vierr = viPrintf (agHandle, "*CLS\n");/* Clear message queues on the Agilent */
vierr = viPrintf (agHandle, "STAT:ALARM:ENABLE 2\n"); /* Enable alarm 2 - the criterea to raise ALARM2 are set elsewhere */
vierr = viPrintf (agHandle, "*SRE 2\n"); /* Enable RSQ on Alarm register */
vierr = viEnableEvent(agHandle, VI_EVENT_SERVICE_REQ, VI_HNDLR, VI_NULL); /* Enable the driver to detect events */
The CallBack is defined prior to main as
ViStatus _VI_FUNCH myCallback(ViSession vi, ViEventType etype,
ViEvent eventContext, ViAddr userHandle)
{
ViStatus status;
ViUInt16 stb;
status = viReadSTB(vi, &stb); /* Read the stats bit */
if (stb & 2) { /* Check that it is an alarm - bit-mapping is device dependent */
/* do the actions for the alarm state */
}
vierr = viPrintf (agHandle, "*CLS\n"); /* Clear the status - this is necessary to be able to call again */
return VI_SUCCESS;
}
03-23-2012 04:05 AM
Hi Anders
Thanks for the message. I was writing a reply to my own post, when yours appeared. You are correct where to find the information.
Thanks
Hans
03-23-2012 04:24 AM - edited 03-23-2012 04:25 AM
You are welcome Hans. Glad to hear the problem is solved, and thank you for posting your solution to the forum.
Have a nice day
Best Regards,
Anders Rohde
Applications Engineer
National Instruments Denmark