static void Configure(Camera camera) { if (camera.GetSfncVersion() < sfnc2_0_0) // Handling for older cameras { regionSelector = PLCamera.AutoFunctionAOISelector; regionSelectorOffsetX = PLCamera.AutoFunctionAOIOffsetX; regionSelectorOffsetY = PLCamera.AutoFunctionAOIOffsetY; regionSelectorWidth = PLCamera.AutoFunctionAOIWidth; regionSelectorHeight = PLCamera.AutoFunctionAOIHeight; regionSelectorValue1 = PLCamera.AutoFunctionAOISelector.AOI1; regionSelectorValue2 = PLCamera.AutoFunctionAOISelector.AOI2; balanceRatio = PLCamera.BalanceRatioAbs; exposureTime = PLCamera.ExposureTimeAbs; autoFunctionAOIROIUseBrightness = PLCamera.AutoFunctionAOIUsageIntensity; autoFunctionAOIROIUseWhiteBalance = PLCamera.AutoFunctionAOIUsageWhiteBalance; } else // Handling for newer cameras (using SFNC 2.0, e.g. USB3 Vision cameras) { regionSelector = PLCamera.AutoFunctionROISelector; regionSelectorOffsetX = PLCamera.AutoFunctionROIOffsetX; regionSelectorOffsetY = PLCamera.AutoFunctionROIOffsetY; regionSelectorWidth = PLCamera.AutoFunctionROIWidth; regionSelectorHeight = PLCamera.AutoFunctionROIHeight; regionSelectorValue1 = PLCamera.AutoFunctionROISelector.ROI1; regionSelectorValue2 = PLCamera.AutoFunctionROISelector.ROI2; balanceRatio = PLCamera.BalanceRatio; exposureTime = PLCamera.ExposureTime; autoFunctionAOIROIUseBrightness = PLCamera.AutoFunctionROIUseBrightness; autoFunctionAOIROIUseWhiteBalance = PLCamera.AutoFunctionROIUseWhiteBalance; } }
public override long[] GetParam(string name, out long?value) { if (Enum.IsDefined(typeof(IntegerName), name)) { IntegerName integerName = (IntegerName)Enum.Parse(typeof(IntegerName), name); if (!camera.Parameters[integerName].IsEmpty && camera.Parameters[integerName].IsReadable) { long[] param = new long[3]; value = camera.Parameters[integerName].GetValue(); param[0] = camera.Parameters[integerName].GetMinimum(); param[1] = camera.Parameters[integerName].GetMaximum(); param[2] = camera.Parameters[integerName].GetIncrement(); return(param); } else { value = null; return(null); } } else { value = null; return(null); } }
// Configure camera for event trigger and register exposure end event handler. public bool Configure() { // In this sample, a software trigger is used to demonstrate synchronous processing of the grab results. // If you want to react to an event as quickly as possible, you have to use Configuration.AcquireContinuous. CameraOpened += Configuration.SoftwareTrigger; if (Parameters[PLCameraInstance.GrabCameraEvents].IsWritable) { Parameters[PLCameraInstance.GrabCameraEvents].SetValue(true); } else { throw new Exception("Can not enable GrabCameraEvents."); } if (base.Open(1000, TimeoutHandling.Return)) { //Check if camera supports waiting for trigger ready if (!base.CanWaitForFrameTriggerReady) { throw new Exception("This sample can only be used with cameras that can be queried whether they are ready to accept the next frame trigger."); } // Features, e.g., 'ExposureEnd', are named according to the GenICam Standard Feature Naming Convention (SFNC). // The SFNC defines a common set of features, their behavior, and the related parameter names. // This ensures the interoperability of cameras from different camera vendors. // Cameras compliant with the USB3 Vision standard are based on SFNC version 2.0. // Basler GigE and FireWire cameras are based on previous SFNC versions. // Accordingly, the behavior of these cameras and some parameters names will be different. // The SFNC version can be used to handle differences between camera device models. if (this.GetSfncVersion() < Sfnc2_0_0) { // The naming convention for ExposureEnd differs between SFNC 2.0 and previous versions. exposureEndDataName = PLGigECamera.ExposureEndEventTimestamp; exposureEndFrameID = PLGigECamera.ExposureEndEventFrameID; exposureEndTimestamp = PLGigECamera.ExposureEndEventTimestamp; } else // For SFNC 2.0 cameras, e.g. USB3 Vision cameras { exposureEndDataName = PLUsbCamera.EventExposureEnd; exposureEndFrameID = PLUsbCamera.EventExposureEndFrameID; exposureEndTimestamp = PLUsbCamera.EventExposureEndTimestamp; } // Check if the device supports events. if (Parameters[PLCamera.EventSelector].CanSetValue(PLCamera.EventSelector.ExposureEnd) == false) { throw new Exception("The device doesn't support exposure end event."); } // Add a callback function to receive the changed FrameID value. Parameters[exposureEndDataName].ParameterChanged += OnEventExposureEndData; // Enable sending of Exposure End events. // Select the event to receive. Parameters[PLCamera.EventSelector].SetValue(PLCamera.EventSelector.ExposureEnd); // Enable it. Parameters[PLCamera.EventNotification].SetValue(PLCamera.EventNotification.On); } return(true); }
public override void SetParam(string name, long value) { if (Enum.IsDefined(typeof(IntegerName), name)) { IntegerName integerName = (IntegerName)Enum.Parse(typeof(IntegerName), name); if (!camera.Parameters[integerName].IsEmpty && camera.Parameters[integerName].IsWritable) { camera.Parameters[integerName].SetValue(value); } } }
public static string GetFriendlyName(this ItemType itemType) { string name = string.Empty; switch (itemType) { case ItemType.Boolean: name = BooleanName.ToLower(); break; case ItemType.Integer: name = IntegerName.ToLower(); break; } return(name); }
/// <summary> /// 获取Int类型属性的可设定范围 /// </summary> /// <param name="property">属性名</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> /// <param name="increment">增长值</param> public void GetCameraParamValues(IntegerName property, out long min, out long max, out long increment) { min = this._camera.Parameters[property].GetMinimum(); max = this._camera.Parameters[property].GetMaximum(); increment = this._camera.Parameters[property].GetIncrement(); }
private static void Configure(Camera camera) { // Camera event processing must be activated first, the default is off. if (camera.Parameters[PLCameraInstance.GrabCameraEvents].IsWritable) { camera.Parameters[PLCameraInstance.GrabCameraEvents].SetValue(true); } else { throw new Exception("Can not enable GrabCameraEvents."); } // Open the camera for setting parameters. camera.Open(); if (camera.GetSfncVersion() < sfnc2_0_0) // Handling for older cameras { nextExpectedFrameNumberImage = 1; nextExpectedFrameNumberExposureEnd = 1; nextFrameNumberForMove = 1; // The naming convention for ExposureEnd differs between SFNC 2.0 and previous versions. exposureEndEventFrameId = PLCamera.ExposureEndEventFrameID; eventNotificationOn = PLCamera.EventNotification.GenICamEvent; } else // Handling for newer cameras (using SFNC 2.0, e.g. USB3 Vision cameras) { nextExpectedFrameNumberImage = 0; nextExpectedFrameNumberExposureEnd = 0; nextFrameNumberForMove = 0; exposureEndEventFrameId = PLCamera.EventExposureEndFrameID; eventNotificationOn = PLCamera.EventNotification.On; } // Register the event handlers camera.StreamGrabber.ImageGrabbed += OnImageGrabbed; if (camera.GetSfncVersion() < sfnc2_0_0) // Handling for older cameras { camera.Parameters["ExposureEndEventData"].ParameterChanged += delegate(Object sender, ParameterChangedEventArgs e) { OnCameraEventExposureEndData(sender, e, camera); }; camera.Parameters["FrameStartOvertriggerEventData"].ParameterChanged += delegate(Object sender, ParameterChangedEventArgs e) { OnCameraEventFrameStartOvertriggerData(sender, e); }; camera.Parameters["EventOverrunEventData"].ParameterChanged += delegate(Object sender, ParameterChangedEventArgs e) { OnCameraEventOverrunEventData(sender, e); }; } else // Handling for newer cameras (using SFNC 2.0, e.g. USB3 Vision cameras) { camera.Parameters["EventExposureEndData"].ParameterChanged += delegate(Object sender, ParameterChangedEventArgs e) { OnCameraEventExposureEndData(sender, e, camera); }; camera.Parameters["EventFrameStartOvertriggerData"].ParameterChanged += delegate(Object sender, ParameterChangedEventArgs e) { OnCameraEventFrameStartOvertriggerData(sender, e); }; } // The network packet signaling an event of a GigE camera device can get lost on the network. // The following commented parameters can be used to control the handling of lost events. //camera.Parameters[ParametersPLGigEEventGrabber.Timeout] //camera.Parameters[PLGigEEventGrabber.RetryCount] // Check if the device supports events. if (!camera.Parameters[PLCamera.EventSelector].IsWritable) { throw new Exception("The device doesn't support events."); } // Enable the sending of Exposure End events. // Select the event to be received. camera.Parameters[PLCamera.EventSelector].SetValue(PLCamera.EventSelector.ExposureEnd); camera.Parameters[PLCamera.EventNotification].SetValue(eventNotificationOn); // Enable the sending of Event Overrun events. if (camera.GetSfncVersion() < sfnc2_0_0) // Handling for older cameras { camera.Parameters[PLCamera.EventSelector].SetValue(PLCamera.EventSelector.EventOverrun); camera.Parameters[PLCamera.EventNotification].SetValue(eventNotificationOn); } // Enable the sending of Frame Start Overtrigger events. if (camera.Parameters[PLCamera.EventSelector].CanSetValue(PLCamera.EventSelector.FrameStartOvertrigger)) { camera.Parameters[PLCamera.EventSelector].SetValue(PLCamera.EventSelector.FrameStartOvertrigger); camera.Parameters[PLCamera.EventNotification].SetValue(eventNotificationOn); } }
public static int GetInteger(IntegerName pname) { Object result = new int(); GCHandle handle = GCHandle.Alloc(result, GCHandleType.Pinned); try { Private.GetInteger((int)pname, handle.AddrOfPinnedObject()); } finally { handle.Free(); } return (int)result; }