-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_nidaq.cpp
102 lines (87 loc) · 3.66 KB
/
test_nidaq.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int main(void){
int error=0;
TaskHandle taskHandle=0;
float64 data[4000];
float64 data2[8000];
char errBuff[2048]={'\0'};
int i=0;
int32 written;
for(;i<4000;i++) {
data[i] = 5.0*(double)i/4000.0;
data2[3999 - i] = 5.0*(double)i/4000.0;
}
i = 0;
for(;i<4000;i++) {
data2[4000 + i] = 5.0 * (double)i/4000.0;
}
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
//DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(taskHandle,"PFI1",DAQmx_Val_Rising));
DAQmxErrChk (DAQmxCfgOutputBuffer(taskHandle, 4000));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"PFI0",1000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,3999));
/*********************************************/
// DAQmx Write Code
/*********************************************/
DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,3999,0,10.0,DAQmx_Val_GroupByChannel,data2,&written,NULL));
printf("Written: %li\n", written);
//DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,4000,0,10.0,DAQmx_Val_GroupByChannel,data2,&written,NULL));
//printf("Written: %li\n", written);
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Wait Code
/*********************************************/
DAQmxErrChk (DAQmxWaitUntilTaskDone(taskHandle,120.0));
/*********************************************/
// DAQmx Write Code
/*********************************************/
DAQmxErrChk(DAQmxStopTask(taskHandle));
//DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,8000,0,10.0,DAQmx_Val_GroupByChannel,data2,&written,NULL));
// printf("Written: %li\n", written);
// DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"PFI0",1000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,4000));
/*********************************************/
// DAQmx Start Code
/*********************************************/
//DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Wait Code
/*********************************************/
//DAQmxErrChk (DAQmxWaitUntilTaskDone(taskHandle,20.0));
// DAQmxErrChk(DAQmxStopTask(taskHandle));
// DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,4000,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL));
/*********************************************/
// DAQmx Start Code
/*********************************************/
//DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Wait Code
/*********************************************/
//DAQmxErrChk (DAQmxWaitUntilTaskDone(taskHandle,20.0));
// DAQmxErrChk(DAQmxStopTask(taskHandle)); */
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
fflush(stdout);
printf("End of program, press Enter key to quit\n");
fflush(stdout);
getchar();
return 0;
}