-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTalk2Galvo.cpp
97 lines (75 loc) · 1.9 KB
/
Talk2Galvo.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
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include "Talk2Galvo.h"
void GalvoData::handleDAQError(int error)
{
char errBuff[2048] = { '\0' };
if (DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle1 != 0)
{
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle1);
DAQmxClearTask(taskHandle1);
}
if (DAQmxFailed(error))
printf("DAQmx Error: %s\n", errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
}
bool GalvoData::initialize()
{
int error = 0;
error = DAQmxCreateTask("", &taskHandle1);
if (error != 0)
{
handleDAQError(error);
printf("ERROR! Cannot control the stage with DAQ card.\n");
taskHandle1 = NULL;
return false;
}
error = DAQmxCreateAOVoltageChan(taskHandle1, "Dev3/ao0:1", "", -5.0, 5.0, DAQmx_Val_Volts, "");
if (error != 0)
{
handleDAQError(error);
printf("ERROR! Cannot control the stage with DAQ card.\n");
taskHandle1 = NULL;
return false;
}
//The first value is as large as possible and the second value is as small as possible
error = DAQmxCfgSampClkTiming(taskHandle1, "", 50000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 5000);
if (error != 0)
{
handleDAQError(error);
printf("ERROR! Cannot control the stage with DAQ card.\n");
taskHandle1 = NULL;
return false;
}
error = DAQmxStartTask(taskHandle1);
if (error != 0)
{
handleDAQError(error);
printf("ERROR! Invoking the stage failed.\n");
return false;
}
return true;
}
int GalvoData::spinGalvo(cv::Point2f pt)
{
int32 written;
int error = 0;
double data[2];
data[0] = pt.x;
data[1] = pt.y;
error = DAQmxWriteAnalogF64(taskHandle1, 1, 0, 10.0, DAQmx_Val_GroupByChannel, data, &written, NULL);
if (error != 0)
{
handleDAQError(error);
printf("ERROR! cannot send speed control commands.\n");
return -1;
}
return 0;
}