/** * Display all the supported HALCON Image Acquisition callbacks. * * @param acq Reference to the initialized acquisition interface. * @return List of the available callbacks. */ static HTuple showAvailableCallbackTypes(ref HFramegrabber acq) { HTuple callbacks; Console.WriteLine("Get and show the supported callback types using the " + System.Environment.NewLine + "parameter 'available_callback_types'..." + System.Environment.NewLine); callbacks = acq.GetFramegrabberParam("available_callback_types"); if (callbacks.Length > 0) { Console.WriteLine("Available callback types:" + System.Environment.NewLine); } else { Console.WriteLine("No callback types supported by the selected device" + System.Environment.NewLine); return(callbacks); } for (int i = 0; i < callbacks.Length; i++) { Console.WriteLine((i + 1) + ")" + callbacks.TupleSelect(i).S.ToString()); } return(callbacks); }
/// <summary> /// Determines whether one or more camera is connected to the frame grabber and /// whether active signals are available from the camera(s). /// </summary> /// <returns> /// <c>true</c> if [is camera connected]; otherwise, <c>false</c>. /// </returns> public bool IsCameraConnected() { HTuple cameraStatus; lock (this.currentFGHandler) { if (this.currentFGHandler != null && this.currentFGHandler.IsInitialized()) { cameraStatus = currentFGHandler.GetFramegrabberParam("camera_status"); if (cameraStatus == 0) { return(false); } else { return(true); } } return(false); } }
protected override void GetCameraSettingData() { try { //long max, min, cur; HTuple fGainRange = 0; fGainRange = framegrabber.GetFramegrabberParam("Gain_range"); gainMin = fGainRange[0]; gainMax = fGainRange[1]; gainCur = fGainRange[3]; gainUnit = "db"; shuterUnit = "us"; HTuple exposureRange = framegrabber.GetFramegrabberParam("ExposureTimeAbs_range"); shuterMin = (long)exposureRange[0].D; shuterMax = (long)exposureRange[1].D; shuterCur = (long)exposureRange[3].D; HTuple fTriggerDelayRange = framegrabber.GetFramegrabberParam("TriggerDelayAbs_range"); triggerDelayAbsMin = fTriggerDelayRange[0]; triggerDelayAbsMax = fTriggerDelayRange[1]; triggerDelayAbs = fTriggerDelayRange[3]; lineDebouncerTimeAbsMin = 0; lineDebouncerTimeAbsMax = 5000; lineDebouncerTimeAbs = 0; } catch (Exception ex) { Util.WriteLog(this.GetType(), ex); Util.Notify("相机设置信息获取异常"); } }
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(); }
/********************************************************************* * Image acquistion parameters (Lists Initialization) *********************************************************************/ #region Image acquistion parameters (List Initialization) /// <summary> /// Reads all current value of the connection parameters /// after initialization of IA device. /// </summary> private void GetCurrentValuesOfGeneralParameters() { // get values of connection parameters if ((frameGrabber != null) && (Connected == true)) { horizontalResolution = frameGrabber.GetFramegrabberParam( "horizontal_resolution"); verticalResolution = frameGrabber.GetFramegrabberParam( "vertical_resolution"); imageWidth = frameGrabber.GetFramegrabberParam( "image_width"); imageHeight = frameGrabber.GetFramegrabberParam( "image_height"); startRow = frameGrabber.GetFramegrabberParam( "start_row"); startColumn = frameGrabber.GetFramegrabberParam( "start_column"); field = frameGrabber.GetFramegrabberParam( "field"); bitsPerChannel = frameGrabber.GetFramegrabberParam( "bits_per_channel"); colorSpace = frameGrabber.GetFramegrabberParam( "color_space"); generic = frameGrabber.GetFramegrabberParam( "generic"); externalTrigger = frameGrabber.GetFramegrabberParam( "external_trigger"); device = frameGrabber.GetFramegrabberParam( "device"); port = frameGrabber.GetFramegrabberParam( "port"); lineIn = frameGrabber.GetFramegrabberParam( "line_in"); } }