/// <summary> /// Detects cameras installed on the computer and if reqd, /// asks the user to select from the list. Saves the /// list of currently active cameras so if any change is detected /// the next time ACAT is run, we can display the list again. /// Also instructs ACAT Vision to use the selected camera /// </summary> /// <returns></returns> private bool detectAndSetPreferredCamera() { var installedCameras = Cameras.GetCameraNames(); var preferredCamera = String.Empty; bool retVal = true; if (hasCameraListChanged() || !isCameraInstalled(VisionActuatorSettings.PreferredCamera)) { VisionActuatorSettings.CameraList = installedCameras.ToArray(); // if there is more than one camera, let the user pick if (installedCameras.Count() > 1) { var form = new CameraSelectForm { CameraNames = installedCameras, Prompt = R.GetString("SelectCamera"), OKButtonText = R.GetString("OK"), CancelButtonText = R.GetString("Cancel"), Name = _title }; var result = form.ShowDialog(); if (result == DialogResult.Cancel) { MessageBox.Show(R.GetString("NoCameraSelectedVisionWillNotBeActivated"), _title, MessageBoxButtons.OK, MessageBoxIcon.Warning); retVal = false; } else { MessageBox.Show(String.Format(R.GetString("SelectedCamera"), form.SelectedCamera), _title, MessageBoxButtons.OK, MessageBoxIcon.Information); preferredCamera = form.SelectedCamera; } } else { preferredCamera = installedCameras.ElementAt(0); } } else { preferredCamera = VisionActuatorSettings.PreferredCamera; } VisionActuatorSettings.PreferredCamera = preferredCamera; VisionActuatorSettings.Save(); VisionSensor.selectCamera(preferredCamera); return(retVal); }
/// <summary> /// Form load event handler. Quit if there are no /// cameras. If multiple cameras, let the user select /// the preferred one to use /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void Form1_Load(object sender, EventArgs e) { Text = _title; var _installedCameras = Cameras.GetCameraNames(); if (!_installedCameras.Any()) { MessageBox.Show("No cameras detected. Exiting", _title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Close(); return; } var preferredCamera = String.Empty; if (_installedCameras.Count() > 1) { var form = new CameraSelectForm { CameraNames = _installedCameras, Name = _title, Prompt = "Select Camera", OKButtonText = "OK", CancelButtonText = "Cancel" }; var result = form.ShowDialog(); if (result == DialogResult.Cancel) { MessageBox.Show("No camera selected. Exiting", _title); Close(); return; } preferredCamera = form.SelectedCamera; } else { preferredCamera = _installedCameras.ElementAt(0); } VisionSensor.selectCamera(preferredCamera); Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width, Screen.PrimaryScreen.WorkingArea.Height - Height); TopMost = false; TopMost = true; VisionSensor.SetVisionEventHandler(CallbackFromVision); }
/// <summary> /// Displays the dialog that lets the user select the /// default camera. If the user selected one, saves /// the name of the camera in the settings file for the /// vision actuator /// </summary> /// <returns>true on success</returns> private bool showCameraSelectDialog() { var preferredCamera = String.Empty; if (!_installedCameras.Any()) { return(false); } var form = new CameraSelectForm { CameraNames = _installedCameras, Name = _title, Prompt = R.GetString("SelectCamera"), OKButtonText = R.GetString("OK"), CancelButtonText = R.GetString("Cancel") }; var result = form.ShowDialog(); if (result != DialogResult.Cancel) { MessageBox.Show(String.Format(R.GetString("SelectedCamera"), form.SelectedCamera), _title, MessageBoxButtons.OK, MessageBoxIcon.Information); preferredCamera = form.SelectedCamera; Settings.SettingsFilePath = UserManager.GetFullPath(VisionActuator.SettingsFileName); var settings = Settings.Load(); settings.PreferredCamera = preferredCamera; settings.Save(); } return(true); }