11-15-2022 08:46 PM - edited 11-15-2022 09:02 PM
Hi,
I got one NI device, the model is 6259. The device is useful and reliable. Task created in NI MAX accquired data successfully.
I learnt from a demo in "C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Count Digital Events\Cnt Dig Events\CntDigEv.c".
After confoguring the device("Dev1/ctr1"), channel("PFI12") and clock source("100kHzTimebase"), no error occured when compiling, while no data was accquired by running the task.
Could anyone help me to figure out what the problem is ?
Below shows the code i use. The source file is also attached.
#include <stdio.h>
#include "NIDAQmx.h"
int re;
TaskHandle taskHandle;
uInt32 data[1000000];
int main(void)
{
taskHandle = 0;
// DAQmx Configure Code
re = DAQmxCreateTask("", &taskHandle);
if (re == 0) printf("task created!\r\n");
else printf("task create failed!error code:%u\r\n",re);
re = DAQmxCreateCICountEdgesChan(taskHandle, "Dev1/ctr1", "PFI12", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp); //PFI12
if (re == 0) printf("count channel selected!\r\n");
else printf("count channel failed!error code:%d\r\n", re);
re = DAQmxCfgSampClkTiming(taskHandle, "100kHzTimebase ", 100000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000000);
if (re == 0) printf("clock sed!\r\n");
else printf("clock setting failed!error code:%d\r\n", re);
// DAQmx Start Code
re = DAQmxStartTask(taskHandle);
if (re == 0) printf("task start!\r\n");
else printf("task not started !error code:%d\r\n", re);
printf("collecting data,Ctrl+C to interrupt\r\n");
for (int i = 0; i < 1000000; i++) {
re = DAQmxReadCounterScalarU32(taskHandle, -1, &data[i], NULL);
if (re != 0) printf("accquire failed!error code:%d\r\n", re);
if (data[i] > 0)
{
printf("\rCount: %u-%u",i, (unsigned int)data[i]);
}
else printf("\rinvalid count input ");
//fflush(stdout);
}
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
return 0;
}
And the feedback is as follows:
task created!
count channel selected!
clock set!
task start!
collecting data,Ctrl+C to interrupt
invalid count input