示例#1
0
        // This event handler is where the actual,
        // potentially time-consuming work is done.
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;
            ThreadData myData = (ThreadData)e.Argument;
            string EFDPortName = myData.EFDName;
            EFDControl efd = new EFDControl(EFDPortName);
            efd.Disable();
            StageController stage;

            string COM = myData.StageName;
            if (COM != EFDPortName)//ugly hack for testing with 1 device
                stage = new StageController(COM);
            else
            {
                stage = new StageController();
                stage.sp = efd.EFDPort;
            }
            //SerialPort stage = null;
            // Directory Path
            //string Name = File_name.Text;
            string path = openFileDialog1.FileName;

            stage.ResetXYZ();
            stage.GetStatus();
            LogLine("Begin Program");
            Thread.Sleep(2000);

            StreamReader readFile = new StreamReader(path);
            while(!worker.CancellationPending)
            {
                string line;
                string[] data;
                line = readFile.ReadLine();
                if(line == null)
                {
                    LogLine("No more lines");
                    goto threadDone;
                }
                else
                {
                    LogLine("Read: "+line);
                    data = line.Split(',');
                    if(data.Length < 5)
                    {
                        LogLine("Not enough parameters");
                        goto threadDone;
                    }
                    const int scaler = 1;
                    Int32 iXPos = Convert.ToInt32(data[0]);
                    Int32 iYPos = Convert.ToInt32(data[1]);
                    Int32 iZPos = Convert.ToInt32(data[2]);
                    Int32 iSpeed = Convert.ToInt32(data[3]);
                    Int32 iEFD = Convert.ToInt32(data[4]);

                    iXPos *= scaler;
                    iYPos *= scaler;
                    iZPos *= scaler;

                    stage.SetSpeed(StageController.StageAxis.Z, new Int32[] { iSpeed });
                    stage.Move(StageController.StageAxis.Z, new Int32[] { iZPos });
                    int ztp, ztn;
                    ztp = iZPos + 10;
                    ztn = iZPos - 10;
                    while (!worker.CancellationPending)
                    {
                        double[] zpos = stage.GetStagePosition(StageController.StageAxis.Z);
                        LogLine("Z " + zpos[0].ToString());

                        double zloc = zpos[0];
                        if (zloc <= ztp && zloc > ztn)
                            break;
                    }
                    if (iEFD == 1)
                        efd.Enable();
                    else
                        efd.Disable();
                    stage.SetSpeed(StageController.StageAxis.XY, new Int32[] { iSpeed,iSpeed });
                    stage.Move(StageController.StageAxis.XY, new Int32[] { iXPos, iYPos });
                    int xtp, xtn,ytp,ytn;
                    xtp = iXPos + 10;
                    xtn = iXPos - 10;
                    ytp = iYPos + 10;
                    ytn = iYPos - 10;
                    while (!worker.CancellationPending)
                    {
                        double[] xypos = stage.GetStagePosition(StageController.StageAxis.XY);
                        LogLine("XY " + xypos[0].ToString() + " " + xypos[1].ToString());
                        double xloc = xypos[0];
                        double yloc = xypos[1];

                        if (xloc <= xtp && xloc > xtn
                            &&
                            yloc <= ytp && yloc > ytn)
                            break;
                    }
                    // Ensure Command was Successfull
                    //Thread.Sleep(1000);
                    //efd.Disable();
                }
            }
            threadDone:
            if(stage != null)
                stage.Shutdown(); // Close COM Port
            if (efd != null)
            {
                efd.Shutdown();
            }
            e.Cancel = true;
        }
示例#2
0
        private void buttonGetXY_Click(object sender, EventArgs e)
        {
            StageController stage = new StageController(comboBoxStagePorts.Text);
            double[] xy = stage.GetStagePosition(StageController.StageAxis.XY);
            string msg = "X = " + xy[0].ToString() + " Y = " + xy[1].ToString() +"H-um";
            MessageBox.Show(msg);
            stage.Shutdown();
            LogLine(msg);
            return;
            // Define Serial Port
            //string COM = inputCOM.Text;
            /*string COM = comboBoxStagePorts.Text;
            System.IO.Ports.SerialPort stage = new System.IO.Ports.SerialPort(COM, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);

            // Open Serial Port
            try
            {
                stage.Open();
            }
            catch(Exception err)
            {
                LogLine("Open failed " + err.Message);
                return;
            }
            // Request XY-position
            string xy_request = "2HW X Y\r";
            stage.Write(xy_request);

            // Read XY-position
            string msg = stage.ReadLine();
            MessageBox.Show(msg);

            // Close Serial Port
            stage.Close();*/
        }
