示例#1
0
 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);
     }
 }
示例#2
0
        /* 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);
        }
示例#3
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);
        }
示例#4
0
 public void Disable()
 {
     if (EFDPort == null || !EFDPort.IsOpen)
     {
         MainGUI.LogLine("EFD Port closed already");
         return;
     }
     EFDPort.WriteLine("0");
     MainGUI.LogLine("EFD Port Disable");
 }
示例#5
0
 public void Enable()
 {
     if (EFDPort == null || !EFDPort.IsOpen)
     {
         MainGUI.LogLine("EFD Port closed");
         return;
     }
     EFDPort.WriteLine("1");
     MainGUI.LogLine("EFD Port Enable");
 }
示例#6
0
 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);
 }
示例#7
0
 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);
 }
示例#8
0
        public MainGUI()
        {
            this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
            InitializeComponent();
            textboxInc.Text          = "1";
            textboxSpeed.Text        = "1";
            openFileDialog1.FileName = "test.txt";
            string[] names = SerialPort.GetPortNames();

            /*comboBoxStagePorts.Items.Add("COM1");//Debug
             * comboBoxStagePorts.Items.Add("COM2");//Debug
             * comboBoxEFDPortNames.Items.Add("COM4");//Debug
             * comboBoxEFDPortNames.Items.Add("COM3");//Debug
             */
            //string selectedStage = (string)Properties.Settings.Default["StagePort"];
            //string selectedEFD = (string)Properties.Settings.Default["EFDPort"];
            string selectedStage = GetPort("StagePort");
            string selectedEFD   = GetPort("EFDPort");

            MainGUI.FillComboBoxNames(names, comboBoxStagePorts, selectedStage);
            MainGUI.FillComboBoxNames(names, comboBoxEFDPortNames, selectedEFD);
            ShowConsole.ShowConsoleWindow();
        }
示例#9
0
 public StageController()
 {
     MainGUI.LogLine("Using Existing Port");
 }