Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-DAQ register signal event isn't functioning in C++ (Error -200982)

I'm currently attempting to have a NI-DAQ read an external trigger in the digital input PFI1, but I get an error -200982 when I run the line:

(DAQmxRegisterSignalEvent(taskHandle, DAQmx_Val_SampleClock, 0, SaveViconData, NULL));

The error states

DAQmx Signal Events are not supported by your device. DAQmx Signal events include the Counter Output event, the Sample Complete Event, the Sample Clock Event, and the Digital Change Detection event.>

but I have created this function using MATLAB fine so I don't think there's an issue with the hardware so I believe I must be making a mistake somewhere as I am quite new to using C++.

The code used is:

int32       error = 0;
static TaskHandle  taskHandle;
int32       read;
float64     data[1000];
char        errBuff[2048] = { '\0' };
using namespace std;
 
int32 CVICALLBACK   SaveViconData(TaskHandle taskHandle, int32 signalID, void* callbackData)
{
    using namespace std;

   cout << "Function triggered\n";
   DAQmxStopTask(taskHandle);
   DAQmxClearTask(taskHandle);
   cout<< "taskHandle\n" <<  flush;
   chrono::seconds dura(1);
   DAQmxStartTask(taskHandle);
    return 0;
}

int main(void)
{
    DAQmxErrChk(DAQmxCreateTask("", &taskHandle)); //d = daq("ni");
    DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "Voltage", DAQmx_Val_RSE, -10.0, 10.0, DAQmx_Val_Volts, NULL)); //ch=addinput(d, "Dev1", 'ai0','Voltage');
    DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle, "PFI1", DAQmx_Val_Falling)); //addtrigger(d, "Digital", "StartTrigger", "External", "Dev1/PFI1");
    DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, NULL, 500.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000)); //change to finite if this doesn't work
    DAQmxErrChk(DAQmxRegisterSignalEvent(taskHandle, DAQmx_Val_SampleClock, 0, SaveViconData, NULL)); //https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/daqmxcfunc/daqmxregistersignalevent.html
    DAQmxStartTask(taskHandle);
    DAQmxWaitUntilTaskDone(taskHandle, 10); // Wait for action to be completed


Error:
    if (DAQmxFailed(error))
        DAQmxGetExtendedErrorInfo(errBuff, 2048);
    if (taskHandle != 0) {
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
    if (DAQmxFailed(error))
        printf("DAQmx Error: %s\n", errBuff);
    return 0;
}

and I'm using a USB-6003 NI-DAQ. Any help would be appreciated

 

0 Kudos
Message 1 of 1
(1,473 Views)