void checkTestStatus(String testResult) { if (IsAutoModeCamera) { TimerCamaraCapture.Stop(); } if (HotTabCamera.GetCameraCount() > 0) { if (mHotTabCamera != null) { mHotTabCamera.Flash(0); } if (Is8MCameraUsed) { Flash_8M(0); } else { SetFlashOff(); } } labelTestCameraName.Text = "None"; pictureBoxPreview.Image = null; pictureBoxPreview2.Image = null; buttonFAIL.Enabled = false; buttonFlash.Enabled = false; buttonCapture.Enabled = false; buttonPreviewTop.Enabled = false; buttonPreviewBottom.Enabled = false; FreeResources(); if (testResult.Equals("PASS")) { labelResult.ForeColor = Color.Green; labelResult.Text = "PASS"; result["result"] = "PASS"; result["EIPLog"] = new JObject { { "Camera", "PASS" }, { "Camera_Info", "PASS" } }; } else { labelResult.ForeColor = Color.Red; labelResult.Text = "FAIL"; result["result"] = "FAIL"; result["EIPLog"] = new JObject { { "Camera", "FAIL" }, { "Camera_Info", testResult } }; } File.WriteAllText(GetFullPath("result.json"), result.ToString()); Thread.Sleep(200); File.Create(GetFullPath("completed")); if (!ShowWindow) { Exit(); } }
void CaptureClick() { try { if (IsAutoModeCamera) { TimerCamaraCapture.Stop(); } else if (buttonFlash.Enabled) { buttonFlash.Enabled = false; buttonFlash.Visible = false; } // 一個image不能同時被兩個PictureBox使用。切換的時候,先把先前使用的PictureBox.Image = null pictureBoxPreview.Image = null; // pictureBoxPreview.Image.Dispose(); pictureBoxPreview2.Image = null; // pictureBoxPreview2.Image.Dispose(); if (mHotTabCamera == null) { checkTestStatus("HotTab Camera is NULL!"); return; } IntPtr mIntPtr = IntPtr.Zero; Cursor.Current = Cursors.WaitCursor; // Release any previous buffer if (mIntPtr != IntPtr.Zero) { Marshal.FreeCoTaskMem(mIntPtr); mIntPtr = IntPtr.Zero; } // 亂數產生Snapshot所要使用的初始PictureBox應該要是哪一個 SwitchSnapshotPreview = RandomGenerator.Next(MinValue, MaxValue); // Capture Image mIntPtr = mHotTabCamera.Click(); // Stride : 指定一條掃描線 (Scan Line) 的開頭和下一條之間的位元組位移 (Offset). 這通常是像素格式的位元組數目 (例如, 16 位元/像素為 2) 乘以點陣圖寬度. 必須是四的倍數 Bitmap CapturePreview = new Bitmap(mHotTabCamera.Width, mHotTabCamera.Height, mHotTabCamera.Stride, PixelFormat.Format24bppRgb, mIntPtr); // If the image is upsidedown CapturePreview.RotateFlip(RotateFlipType.RotateNoneFlipY); // Snapshot截圖會亂數顯示在兩個Preview的PictureBox之間 if (SwitchSnapshotPreview % 2 == 0) { pictureBoxPreview.Image = CapturePreview; Clipboard.SetDataObject(pictureBoxPreview.Image); } else { pictureBoxPreview2.Image = CapturePreview; Clipboard.SetDataObject(pictureBoxPreview2.Image); } Clipboard.GetImage().Save("Preview.bmp", ImageFormat.Bmp); if (IsAutoModeCamera) { buttonPASS.Enabled = false; buttonFAIL.Enabled = false; CaptureDecodeData = CaptureDecoder.decode(CapturePreview); if (IsDebugMode) { Trace.WriteLine("ConfirmTagContextBarcode : " + ConfirmTagContextBarcode); Trace.WriteLine("Capture Barcode Decode : " + CaptureDecodeData); } if (buttonFlash.Text.Equals("ON") && (CaptureDecodeData.Contains(ConfirmTagContextBarcode.Substring(0, ConfirmTagContextBarcode.Length - 3)))) { checkTestStatus("Capture can be decoded in FLASH ON!"); } else if (buttonFlash.Text.Equals("ON")) { TimerCamaraCapture.Start(); } else if (CaptureDecodeData.Contains(ConfirmTagContextBarcode.Substring(0, ConfirmTagContextBarcode.Length - 3))) { TestNextCamera(); } else { checkTestStatus("Capture Barcode Decode FAIL!"); } } Cursor.Current = Cursors.Default; // Release any previous buffer if (mIntPtr != IntPtr.Zero) { Marshal.FreeCoTaskMem(mIntPtr); mIntPtr = IntPtr.Zero; } // 手動測項防呆機制(不讓產線沒有測試就直接按PASS/FAIL) buttonPreviewTop.Enabled = true; buttonPreviewBottom.Enabled = true; } catch (Exception ex) { Trace.WriteLine(ex.ToString()); ExceptionEvent(ex); } }