04-16-2013 11:29 AM - edited 04-16-2013 11:33 AM
Hi,
I have been looking for some information about PXI and interruptions but there is not too much information online, so I am a little bit lost. I have to develop a program to detect an interruption from a PXI and then retrieve the data from third part 3 part device that some colleagues have developed. To start, I modified a little bit the example that the VISA driver includes in its help (I just changed the event from the original file).
#include <stdio.h> #include <stdlib.h> #include "visa.h" static ViUInt16 StatusID; static ViSession instr; static ViSession defaultRM; static ViStatus status; static int tempchar; ViStatus _VI_FUNCH IntrHandler(ViSession instr, ViEventType etype, ViEvent event, ViAddr userhandle); /* * Here we define the function that is called whenever an interrupt event is received. */ ViStatus _VI_FUNCH IntrHandler(ViSession instr, ViEventType etype, ViEvent event, ViAddr userhandle) { /* etype is a number which identifies the event type that has been received. */ viGetAttribute (event, VI_ATTR_SIGP_STATUS_ID, &StatusID); printf("An event was received. The Status/ID value is 0x%x\n",StatusID); /* System calls are allowed to be used inside the event handler on all VISA supported platforms other than Macintosh. */ return VI_SUCCESS; } int main (void) { /*First we must call viOpenDefaultRM to get the manager handle. We will store this handle in defaultRM. */ status=viOpenDefaultRM (&defaultRM); if (status < VI_SUCCESS) { printf("Could not open a session to the VISA Resource Manager!\n"); exit (EXIT_FAILURE); } status = viOpen (defaultRM, "visa://137.138.179.180/PXI16::12::INSTR", VI_NULL, VI_NULL, &instr); if (status < VI_SUCCESS) { printf("Can not open a VISA session to visa://137.138.179.180/PXI16::12::INSTR\n"); viClose (defaultRM); exit (EXIT_SUCCESS); } /*Now we will install the event handler that will monitor interrupt events. The handler is named IntrHandler. uhandle is a handle * allowing data to be passed to the handler from the application. */ status = viInstallHandler (instr, VI_EVENT_PXI_INTR, IntrHandler, VI_NULL); // status = viInstallHandler (instr, VI_EVENT_EXCEPTION, IntrHandler, VI_NULL); if (status < VI_SUCCESS) { printf("Could not install the interrupt handler.\n"); viClose (defaultRM); exit (EXIT_SUCCESS); } /* * Now we will enable signal processing events so the program can receive them into its event handler. It will only receive events for * interrupts or signals. See the other interrupt example to see how things would differ if events were queued. */ status = viEnableEvent (instr, VI_EVENT_PXI_INTR, VI_HNDLR, VI_NULL); // status = viEnableEvent (instr, VI_EVENT_EXCEPTION, VI_HNDLR, VI_NULL); if (status < VI_SUCCESS) { printf("Could not enable the interrupt event.\n"); viClose (defaultRM); exit (EXIT_SUCCESS); } /* * Under Windows 3.x or the Macintosh, Yield() or PeekMessage() functions may need to be called to give up processor time so that VISA events * will be invoked. Under WIN32 or UNIX, this is not necessary because VISA event handlers are spawned in a separate thread. */ printf("Press any key to stop waiting for events.\n"); fflush(stdin); tempchar=getchar(); /* Now we will uninstall the handler we installed to handle interrupts Calling this function will implicitly call viDisableEvent().
* Note that unlike viWaitonEvent, the event is closed for us when we exit the handler. Compare this with the other interrupt example. */ status = viUninstallHandler (instr, VI_EVENT_VXI_SIGP, IntrHandler, VI_NULL); /* Now we will close the session to the instrument using viClose. We will tell VISA what to close using the handle, "instr". */ viClose (instr); viClose (defaultRM); printf("\nHit Enter to continue."); fflush(stdin); getchar(); return 0; }
When the program executes the line
status = viEnableEvent (instr, VI_EVENT_PXI_INTR, VI_HNDLR, VI_NULL);
an error appears:
Function viEnableEvent: (return value == -1073807302 [0xbfff003a]). Unable to start operation because setup is invalid (due to attributes being set to an inconsistent state).
If I run the program configuring the other event in the code (and also changing the properties in the handler)
// status = viInstallHandler (instr, VI_EVENT_EXCEPTION, IntrHandler, VI_NULL);
the program works fine...Has someone an idea why i have this error when I use the event VI_EVENT_PXI_INTR?
Also I have another question about interruptions with PXI. Thefinalgoal is to develop a program that calls dll´s made withLabWindows anddetectthepossibleinterruptions in the PXI. I have been looking for some examples but I haven´t seen anything similar...Has someone a practical examples of how to handle interruptions with LabVIEW?
Thanks,
Jaime
04-23-2013 07:23 AM
Hey Jaime,
The error you mentioned is discussed in following KnowledgeBase.
http://digital.ni.com/public.nsf/websearch/DDE6A6A773A4B1DC86256BC0005C8A8F?OpenDocument
Please let me know if this solution works for your you.
Thomas
04-23-2013 07:46 AM
Hi Thomas,
First of all, thanks for your reply. I solved my problem with the next link.
Error BFFF003A When Enabling Interrupts in MAX with 3rd Party Device
http://digital.ni.com/public.nsf/allkb/DFF952E483E212658625712B007B72FB?OpenDocument
Thanks!
Jaime
04-23-2013 07:53 AM
Hi,
thanks for your reply. I´m pleased to hear, that you solved your problem.
Thomas