// Close currently open camera if any private void CloseCamera( ) { timer.Stop( ); if (videoSource != null) { videoSourcePlayer.VideoSource = null; videoSource.SignalToStop( ); videoSource.WaitForStop( ); videoSource = null; } }
// On "Connect" button click private void connectButton_Click(object sender, EventArgs e) { // set busy cursor this.Cursor = Cursors.WaitCursor; // close whatever is open now CloseCamera( ); if (videoSource == null) { try { videoSource = new XimeaVideoSource(deviceCombo.SelectedIndex); // start the camera videoSource.Start( ); // get some parameters nameBox.Text = videoSource.GetParamString(CameraParameter.DeviceName); snBox.Text = videoSource.GetParamString(CameraParameter.DeviceSerialNumber); typeBox.Text = videoSource.GetParamString(CameraParameter.DeviceType); // width widthUpDown.Minimum = videoSource.GetParamInt(CameraParameter.WidthMin); widthUpDown.Maximum = videoSource.GetParamInt(CameraParameter.WidthMax); widthUpDown.Value = videoSource.GetParamInt(CameraParameter.WidthMax); // height heightUpDown.Minimum = videoSource.GetParamInt(CameraParameter.HeightMin); heightUpDown.Maximum = videoSource.GetParamInt(CameraParameter.HeightMax); heightUpDown.Value = videoSource.GetParamInt(CameraParameter.HeightMax); // exposure exposureUpDown.Minimum = videoSource.GetParamInt(CameraParameter.ExposureMin) / 1000; exposureUpDown.Maximum = videoSource.GetParamInt(CameraParameter.ExposureMax) / 1000; exposureUpDown.Value = 0; exposureUpDown.Value = 10; // gain gainUpDown.Minimum = new Decimal(videoSource.GetParamFloat(CameraParameter.GainMin)); gainUpDown.Maximum = new Decimal(videoSource.GetParamFloat(CameraParameter.GainMax)); gainUpDown.Value = new Decimal(videoSource.GetParamFloat(CameraParameter.Gain)); videoSourcePlayer.VideoSource = videoSource; EnableConnectionControls(false); // reset stop watch stopWatch = null; // start timer timer.Start( ); } catch (Exception ex) { MessageBox.Show("Failed openning XIMEA camera:\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CloseCamera( ); } } this.Cursor = Cursors.Default; }