private void RefreshCameras() { // make sure camera 1 is shutdown if (cam1.Running) { try { cam1.StopCamera(); } catch (Exception inner) { string errMsg = "Form1.RefreshCameras : Unable to stop camera 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return; } } // attempt to start camera 1 try { cam1.StartCamera(DEFAULT_CAM1_NAME, 0); } catch (Exception inner) { string errMsg = "Form1.RefreshCameras : Unable to start camera 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); } // make sure camera 2 is shutdown if (cam2.Running) { try { cam2.StopCamera(); } catch (Exception inner) { string errMsg = "Form1.RefreshCameras : Unable to stop camera 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return; } } // attempt to start camera 2 try { cam2.StartCamera(DEFAULT_CAM2_NAME, 1); } catch (Exception inner) { string errMsg = "Form1.RefreshCameras : Unable to start camera 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); } }
private void tsbtnEmergencyStop_Click(object sender, EventArgs e) { USBRelayController relay = USBRelayController.Instance; try { relay.SetRelay0Status(true); relay.SetRelay1Status(true); } catch (Exception inner) { string errMsg = "MainForm.tsbtnEmergencyStop : Relay controller not initialized."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); } }
private void Stop() { log.Info("MainForm.Stop : Stopping image processors and save queue engine."); try { imagep1.Stop(); } catch (Exception inner) { string errMsg = "MainForm.Stop : Error stopping image processor 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); } try { imagep2.Stop(); } catch (Exception inner) { string errMsg = "MainForm.Stop : Error stopping image processor 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); } try { saveEngine.Stop(); } catch (Exception inner) { string errMsg = "MainForm.Stop : Error stopping save engine."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); } return; }
private bool Start() { log.Info("MainForm.Start : Starting image processors and save queue engine."); // set parameters for image processors MetaData metadata = MetaData.Instance; imagep1.SetContrast(metadata.MinimumContrast); imagep1.SetRange(metadata.ImagerNoise); imagep1.SetTargetIntensity(metadata.TargetIntenstiy); imagep2.SetContrast(metadata.MinimumContrast); imagep2.SetRange(metadata.ImagerNoise); imagep2.SetTargetIntensity(metadata.TargetIntenstiy); Rectangle r = Camera1Display.GetRegionToProcess(); if (r != Rectangle.Empty) { imagep1.EnableAutoROI(true); imagep1.SetRegionToProcess(r); } else { imagep1.EnableAutoROI(false); } r = Camera2Display.GetRegionToProcess(); if (r != Rectangle.Empty) { imagep2.EnableAutoROI(true); imagep2.SetRegionToProcess(r); } else { imagep2.EnableAutoROI(false); } try { imagep1.Start(1000 / metadata.TestFrequency); } catch (Exception inner) { string errMsg = "MainForm.Start : Error starting image processor 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return(false); } Thread.Sleep(100); try { imagep2.Start(1000 / metadata.TestFrequency); } catch (Exception inner) { string errMsg = "MainForm.Start : Error starting image processor 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return(false); } try { saveEngine.Start(5); } catch (Exception inner) { string errMsg = "MainForm.Start : Error starting save engine."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return(false); } return(true); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { log.Info("MainForm.Form1_FormClosing : Application is closing, shutting down threads."); // stop cameras if (cam1.Running) { try { cam1.StopCamera(); } catch (Exception inner) { string errMsg = "MainForm.Form1_FormClosing : Unable to stop camera 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); } } if (cam2.Running) { try { cam2.StopCamera(); } catch (Exception inner) { string errMsg = "MainForm.Form1_FormClosing : Unable to stop camera 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); } } // stop image processors if (imagep1.Running) { try { imagep1.Stop(); } catch (Exception inner) { string errMsg = "MainForm.Form1_FormClosing : Unable to stop image processor 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); } } if (imagep2.Running) { try { imagep2.Stop(); } catch (Exception inner) { string errMsg = "MainForm.Form1_FormClosing : Unable to stop image processor 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); } } // stop saveQueue Engine if (saveEngine.Running) { try { saveEngine.Stop(); } catch (Exception inner) { string errMsg = "MainForm.Form1_FormClosing : Unable to stop save engine."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); } } log.Info("MainForm.Form1_FormClosing : All threads shutdown, program terminating."); }