15 public static Process deviceServer;
16 public static PointD location;
17 public static double focus;
18 public static string run_cmd(
string cmd,
string args)
20 ProcessStartInfo start =
new ProcessStartInfo();
21 start.FileName =
"python.exe";
22 start.Arguments =
string.Format(
"{0} {1}", cmd, args);
23 start.WorkingDirectory = Application.StartupPath +
"/PythonMicroscope/microscope";
24 start.UseShellExecute =
false;
25 start.RedirectStandardOutput =
true;
26 start.CreateNoWindow =
true;
28 using (Process process = Process.Start(start))
30 using (StreamReader reader = process.StandardOutput)
32 res = reader.ReadToEnd();
36 Application.DoEvents();
39 public static void StartCommand(
string cmd,
string args)
41 ProcessStartInfo start =
new ProcessStartInfo();
42 start.FileName =
"python.exe";
43 start.Arguments =
string.Format(
"{0} {1}", cmd, args);
44 start.WorkingDirectory = Application.StartupPath +
"/PythonMicroscope/microscope";
45 start.UseShellExecute =
false;
46 start.RedirectStandardOutput =
true;
47 start.CreateNoWindow =
false;
49 public static void Start()
51 ProcessStartInfo start =
new ProcessStartInfo();
52 start.FileName =
"python.exe";
53 start.Arguments =
string.Format(
"{0} {1}",
"device_server.py",
"config.txt");
54 start.WorkingDirectory = Application.StartupPath +
"/PythonMicroscope/microscope";
55 start.UseShellExecute =
false;
56 start.RedirectStandardOutput =
false;
57 start.CreateNoWindow =
false;
58 deviceServer = Process.Start(start);
60 public static void Stop()
62 if(deviceServer!=
null)
63 if(!deviceServer.HasExited)
66 public bool Initialize()
70 string s = run_cmd(
"initialize.py", Properties.Settings.Default.PStage);
71 if (!s.Contains(
"OK"))
76 public bool SetPosition(Point3D p)
78 string s = run_cmd(
"setstagexyz.py", Properties.Settings.Default.PStage +
" " + p.X +
" " + p.Y +
" " + p.Z);
82 location =
new PointD(p.X, p.Y);
88 public bool SetPosition(PointD p)
90 string s = run_cmd(
"setstagexy.py", Properties.Settings.Default.PStage +
" " + p.X +
" " + p.Y);
99 public bool GetPosition3D(out Point3D p,
bool update)
103 p =
new Point3D(location.X, location.Y, focus);
106 string s = run_cmd(
"getstagexyz.py", Properties.Settings.Default.PStage);
107 if (s.Contains(
"OK"))
109 string[] sts = s.Split();
110 p =
new Point3D(
double.Parse(sts[0]),
double.Parse(sts[2]),
double.Parse(sts[4]));
120 public bool GetPosition(out PointD p,
bool update)
127 string s = run_cmd(
"getstagexy.py", Properties.Settings.Default.PStage);
128 if (s.Contains(
"OK"))
130 string[] sts = s.Split();
131 p =
new PointD(
double.Parse(sts[0]),
double.Parse(sts[2]));
141 public bool SetFilterWheelPosition(
int p)
143 string s = run_cmd(
"setfilterwheel.py", Properties.Settings.Default.PFilterWheel +
" " + p);
144 if (s.Contains(
"OK"))
149 public bool GetFilterWheelPosition(out
int p)
151 string s = run_cmd(
"getfilterwheel.py", Properties.Settings.Default.PFilterWheel);
152 if (s.Contains(
"OK"))
154 string[] sts = s.Split();
155 p =
int.Parse(sts[2]);
164 public bool TakeImage(
string path)
166 string s = run_cmd(
"takeimage.py", path);
167 if (s.Contains(
"OK"))
172 public bool SetExposure(
float f)
174 string s = run_cmd(
"setexposure.py", f.ToString());
175 if (s.Contains(
"OK"))
180 public bool GetSize(out
int width, out
int height)
182 string s = run_cmd(
"getcamrect.py",Properties.Settings.Default.PCamera);
185 if (!s.Contains(
"OK"))
187 string[] sts = s.Split();
188 width =
int.Parse(sts[0]);
189 height =
int.Parse(sts[2]);