Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

PCI-6503 callback


yI am trying to develop with the PCI-DIO-24 (PCI-6503) in VC6  / Ni-DAQ version 7.4. I simply want a function to be called when a digital input goes high or low. but the callback function always be no  response.Have anybody can help me to find what's wrong?

my code: basis of  DAQTest.zip
#include <afx.h>
#include <afxwin.h>         // MFC core and standard components
#include "nidaqex.h"
#include <iostream>
using namespace std;

void __stdcall OnDataCallback(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam) ;

void main(void)
{
    int nRetCode = 0;// initialize MFC and print and error on failure
 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
 {
  cerr << _T("Fatal Error: MFC initialization failed") << endl;
  return;
 }
    i16 iStatus = 0, iRetVal = 0, iDBmodeON = 1, iDBmodeOFF = 0, iDevCode = 0;
 i16 iSampTB = 0;    u16 uSampInt = 0;
 i16 iHalfReady = 0;    i16 iDAQstopped = 0;   u32 ulPtsTfr = 0;    i16 iIgnoreWarning = 0;
 
 i16 iGain = 1; i16 iUnits = 0;    
u32 ulCount = 1000;  f64 dSampRate = 2.0; 
static i16 piHalfBuffer[50000] = {0};
 i32 lTimeout = 180;

 i16 iDevice = 1; 
 iStatus = Init_DA_Brds(iDevice, &iDevCode);
 iRetVal = NIDAQErrorHandler(iStatus, "Init_DA_Brds", iIgnoreWarning);

 i16 iChan = 0; 
 int iMode = 1;
 int iDirection = 0;
 iStatus=DIG_Prt_Config(iDevice,iChan,iMode, iDirection);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_Prt_Config", iIgnoreWarning);

 CString strChan;
 strChan.Format("DI%-d",iChan); 
 const int nMaxStrChan = 128;
 i8 FAR chanStr[nMaxStrChan]; memset(chanStr, 0, nMaxStrChan);
 strcpy(chanStr, (LPCSTR)strChan);

 i16 nDAQEvent = 8, nAddMode = 1;  
 i32 nTrigVal0 = 1, nTrigVal1=0,nIgnor = 0;
 iStatus = Config_DAQ_Event_Message( iDevice,nAddMode, chanStr,nDAQEvent, nTrigVal0, nTrigVal1, nIgnor, nIgnor, nIgnor,  NULL, NULL,  (unsigned long)(&OnDataCallback));
 iRetVal = NIDAQErrorHandler(iStatus, "Config_DAQ_Event_Message", iIgnoreWarning);

  i16 iGroup = 0;
 i16 iGroupsize = 1;
 static i16 portList[1] = {0};

 iStatus = DIG_SCAN_Setup(iDevice, iGroup, iGroupsize, portList, iDirection);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_SCAN_Setup", iIgnoreWarning);
 
 static i16 piBuffer[100] = {0};//accept 100 items only
 iStatus = DIG_Block_In(iDevice, iGroup, piBuffer, 1000);
 iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In", iIgnoreWarning);

    printf(" Continuous acquisition has started.\n");
    printf(" HINT: You can add your own graphing calls in the while loop.\n");
 TRACE(" Continuous acquisition has started.\n");
    TRACE(" HINT: You can add your own graphing calls in the while loop.\n");
 
    while (iLoopCount <10)
 {
  if (iLoopCount)
  {
   printf(" get call back %d!\n",iLoopCount);
   break;
   iLoopCount++;
  }
  ::Sleep(5);
    }

    printf(" Continuous acquisition is done!\n");
 TRACE(" Continuous acquisition is done!\n");
    /* CLEANUP - Don't check for errors on purpose. */
    iStatus = DAQ_Clear(iDevice);
    iStatus = DAQ_DB_Config(iDevice, iDBmodeOFF);
    iStatus = Timeout_Config(iDevice, -1);
}

void __stdcall OnDataCallback(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam)
{
 i32 iPattern=0;
 DIG_In_Prt(1,0,&iPattern);
 iLoopCount++;
// TRACE("CNIDAQBoard::OnDataCallback #%d\n", iLoopCount );
 return;
}

 

0 Kudos
Message 1 of 2
(2,940 Views)

I suggest you install NI-DAQmx instead of traditional DAQ.

http://digital.ni.com/public.nsf/allkb/FB26BDA52FFFD4EE86257124005C36C3

0 Kudos
Message 2 of 2
(2,909 Views)