LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using callbacks with a USB connected VISA instrument?

Solved!
Go to solution

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?

0 Kudos
Message 1 of 5
(3,527 Views)
Solution
Accepted by topic author HDJ

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

 

 

 

0 Kudos
Message 2 of 5
(3,516 Views)

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;

}

Message 3 of 5
(3,514 Views)

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

0 Kudos
Message 4 of 5
(3,513 Views)

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

0 Kudos
Message 5 of 5
(3,507 Views)