示例#3
0
        // This event handler is where the actual,
        // potentially time-consuming work is done.
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker      = sender as BackgroundWorker;
            ThreadData       myData      = (ThreadData)e.Argument;
            string           EFDPortName = myData.EFDName;
            EFDControl       efd         = new EFDControl(EFDPortName);

            efd.Disable();
            StageController stage;

            string COM = myData.StageName;

            if (COM != EFDPortName)//ugly hack for testing with 1 device
            {
                stage = new StageController(COM);
            }
            else
            {
                stage    = new StageController();
                stage.sp = efd.EFDPort;
            }
            //SerialPort stage = null;
            // Directory Path
            //string Name = File_name.Text;
            string path = openFileDialog1.FileName;

            stage.ResetXYZ();
            stage.GetStatus();
            LogLine("Begin Program");
            Thread.Sleep(2000);

            StreamReader readFile = new StreamReader(path);

            while (!worker.CancellationPending)
            {
                string   line;
                string[] data;
                line = readFile.ReadLine();
                if (line == null)
                {
                    LogLine("No more lines");
                    goto threadDone;
                }
                else
                {
                    LogLine("Read: " + line);
                    data = line.Split(',');
                    if (data.Length < 5)
                    {
                        LogLine("Not enough parameters");
                        goto threadDone;
                    }
                    const int scaler = 1;
                    Int32     iXPos  = Convert.ToInt32(data[0]);
                    Int32     iYPos  = Convert.ToInt32(data[1]);
                    Int32     iZPos  = Convert.ToInt32(data[2]);
                    Int32     iSpeed = Convert.ToInt32(data[3]);
                    Int32     iEFD   = Convert.ToInt32(data[4]);

                    iXPos *= scaler;
                    iYPos *= scaler;
                    iZPos *= scaler;

                    stage.SetSpeed(StageController.StageAxis.Z, new Int32[] { iSpeed });
                    stage.Move(StageController.StageAxis.Z, new Int32[] { iZPos });
                    int ztp, ztn;
                    ztp = iZPos + 10;
                    ztn = iZPos - 10;
                    while (!worker.CancellationPending)
                    {
                        double[] zpos = stage.GetStagePosition(StageController.StageAxis.Z);
                        LogLine("Z " + zpos[0].ToString());

                        double zloc = zpos[0];
                        if (zloc <= ztp && zloc > ztn)
                        {
                            break;
                        }
                    }
                    if (iEFD == 1)
                    {
                        efd.Enable();
                    }
                    else
                    {
                        efd.Disable();
                    }
                    stage.SetSpeed(StageController.StageAxis.XY, new Int32[] { iSpeed, iSpeed });
                    stage.Move(StageController.StageAxis.XY, new Int32[] { iXPos, iYPos });
                    int xtp, xtn, ytp, ytn;
                    xtp = iXPos + 10;
                    xtn = iXPos - 10;
                    ytp = iYPos + 10;
                    ytn = iYPos - 10;
                    while (!worker.CancellationPending)
                    {
                        double[] xypos = stage.GetStagePosition(StageController.StageAxis.XY);
                        LogLine("XY " + xypos[0].ToString() + " " + xypos[1].ToString());
                        double xloc = xypos[0];
                        double yloc = xypos[1];

                        if (xloc <= xtp && xloc > xtn
                            &&
                            yloc <= ytp && yloc > ytn)
                        {
                            break;
                        }
                    }
                    // Ensure Command was Successfull
                    //Thread.Sleep(1000);
                    //efd.Disable();
                }
            }
threadDone:
            if (stage != null)
            {
                stage.Shutdown(); // Close COM Port
            }
            if (efd != null)
            {
                efd.Shutdown();
            }
            e.Cancel = true;
        }