private void buttonEFDOn_Click(object sender, EventArgs e) { EFDControl efd = new EFDControl(comboBoxEFDPortNames.Text); efd.Enable(); Thread.Sleep(1000); efd.Shutdown(); }
// 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; }
// 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; }