-
Notifications
You must be signed in to change notification settings - Fork 0
/
DexNiDaqTargets.cpp
99 lines (69 loc) · 3.02 KB
/
DexNiDaqTargets.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
/***************************************************************************/
/* */
/* DexNiDaqTargets */
/* */
/***************************************************************************/
// This is the interface to a NiDaq digital outputs.
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <NIDAQmx.h>
#include <fMessageBox.h>
#include <VectorsMixin.h>
#include <DexTimers.h>
#include <Dexterous.h>
#include "DexTargets.h"
/*********************************************************************************/
void DexNiDaqTargets::ReportNiDaqError ( void ) {
char errBuff[2048]={'\0'};
DAQmxGetExtendedErrorInfo( errBuff, 2048);
fMessageBox( MB_OK, "DexNiDaqADC", errBuff );
}
DexNiDaqTargets::DexNiDaqTargets( void ) {
nVerticalTargets = N_VERTICAL_TARGETS;
nHorizontalTargets = N_HORIZONTAL_TARGETS;
nTargets = nVerticalTargets + nHorizontalTargets;
screen_targets = new DexScreenTargets( nVerticalTargets, nHorizontalTargets );
}
void DexNiDaqTargets::Initialize( void ) {
char channel_range[32];
int32 error_code;
// Define the channels to be acquired.
// NI-DAQ uses this string based method to select channels.
// We need 23 bits to cover the horizontal and vertical channels,
// so we need 3 8-bit ports.
sprintf( channel_range, "Dev1/port0:2" );
// Initialize the ports for digital output.
error_code = DAQmxCreateTask("",&taskHandle);
if( DAQmxFailed( error_code ) ) ReportNiDaqError();
// Set to treat all digital lines as a single multi-bit channel..
error_code = DAQmxCreateDOChan(taskHandle, channel_range, "", DAQmx_Val_ChanForAllLines );
if( DAQmxFailed( error_code ) ) ReportNiDaqError();
// Here we don't set a clock. The read will read all the channels once as quickly as possible.
// Initialize the screen targets that we run in parallel.
screen_targets->Initialize();
}
void DexNiDaqTargets::SetTargetStateInternal( unsigned long state ) {
int32 channels_written;
DAQmxWriteDigitalU32( taskHandle, 1, true, 1.0, DAQmx_Val_GroupByScanNumber, &state, &channels_written, NULL );
screen_targets->SetTargetStateInternal( state );
}
int DexNiDaqTargets::Update( void ) {
return ( screen_targets->Update() );
}
void DexNiDaqTargets::Quit( void ) {
int32 error_code;
if( taskHandle!=0 ) {
// I think that the task stops itself after the read, but I'm not sure.
// In any case, it doesn't seem to hurt to do this.
error_code = DAQmxStopTask(taskHandle);
if( DAQmxFailed( error_code )) ReportNiDaqError();
// I don't know what happens if you don't clear a task before leaving,
// but the NI examples says to do it, so I do it.
error_code = DAQmxClearTask(taskHandle);
if( DAQmxFailed( error_code ) ) ReportNiDaqError();
}
screen_targets->Quit();
}