Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I stop DAQ event

Hi all,
my program can not stop event eventhough 2 functions have been called
DAQ_Clear(iDevice);
Config_DAQ_Event_Message (iDevice, 0, "", 1, 0, 0, 0, 0, 0, 0, 0, 0);
 
Anyone can point me if it is board problem or driver or my code.
My operating system is windows2000, tool is VisualC++ ver7.
 nidaq32.dll and nidex.dll are created on July15,2004.
I tested 2 identical nidaq-Dio24 borads with the same code and got the same problem.
Below is my code.
Thanks in advance
 
 
/*  Digital Port A, Line 1 = HIGH
  The STBA* STRBB*  is tied to interrupt signal
All port A and B are tied to GND through 4.7 Kohm
PA.1 tied to 5 V
*/
#define STRICT
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "nidaqex.h"
#include "nidaq.h"
//Prototype function
void CallBack (int handle, int msg, unsigned wParam, unsigned long lParam);
void CleanupNIDAQEvents(short iDevice);
//defined global variable so that callback() can access
i16 iNum = 0;
i16 temp;
bool DAQEventFlag =0;
i16 iStatus2 = 0;
i16 iRetVal = 0;
i16 iDevice = 1;
i16 iPort2 = 1; //port B
i32 iPattern2 = 0;
i16 iIgnoreWarning = 0;

void main (void)
{
 i16 iStatus = 0;
 i16 iRetVal = 0;
 i16 iDevice = 1;
 i16 iGroup = 1;
 static i16 portList[1] = {0};
 static i16 piBuffer[100] = {0};
 u32 ulRemain = 100;
 i16 iIgnoreWarning = 0;
 i16 iYieldOn = 1;
 i16 i = 0;
 iStatus = Init_DA_Brds (iDevice, &temp);  /* Resets the board */
 iRetVal = NIDAQErrorHandler(iStatus, "Init_DA_Brds", iIgnoreWarning);
 i16 iStatus2 = 0;
 i16 iPort2 = 1; //port B
 i32 iPattern2 = 0;
    iStatus2 = DIG_Prt_Config(iDevice, iPort2, 1, 0);//mode1 input
 iRetVal = NIDAQErrorHandler(iStatus2, "DIG_Prt_Config", iIgnoreWarning);
    printf(" PortB is configured as input.\n");
 /* Sets up so a 1 on digital PartA.1 generates a interrupt */
 iStatus = Config_DAQ_Event_Message (iDevice, 1, "DI0", 8, 2, 2, 0, 0, 0, 0, 0, (unsigned long)CallBack); 
 iRetVal = NIDAQErrorHandler(iStatus, "Config_DAQ_Event_Message", iIgnoreWarning);
 /* Read 100 elements from Dig Port 0 (And check for our 1 on line 0) */
 iStatus = DIG_SCAN_Setup(iDevice, iGroup, 1, portList, 0);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_SCAN_Setup", iIgnoreWarning);
 iStatus = DIG_Block_In(iDevice, iGroup, piBuffer, 1000);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In", iIgnoreWarning);
 iStatus2 = DIG_In_Prt(iDevice, iPort2, &iPattern2);
    printf(" The digital pattern on port %d is (DECIMAL) %ld\n", iPort2, iPattern2);
 char ckey;
  while (TRUE) //stay here forever for event test
 {
  if (DAQEventFlag)
  {                
   DAQEventFlag = FALSE;
   printf("Hit c key to disable callback, other key for continue events \n"); /* Print how many interrupts we saw */
   ckey = getchar();
   if (ckey == 'c')
    {
     printf("c key has been hit \n");
     i16 iDevice = 1;
     CleanupNIDAQEvents(iDevice);
    }
  }//end of if (DAQEventFlag)
 }//end while (TRUE) //stay here forever for interrupt
}//end main

void CallBack (int handle, int msg, unsigned wParam, unsigned long lParam)
{
  iStatus2 = DIG_In_Prt(iDevice, iPort2, &iPattern2);
  iRetVal = NIDAQErrorHandler(iStatus2, "DIG_In_Prt", iIgnoreWarning);
  printf("portB value----> %d \n",iPattern2);
   DAQEventFlag = TRUE;
}

void CleanupNIDAQEvents(short iDevice)
{
 i16 iStatus = 0,
  iRetVal = 0,
  ignoreWarning = 0;
 DAQ_Clear(iDevice);
 printf("\nCleaning up DAQ Event\n");// for testing DAQ brd is really cleaned
 
 /*** CLEAR all DAQ Events! ***/
 iStatus = Config_DAQ_Event_Message (1, 0, "",
  1, 0, 0, 0, 0, 0, 0, 0, 0);
 iRetVal = NIDAQErrorHandler(iStatus, "Config_DAQ_Event_Message", ignoreWarning);
}
0 Kudos
Message 1 of 2
(3,123 Views)

Dear Lmai,

There is an example on ni.com called Using DAQ Event 8 to Send a Message When a Digital Pattern is Matched in Visual C++ that demonstrates how to correctly use Config_DAQ_Event_Message with Event 8. This will help you troubleshoot board/code/driver issues. Have a great day!

Sincerely,

Marni S.

0 Kudos
Message 2 of 2
(3,100 Views)