/***************************************************************************** * This code installs and uses a trigger handler. It prompts the user for a * * trigger line to watch, and a protocol to watch for, and then waits until * * the desired trigger is seen. * *****************************************************************************/ #include #include #include #include static char ch; static UINT16 lines_enabled; static INT16 controller; static unsigned short line_triggered; static NIVXI_HTRIG *new_trig_handler; static NIVXI_STATUS Status; static int disarm, line, protocol, trigevent, protocol_to_watch, trig_to_watch; /**************************************************************************** * This is the installed trigger handler. Once installed using the VXI * * function "SetVXItrigHandler()", anytime the proper trigger is seen (line * * and protocol), the code in this function will be executed. In this case, * * all that is needed is to save information to global variables so the data * * can be used in later code. Do not attempt to do UIR or STDIO output from * * within the trigger handler. * ****************************************************************************/ NIVXI_HQUAL void NIVXI_HSPEC mytrighandler (INT16 ctrlr, UINT16 ln, UINT16 type) { line_triggered = ln; //save value to global variable trigevent = 1; //set the event flag } /****************************************************************************** * In the main code, the flow is as follows: * * * * 1) InitVXIlibrary(): initialize the VXI library. * * 2) prompt the user for data concerning what to watch for. * * 3) EnableTrigSense(): allows the CPU to "see" triggers. * * 4) SetTrigHandler(): installs trigger handler shown above this comment block* * 5) wait in a while loop for the trigger to occur. * * 6) display results for user. * ******************************************************************************/ void main () { Cls(); //clear the STDIO widow if ( InitVXIlibrary() ) //This function must be called to use VXI functions. { printf ("Unable to Initialize VXI library... exiting"); exit (0); } /* * Prompt the user for info regarding trigger line and protocol */ printf ("What trigger line would you like to watch? (0-7) >> "); scanf ("%d", &line); printf ("What protocol would you like to watch for? (options below)\n"); printf ("2 - Start\n3 - Stop\n4 - Sync\n5 - Semi-sync\n6 - Async\n>> "); scanf ("%d", &protocol); /* * First we must enable the CPU to see a trigger. To do this, we need to * use the following function and parameters: * * controller: which controller to enable sensing * line: trigger line to watch * protocol: protocol to watch for */ controller = -1; //use default controller //line and protocol values from above Status = EnableTrigSense(controller, line, protocol); /* * To watch for a trigger we must install our own trigger handler. * The parameters of the function to do that are: * * lines_enabled: contains a bit vector of trigger lines * new_trig_handler: contains a pointer to the new trigger handler */ lines_enabled = 0xFF; //watch all trigger lines new_trig_handler = mytrighandler; Status = SetTrigHandler (lines_enabled, new_trig_handler); if ( Status ) { printf ("Error installing trigger handler... exiting"); exit (0); //could not install handler, need to exit code } printf ("\nWatching for trigger to occur...\n"); trigevent == 0; //clear trigger event flag while ( trigevent == 0 ) { } //stay in this loop until a trigger is detected. //since we have fallen out of the while loop, a trigger was detected printf ("\n\nI was triggered using the desired protocol on line %d\n",line_triggered); printf ("\n"); getchar(); scanf ("%c", &ch); //wait for user to hit a key to quit CloseVXIlibrary(); }