void FreeResources() { string PreviewImage = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "Preview.jpg"; if (File.Exists(PreviewImage)) { File.Delete(PreviewImage); } #if IsInstallHotTab if (mHotTabCamera != null) { mHotTabCamera.Flash(0); SetFlashOff(); mHotTabCamera.Dispose(); mHotTabCamera = null; } #endif }
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 UpdateDeviceList() { try { if (IsDeveloperMode) { CameraList = new List <string>(new string[] { "10.1 TPC(vid_064e&pid_998d)", "PC Camera(vid_058f&pid_3841)" }); } else { CameraList = HotTabCamera.GetListCamera(); } // 將抓到的Camera做升序排列 // [WAY 1] LINQ // IEnumerable<string> sortAscendingQuery = from camera in CameraList // orderby camera //"ascending" is default // select camera; // CameraList = sortAscendingQuery.ToList(); // [WAY 2] List<T>.Sort 方法() // CameraList.Sort(); // 常見的三種Camera的升序排列結果: // 10.1 TPC(vid_064e & pid_998d) // IZONE UVC 5M Camera(vid_2081 & pid_270d) // PC Camera(vid_058f&pid_3841) comboBoxCameraDevices.Items.Clear(); if (CameraList.Count > 0) // if (m_devicename != null) { for (int i = 0; i < CameraList.Count; i++) { // DAP7會出現一個未知的VDP Source()裝置, 選擇後按下Snap會crash // ID82會出現一個未知的Virtual Viscomsoft Screen Capture if (!CameraList[i].Contains("VDP") && !CameraList[i].Contains("Virtual")) { iCameraAmount++; comboBoxCameraDevices.Items.Add(CameraList[i]); if (IsDebugMode) { Trace.WriteLine("Index : " + i + " , Camara Name : " + CameraList[i]); } } } // comboBoxCameraDevices.Sorted = true; if (IsDebugMode) { Trace.WriteLine("Total Camara : " + CameraList.Count + "(" + CameraAmount + ")"); } if (CameraAmount.Equals(CameraList.Count)) { comboBoxCameraDevices.SelectedIndex = TestCamera; comboBoxCameraDevices.Enabled = false; } else { MessageBox.Show("Front Camera or Rear Camera is blocked.\r\nPlease check module or config file.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error); checkTestStatus("Front Camera or Rear Camera is blocked."); } } else { iCameraAmount = 0; if (comboBoxCameraDevices.InvokeRequired) { comboBoxCameraDevices.Invoke(new Action(() => { comboBoxCameraDevices.Items.Add("Device Not Found"); })); } else { comboBoxCameraDevices.Items.Add("Device Not Found"); } comboBoxCameraDevices.SelectedIndex = 0; comboBoxCameraDevices.Enabled = false; } } catch (Exception ex) { ExceptionEvent(ex); } }
public void InitializeCameraListDevice(int iDeviceNum, PictureBox box) { lock (thisLock) { if (IsDebugMode) { Trace.WriteLine("Init No." + iDeviceNum + " Camara : " + CameraList[iDeviceNum] + " by Thread " + Thread.CurrentThread.ManagedThreadId + " on " + System.DateTime.Now); } groupBoxTestButton.Enabled = false; try { if (mHotTabCamera != null) { mHotTabCamera.Dispose(); mHotTabCamera = null; } this.Invoke((MethodInvoker) delegate() { if (IsDebugMode) { Trace.WriteLine("New HotTabCamera No." + iDeviceNum + " by Thread " + Thread.CurrentThread.ManagedThreadId + " on " + System.DateTime.Now); } mHotTabCamera = new HotTabCamera(iDeviceNum, VIDEOWIDTH, VIDEOHEIGHT, VIDEOBITSPERPIXEL, box); }); CameraResolution = HotTabCamera.CheckMaxResolution(iDeviceNum); // 2M Camera : X = 1600, Y = 1200 // 5M Camera : X = 2592, Y = 1944 // 6M Camera : X = 3264, Y = 1836 if (IsDebugMode) { Trace.WriteLine("CameraResolution, X : " + CameraResolution.X + " , Y : " + CameraResolution.Y); } // 1. 只有單個相機, 沒有閃光燈 // 2. 有前後相機, 後相機有閃光燈 // 像素不到500萬, 一定是前鏡頭 if ((CameraResolution.X < 1920) && (CameraResolution.Y < 1440)) { labelTestCameraName.Text = "Front Camera"; buttonFlash.Visible = false; buttonFlash.Enabled = false; buttonCapture.Enabled = true; } else // ID82, IB10X, DAP7, M9020B, ID8HH, ID90 只有單一相機, 有閃光燈 { labelTestCameraName.Text = "Rear Camera"; buttonFlash.Visible = true; buttonFlash.Enabled = true; buttonCapture.Enabled = false; mHotTabCamera.Flash(0); if (Is8MCameraUsed) { Flash_8M(0); } else { SetFlashOff(); } } if (IsAutoModeCamera) { buttonFlash.Visible = true; buttonFlash.Enabled = false; buttonCapture.Visible = true; buttonCapture.Enabled = false; TimerCamaraCapture.Interval = TimerIntervalCamaraCapture; TimerCamaraCapture.Start(); } } catch (Exception ex) { ExceptionEvent(ex); } groupBoxTestButton.Enabled = true; } }
void camera_Load(object sender, EventArgs e) { result["result"] = "FAIL"; var jsonconfig = GetFullPath("config.json"); if (!File.Exists(jsonconfig)) { MessageBox.Show("config.json not founded"); Exit(); } dynamic jobject = JObject.Parse(File.ReadAllText(jsonconfig)); ShowWindow = (bool)jobject.ShowWindow; CameraAmount = (int)jobject.CameraAmount; IsAutoModeCamera = (bool)jobject.IsAutoModeCamera; TimerIntervalCamaraCapture = (int)jobject.TimerIntervalCamaraCapture; ConfirmTagContextBarcode = jobject.ConfirmTagContextBarcode.ToString(); TestProduct = jobject.TestProduct.ToString(); IsFM08 = (bool)jobject.IsFM08; if (ShowWindow) { this.Opacity = 100; this.ShowInTaskbar = true; } if (IsDebugMode) { Trace.WriteLine("Camera_Load, Is8MCameraUsed : " + Is8MCameraUsed); } TestCamera = 0; // 確認測試過的相機數是初始值的0, Winmate Kenkun modify on 2017/07/07 if (IsDeveloperMode) { UpdateDeviceList(); } else if (HotTabCamera.GetCameraCount() <= 0) { if (IsDebugMode) { Trace.WriteLine("Camera Not Found"); } comboBoxCameraDevices.Items.Add("Device Not Found"); comboBoxCameraDevices.SelectedIndex = 0; checkTestStatus("Camera Not Found."); return; } else { FangtecCameraDLL.ALC_Initialization(0, ""); // About 1.3 Sec // 將Camera轉90度, 需搭配廠商提供的Rotation Driver if (TestProduct.Equals("FMB8") && !IsFM08) { HotTabDLL.FangtecRotate090(); // 由於DLL改版, 只有FM10用, Winmate Kenkun modify on 2015/12/14 } UpdateDeviceList(); } if (IsAutoModeCamera) { if (IsDebugMode) { Trace.WriteLine("Camera - AutoMode"); } groupBoxCapturePreview.Visible = false; groupBoxPositionOfCapture.Visible = false; CaptureDecoder = new decoder(); } }