2using System.Collections.Generic;
3using System.ComponentModel;
9using System.Windows.Forms;
11using System.Runtime.CompilerServices;
12using System.Runtime.InteropServices;
19 [DllImport(
"PriorScientificSDK.dll", CallingConvention = CallingConvention.Cdecl)]
22 [DllImport(
"PriorScientificSDK.dll", CallingConvention = CallingConvention.Cdecl)]
25 [DllImport(
"PriorScientificSDK.dll", CallingConvention = CallingConvention.Cdecl)]
28 [DllImport(
"PriorScientificSDK.dll", CallingConvention = CallingConvention.Cdecl)]
31 [DllImport(
"PriorScientificSDK.dll", CallingConvention = CallingConvention.Cdecl)]
38 StringBuilder dllVersion =
new StringBuilder();
46 private void Form1_Load(
object sender, EventArgs e)
51 MessageBox.Show(
"Error getting Prior SDK version (" + err.ToString() +
")");
56 if ((err = priorSDK.
Initialise()) != Prior.PRIOR_OK)
58 MessageBox.Show(
"Error initialising Prior SDK (" + err.ToString() +
")");
67 MessageBox.Show(
"Error (" + sessionID.ToString() +
") Creating session in SDK " + dllVersion);
81 open = priorSDK.
Cmd(sessionID,
"controller.connect " + port.ToString(), ref userRx,
false);
84 if (open != Prior.PRIOR_OK)
86 MessageBox.Show(
"Error (" +
open.ToString() +
") connecting to stage controller ",
"",
87 MessageBoxButtons.OK, MessageBoxIcon.Error);
98 err = priorSDK.
Cmd(sessionID,
"controller.stage.hostdirection.set -1 1", ref userRx);
102 private void Form1_FormClosing(
object sender, FormClosingEventArgs e)
106 err = priorSDK.
Cmd(sessionID,
"controller.disconnect", ref userRx);
110 private void systemCheck()
114 err = priorSDK.
Cmd(sessionID,
"controller.stage.name.get", ref userRx);
116 err = priorSDK.
Cmd(sessionID,
"controller.z.name.get", ref userRx);
125 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.move-at-velocity " +
126 (-10000).ToString() +
" " + (-10000).ToString(), ref userRx)) !=
Prior.
PRIOR_OK)
134 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.position.set 0 0", ref userRx)) !=
Prior.
PRIOR_OK)
140 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.goto-position 1000 1000", ref userRx)) !=
Prior.
PRIOR_OK)
149 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.position.set "+ p.X +
" " + p.Y, ref userRx)) !=
Prior.
PRIOR_OK)
158 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.position.get", ref userRx)) !=
Prior.
PRIOR_OK)
162 string[] sts = userRx.Split(
' ');
163 double dx =
double.Parse(sts[0]);
164 double yx =
double.Parse(sts[1]);
169 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.position.set " + p.X +
" " + p.Y, ref userRx)) !=
Prior.
PRIOR_OK)
174 if ((err = priorSDK.
Cmd(sessionID,
"controller.z.position.set " + p.Z, ref userRx)) !=
Prior.
PRIOR_OK)
176 throw new Exception(err.ToString());
184 if ((err = priorSDK.
Cmd(sessionID,
"controller.nosepiece.goto-position " + p, ref userRx)) !=
Prior.
PRIOR_OK)
193 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.position.get", ref userRx)) !=
Prior.
PRIOR_OK)
195 throw new Exception(err.ToString());
197 string[] sts = userRx.Split(
' ');
198 double dx =
double.Parse(sts[0]);
199 double yx =
double.Parse(sts[1]);
200 if ((err = priorSDK.
Cmd(sessionID,
"controller.z.position.get", ref userRx)) !=
Prior.
PRIOR_OK)
202 throw new Exception(err.ToString());
204 double zx =
double.Parse(userRx);
205 return new Point3D(dx, yx, zx);
210 if ((err = priorSDK.
Cmd(sessionID,
"controller.z.position.set " + d, ref userRx)) !=
Prior.
PRIOR_OK)
212 throw new Exception(err.ToString());
219 if ((err = priorSDK.
Cmd(sessionID,
"controller.z.position.get", ref userRx)) !=
Prior.
PRIOR_OK)
221 throw new Exception(err.ToString());
223 return double.Parse(userRx);
228 if ((err = priorSDK.
Cmd(sessionID,
"controller.nosepiece.position.set " + d, ref userRx)) !=
Prior.
PRIOR_OK)
230 throw new Exception(err.ToString());
237 if ((err = priorSDK.
Cmd(sessionID,
"controller.nosepiece.position.get", ref userRx)) !=
Prior.
PRIOR_OK)
239 throw new Exception(err.ToString());
241 return int.Parse(userRx);
245 if ((err = priorSDK.
Cmd(sessionID,
"controller.nosepiece.no-of-positions.get", ref userRx)) !=
Prior.
PRIOR_OK)
247 throw new Exception(err.ToString());
249 return int.Parse(userRx);
253 if ((err = priorSDK.
Cmd(sessionID,
"controller.stage.busy.get", ref userRx)) !=
Prior.
PRIOR_OK)
258 return Convert.ToInt32(userRx);
263 if ((err = priorSDK.
Cmd(sessionID,
"controller.z.busy.get", ref userRx)) !=
Prior.
PRIOR_OK)
268 return Convert.ToInt32(userRx);
272 if ((err = priorSDK.
Cmd(sessionID,
"controller.nosepiece.busy.get", ref userRx)) !=
Prior.
PRIOR_OK)
277 return Convert.ToInt32(userRx);
281 if ((err = priorSDK.
Cmd(sessionID,
"controller.shutter.open", ref userRx)) !=
Prior.
PRIOR_OK)
290 if ((err = priorSDK.
Cmd(sessionID,
"controller.shutter.close", ref userRx)) !=
Prior.
PRIOR_OK)
299 if ((err = priorSDK.
Cmd(sessionID,
"controller.shutter.state.get", ref userRx)) !=
Prior.
PRIOR_OK)
304 return int.Parse(userRx);
322 while (
zBusy() != 0);
354 public int Cmd(
int session,
string usertx, ref
string userrx,
bool displayError =
true)
358 StringBuilder tx =
new StringBuilder();
359 StringBuilder rx =
new StringBuilder();
366 userrx = rx.ToString();
372 MessageBox.Show(
"Sent " + usertx +
"\rSDK error: " + ret.ToString() );
System.Windows.Forms.Application Application
const int PRIOR_OK
SDK ERROR CODES returned directly by the SDk.
bool SetPosition(Point3D p)
static int PriorScientificSDK_CloseSession(int sessionID)
static int PriorScientificSDK_OpenNewSession()
void waitUntilStageIdle()
int CloseSession(int sessionID)
int Cmd(int session, string usertx, ref string userrx, bool displayError=true)
static int PriorScientificSDK_Initialise()
void waitUntilNosePieceIdle()
bool SetPosition(PointD p)
int GetNosePiecePositions()
static int PriorScientificSDK_Version(StringBuilder version)
int GetVersion(StringBuilder version)
static int PriorScientificSDK_cmd(int session, StringBuilder tx, StringBuilder rx)