private void CamParamsChanged(object sender, EventArgs e) { double gainValue = 0, exposureValue = 0; //------------------------------------------------------------ // Cập nhật giá trị Gain //------------------------------------------------------------ try { gainValue = Double.Parse(txtGainValue.Text); MainFrameGrabber.SetFramegrabberParam(new HTuple("Gain"), new HTuple(gainValue)); } catch { } //------------------------------------------------------------ // Cập nhật giá trị Exposure //------------------------------------------------------------ try { exposureValue = Double.Parse(txtExposureValue.Text); MainFrameGrabber.SetFramegrabberParam(new HTuple("ExposureTime"), new HTuple(exposureValue)); } catch { } //------------------------------------------------------------ // Chụp ảnh mới theo thay đổi //------------------------------------------------------------ GrabMutex.WaitOne(); HImage Img; Img = MainFrameGrabber.GrabImage(); Img.DispObj(MainWindow); Img.Dispose(); GrabMutex.ReleaseMutex(); //------------------------------------------------------------ // Cập nhật CameraSet //------------------------------------------------------------ CurrentCameraSet.Gain = gainValue; CurrentCameraSet.Exposure = exposureValue; }
private void btnConnect_Click(object sender, EventArgs e) { //------------------------------------------------------------ // Kiểm tra lệnh kết nối hay ngắt kết nối //------------------------------------------------------------ if (CameraConnected) { MainFrameGrabber.Dispose(); btnConnect.Text = " Connect"; CameraConnected = false; return; } //------------------------------------------------------------ // Lấy giá trị device và generic cho hàm kết nối camera //------------------------------------------------------------ bool isFileInterface = false; string regexDevicePattern = @"(device:)(.+?)(\s\|)"; string regexGenericPattern = @"(suggestion:)(.+)(\s\|)"; string deviceInfo = cbDevices.SelectedItem.ToString(); string device = Regex.Match(deviceInfo, regexDevicePattern).Groups[2].Value; if (device.Length < 3) { device = "default"; } HTuple generic; if (deviceInfo.Contains("misconfigured")) { generic = Regex.Match(deviceInfo, regexGenericPattern).Groups[2].Value; } else { generic = new HTuple(-1); } //------------------------------------------------------------ // Check if is File Interface //------------------------------------------------------------ string interfaceName = cbInterfaces.SelectedItem.ToString(); if (interfaceName == "File") { isFileInterface = true; } if (!isFileInterface) { try { MainFrameGrabber = new HFramegrabber(interfaceName, 1, 1, 0, 0, 0, 0, "default", new HTuple(-1), new HTuple("default"), generic, "default", new HTuple("default"), new HTuple(device), new HTuple(-1), new HTuple(-1)); } catch { return; } try { //------------------------------------------------------------ // Lấy giá trị Gain, Exposure từ Camera //------------------------------------------------------------ HTuple gain = MainFrameGrabber.GetFramegrabberParam("Gain"); HTuple exposureTime = MainFrameGrabber.GetFramegrabberParam("ExposureTime"); //------------------------------------------------------------ // Hiển thị lên ô cài đặt //------------------------------------------------------------ txtGainValue.Text = gain.D.ToString(); txtExposureValue.Text = exposureTime.D.ToString(); //------------------------------------------------------------ // Thay đổi trạng thái kết nối //------------------------------------------------------------ btnConnect.Text = " Connected"; CameraConnected = true; //------------------------------------------------------------ // Cập nhật CameraSet //------------------------------------------------------------ CurrentCameraSet.Device = device; CurrentCameraSet.Generic = generic; } catch (Exception ex) { } } else { MainFrameGrabber = null; } //------------------------------------------------------------ // Set Window display image //------------------------------------------------------------ string ImgType; int ImgWidth, ImgHeight; HImage Img; Img = MainFrameGrabber.GrabImageAsync(1); Img.GetImagePointer1(out ImgType, out ImgWidth, out ImgHeight); MainWindow.SetPart(0, 0, ImgHeight - 1, ImgWidth - 1); Img.DispObj(MainWindow); Img.Dispose(); }