public string WaitForNewLine(int timeout) { sp.ReadTimeout = timeout; try { string newline = ""; while (true) { int newb = sp.ReadByte(); //Console.Write("Rx: " + newb.ToString("X2") + "\t " + newb.ToString() + "\t" + System.Text.Encoding.UTF8.GetString(new byte[] { (byte)newb })+"\t"); if (newb == 0x03 || newb == '\r') { continue; } if (newb == 0x0A) { break; } string newdata = System.Text.Encoding.UTF8.GetString(new byte[] { (byte)newb }); newline += newdata; } return(newline); } catch (Exception e) { MainGUI.LogLine("Serial Port error:" + e.Message); return(null); } }
/* public int Where(StageAxis axis, ref double[] where) * { * string command = GetStageString(axis); * string precision = stagePrecision; * * return 0; * }*/ public int SetSpeed(StageAxis axis, Int32[] speeds) { string command = GetStageString(axis); string precision = "H"; string numbers = ""; if (axis == StageAxis.Z) { numbers = "Z=" + speeds[0].ToString(); } else if (axis == StageAxis.XY) { numbers = "X=" + speeds[0].ToString() + " Y=" + speeds[1].ToString(); } command += precision + "S " + numbers; MainGUI.LogLine(command); if (sp.IsOpen) { string old = sp.ReadExisting(); sp.Write(command + "\r"); } string result = WaitForNewLine(standardTimeout); MainGUI.LogLine(result); return(0); }
public double[] GetStagePosition(StageAxis axis) { string command = GetStageString(axis); string precision = "H"; command += precision + "W "; string whichaxis = ""; if (axis == StageAxis.Z) { whichaxis = "Z"; } else if (axis == StageAxis.XY) { whichaxis = "X Y"; } command += whichaxis; MainGUI.LogLine(command); if (sp.IsOpen) { string old = sp.ReadExisting(); sp.Write(command + "\r"); } string result = WaitForNewLine(standardTimeout); if (result.Length <= 3) { result = WaitForNewLine(standardTimeout); } if (result == "Unknown") { return(null); } double[] retInt = null; if (axis == StageAxis.Z) { double zpos = 0; string zpart = result.Substring(2); zpos = Convert.ToDouble(zpart); retInt = new double[] { zpos }; } else if (axis == StageAxis.XY) { double xpos = 0, ypos = 0; string zpart = result.Substring(3);//remove :A_ string[] nums = zpart.Split(' '); xpos = Convert.ToDouble(nums[0]); ypos = Convert.ToDouble(nums[1]); retInt = new double[] { xpos, ypos }; } return(retInt); }
public void Disable() { if (EFDPort == null || !EFDPort.IsOpen) { MainGUI.LogLine("EFD Port closed already"); return; } EFDPort.WriteLine("0"); MainGUI.LogLine("EFD Port Disable"); }
public void Enable() { if (EFDPort == null || !EFDPort.IsOpen) { MainGUI.LogLine("EFD Port closed"); return; } EFDPort.WriteLine("1"); MainGUI.LogLine("EFD Port Enable"); }
public EFDControl(string name) { try { EFDPort = new SerialPort(name, 9600); EFDPort.Open(); } catch (Exception e) { EFDPort = null; MainGUI.LogLine("EFD Port failed to open " + name); return; } MainGUI.LogLine("EFD Port Created.... Opening Port " + name); }
public StageController(string name) { try { sp = new SerialPort(name, 115200); sp.Open(); } catch (Exception e) { sp = null; MainGUI.LogLine("StageController Port failed to open " + name); return; } MainGUI.LogLine("StageController Port Created.... Opening Port " + name); }
public StageController() { MainGUI.LogLine("Using Existing Port"); }