/// <summary> /// Closes the camera, vimba, and the frame grabber, and reinitializes them to default settings. Takes about a minute to complete. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ReinitializeSystem_Button_Click(object sender, EventArgs e) { try { if (!restartLocked) { if (shutter.ShutterOpen) { shutter.Close(); Shutter_Label.Text = "Closed"; } if (vmb.IsAcquiring) { vmb.StartAcquisition(); } vmb.Close(); Thread.Sleep(100); int i = vmb.Initialize(); if (i < 0) { MessageBox.Show("Camera Open Failed"); Application.Exit(); } string FORMAT = ""; string FORMATFILE = ""; FORMATFILE = $"{Constants.projectPath}Resources/XCAPVideoSetup16Bit30Hz.fmt"; PXD.pxd_PIXCIclose(); Thread.Sleep(100); i = PXD.pxd_PIXCIopen("", FORMAT, FORMATFILE); Thread.Sleep(100); if (i < 0) { MessageBox.Show("PXD Open Failed"); PXD.pxd_mesgFault(1); Application.Exit(); } promptBox.Text += "System Fully Booted\n"; restartLocked = true; ReinitializeSystem_Button.BackColor = Color.DarkGray; LockReinitialize_Button.Text = "Locked"; LockReinitialize_Button.BackColor = Color.White; } } catch (VimbaException ve) { promptBox.Text += $"{ve.Message}\n"; } catch (Exception ex) { promptBox.Text += $"{ex.Message}\n"; } }
/// <summary> /// Prepares the image frame and formats pixci's frames for displaying images for live stream. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ImagePictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { // Create a local version of the graphics object for the PictureBox. Graphics Draw = e.Graphics; IntPtr hDC = Draw.GetHdc(); // Get a handle to ImagePictureBox. WindowsFunctions.SetStretchBltMode(hDC, WindowsFunctions.STRETCH_DELETESCANS); PXD.pxd_renderStretchDIBits(1, 1, 0, 0, -1, -1, 0, hDC, 0, 0, ImagePictureBox.Width, ImagePictureBox.Height, 0); Draw.ReleaseHdc(hDC); // Release ImagePictureBox handle. }
} // /// <summary> /// Refreshes the live image if Timer1 is active. Otherwise this function is ignored. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { // If Live and captured image has changed then update the window if (pxd.IsStreaming && LastCapturedField != PXD.pxd_capturedFieldCount(1)) // Double checks the live conditions { LastCapturedField = PXD.pxd_capturedFieldCount(1); ImagePictureBox.Invalidate(); } } catch { // ... } }
/// <summary> /// This function executes as the program loads. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, System.EventArgs e) { try { shutter.Close(); // Calls the precompiled CloseShutter.exe program pxd.IsSixteenBit = true; //Default function parameters vmb.exposureTime = 33000; vmb.highGain = true; pxd.imageName = "stillShot"; pxd.liveName = "videoFrame"; pxd.frameCount = 40; pxd.frameCountRemainder = 0; //info[1] = "TempSetPoint\tCamTemp\tExposure\tGain\tFrameRate"; /*while (File.Exists($"{Constants.infoPath}VideoInfo/info{infoFiles}.txt")) * { * infoFiles++; * }*/ pxd.Close(); // In case the DLL was run before and aborted without closing pxd.Initialize(); if (!pxd.IsOpen) // Double check that pxd opened successfully { Thread.Sleep(5000); pxd.Initialize(); } if (!pxd.IsOpen) // Abort if frame grabber fails to initialize { MessageBox.Show("Open Failed, Possible Frame Grabber Malfunction\n" + "If you get this message repeatedly, restart Windows"); PXD.pxd_mesgFault(1); Application.Exit(); } //promptBox.Text += $"{vmb.Initialize()}"; vmb.Initialize(); if (!vmb.IsOpen) { Thread.Sleep(1000); int i = vmb.Initialize(); if (i < 0) { MessageBox.Show("Camera Open Failed"); Application.Exit(); } } if (!vmb.VMBOpen) { promptBox.Text += "Could not boot Vimba\n"; promptBox.Text += "Closing PIXCI\n"; PXD.pxd_PIXCIclose(); } else if (!vmb.IsOpen) { promptBox.Text += "Could not boot Camera\n"; promptBox.Text += "Closing PIXCI\n"; PXD.pxd_PIXCIclose(); } else { promptBox.Text += "Camera booted and ready\n"; } } catch (Exception ex) { promptBox.Text += $"{ex.Message}\n"; } } //