Discussion:
??? How can I use CallBack in GUI VC++ MFC
(too old to reply)
adifly
2008-03-26 02:40:06 UTC
Permalink
I try your code! also can't  use callback function.
Have anybody can hely me?
MY hardward: PCI-6503
soft:VC 6
 
 
adifly
2008-03-28 03:10:08 UTC
Permalink
hi Nick F.
My brd is:NiDAQ DIO24 (6503),
I send trigger to  portA bit0.
when I use "Measurement & Automation" AP to get trigger, it is ok to get trigger!
But run my code  to callback is fail.
need help to tell me what is wrong?
thanks
 
MY code :
#include "nidaqex.h"#include "nidaq.h"//typedef void (* CALLBACK) (int , int , unsigned , unsigned long )void CallBackfun (int handle, int msg, unsigned wParam, unsigned long lParam);
i16 iNum = 0;i16 temp;
/* ================================================================= */void main (void)
{  /*Local Variable Declarations*/  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);
 /* Sets up so a 1 on digital port 0, line 0 generates a interrupt */ iStatus = Config_DAQ_Event_Message (iDevice, 1, "DI0", 8, 1, 1, 0, 0, 0, 0, 0, (unsigned long)&CallBackfun); //
//iStatus = Config_DAQ_Event_Message (iDevice, 1, "DI0", 8, 2, 2, 0, 0, 0, 0, 0, (unsigned long)CallBack); //I  try it but result  is  fail
//
 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, 100);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In", iIgnoreWarning);
 
 while (ulRemain > 0 && i < 1000)
{   iStatus=DIG_Block_Check (iDevice, iGroup, &ulRemain);
  iRetVal=NIDAQYield(iYieldOn);
  i++;  printf("# of events generated %d.\n", iNum); /* Print how many interrupts we saw */    }
 if (ulRemain == 100 && i == 1000) {
  printf("No STB provided.\n");    }
 else {
  printf("Operation completed.\n");    }
  getchar();}
/* ================================================================= */void CallBackfun (int handle, int msg, unsigned wParam, unsigned long lParam){  iNum++; //<==I set breakpoint in here.but no any response.}
 
 
Nick F
2008-03-28 22:10:08 UTC
Permalink
Hi adifly, If you go to C:\Program Files\National Instruments\NI-DAQ\Include\ you can find "nidaq.h" which is the header file for our DAQ drivers.  If you look up that functionin the header file, you will see that the last parameter is an unsigned integer which is the address of the function call.  You can also find information about this function by going to the DAQ help through Start >> All Programs >> National Instruments >> NI-DAQ >> Tradidional NI-DAQ Function Reference Help.  If you click on the Index tab and type in the function name, it will show you information on that function.  Hopefully this will help you debug why you are not able to run the callback function.
Loading...