-
Notifications
You must be signed in to change notification settings - Fork 0
/
stageControlXY.cpp
150 lines (116 loc) · 2.87 KB
/
stageControlXY.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//#using <mscorlib.dll>
//#include <vcclr.h>
#include <QString>
#include "globals.h"
#include "MarzController.h"
#include "StageControlXY.h"
/*
#using <System.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::IO::Ports;
using namespace System::Runtime::InteropServices;
*/
StageControlXY::StageControlXY()
{
m_COMPort = "";
m_pMarz = new MarzController(this);
}
StageControlXY::~StageControlXY()
{
if (m_pMarz != nullptr)
delete m_pMarz;
}
bool StageControlXY::Connect()
{
if (m_COMPort == "")
return false;
if (m_COMPort != "")
if (m_pMarz->connectToPort(m_COMPort))
emit STAGECONNECTED(true, m_COMPort);
emit ACTIONCOMPLETED("XY stage connected");
}
void StageControlXY::Disconnect()
{
m_pMarz->disconnect();
emit STAGECONNECTED(true, "?");
emit ACTIONCOMPLETED("XY stage disconnected");
}
// detect the COM port and connect Stage to it
void StageControlXY::assignPort(QVector<QString> AvailablePorts, QString excludePort)
{
for (int i = 0; i < AvailablePorts.length(); i++)
{
if (AvailablePorts[i] == excludePort)
continue;
if (m_pMarz->connectToPort(AvailablePorts[i]))
{
m_COMPort = AvailablePorts[i];
break;
}
}
emit CONNECTEDTOPORT(m_COMPort);
}
void StageControlXY::MoveAbsolute(double x, double y, ACTIONS::action act)
{
m_pMarz->moveAsolute(x, y);
if (act == ACTIONS::nothing)
emit ACTIONCOMPLETED("move absolute XY completed");
else
emit STAGEMOVED(x, y, act);
}
void StageControlXY::MoveRelative(double x, double y, ACTIONS::action act)
{
m_pMarz->MoveRelative(x, y);
if (act == ACTIONS::nothing)
emit ACTIONCOMPLETED("move relative complete");
else
emit STAGEMOVED(x, y, act);
}
void StageControlXY::go(double fx, double fy)
{
m_pMarz->mouseMove(fx, fy);
emit ACTIONCOMPLETED("go to " + QString::number(fx) + " " + QString::number(fy));
}
void StageControlXY::SendCommand(QString cmd)
{
m_pMarz->sendCommand(cmd);
emit ACTIONCOMPLETED("command " + cmd + " completed");
}
void StageControlXY::SetVelocity(double velo)
{
m_pMarz->setVelocity(velo);
emit ACTIONCOMPLETED("set velocity complete");
}
void StageControlXY::SetJoystick(bool on)
{
m_pMarz->setJoystick(on);
QString state = (on ? "on" : "off");
emit ACTIONCOMPLETED("set joystick " + state +" complete");
}
void StageControlXY::Calibrate()
{
m_pMarz->calibrateXY();
emit ACTIONCOMPLETED("calibration complete");
}
void StageControlXY::MeasureRange()
{
m_pMarz->measureRangeXY();
emit ACTIONCOMPLETED("range measurement complete");
}
void StageControlXY::Abort()
{
m_pMarz->abortXY();
emit ACTIONCOMPLETED("XY stage command aborted");
}
void StageControlXY::updatePositions(bool bFiducial)
{
double x, y;
m_pMarz->getPosition(x, y);
emit UPDATEPOSITIONS(bFiducial, x, y);
emit ACTIONCOMPLETED("XY get position");
}
void StageControlXY::updatePositions(double x, double y)
{
emit UPDATEPOSITIONS(false, x, y);
}