public void SetExposure(int value) { bool bval; //ExposureTimeRaw NODE_HANDLE m_hNode = new NODE_HANDLE(); m_hNode = m_imageProvider.GetNodeFromDevice("ExposureTimeRaw"); if (m_hNode.IsValid) { int inc = checked ((int)GenApi.IntegerGetInc(m_hNode)); int min = checked ((int)GenApi.IntegerGetMin(m_hNode)); int max = checked ((int)GenApi.IntegerGetMax(m_hNode)); int expVal = (value) - (value % inc); if (expVal < min) { expVal = min; } if (expVal > max) { expVal = max; } if (!m_hNode.IsValid) { return; } bval = GenApi.NodeIsWritable(m_hNode); if (!bval) { return; } GenApi.IntegerSetValue(m_hNode, expVal); } }
private static CameraProperty ReadFloatProperty(PYLON_DEVICE_HANDLE deviceHandle, string symbol) { CameraProperty p = new CameraProperty(); p.Identifier = symbol; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, symbol); if (!nodeHandle.IsValid) { return(p); } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA || accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO) { return(p); } p.Supported = true; p.ReadOnly = accessMode != EGenApiAccessMode.RW; EGenApiNodeType type = GenApi.NodeGetType(nodeHandle); if (type != EGenApiNodeType.FloatNode) { return(p); } p.Type = CameraPropertyType.Float; double min = GenApi.FloatGetMin(nodeHandle); double max = GenApi.FloatGetMax(nodeHandle); EGenApiRepresentation repr = GenApi.FloatGetRepresentation(nodeHandle); double currentValue = GenApi.FloatGetValue(nodeHandle); // We don't support a dedicated control for "pure numbers" just use the regular slider. if (repr == EGenApiRepresentation.PureNumber) { repr = EGenApiRepresentation.Linear; } // Fix values that should be log. double range = Math.Log(max - min, 10); if (range > 4 && repr == EGenApiRepresentation.Linear) { repr = EGenApiRepresentation.Logarithmic; } p.Minimum = min.ToString(CultureInfo.InvariantCulture); p.Maximum = max.ToString(CultureInfo.InvariantCulture); p.Representation = ConvertRepresentation(repr); p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture); return(p); }
public static void WriteEnum(PYLON_DEVICE_HANDLE deviceHandle, string enumerationName, string enumerationValue) { NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName); WriteEnum(nodeHandle, enumerationName, enumerationValue); }
/* A device has been opened. Update the control. */ private void DeviceOpenedEventHandler() { if (InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new ImageProvider.DeviceOpenedEventHandler(DeviceOpenedEventHandler)); return; } try { /* Get the node. */ m_hNode = m_imageProvider.GetNodeFromDevice(name); /* Register for changes. */ m_hCallbackHandle = GenApi.NodeRegisterCallback(m_hNode, m_nodeCallbackHandler); /* Update the displayed name. */ labelName.Text = GenApi.NodeGetDisplayName(m_hNode) + ":"; /* Update the control values. */ UpdateValues(); } catch { /* If errors occurred disable the control. */ Reset(); } }
private static CameraProperty ReadIntegerProperty(PYLON_DEVICE_HANDLE deviceHandle, string symbol) { CameraProperty p = new CameraProperty(); p.Identifier = symbol; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, symbol); if (!nodeHandle.IsValid) { log.WarnFormat("Could not read Basler property {0}: node handle is not valid. (The property is not supported).", symbol); return(p); } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA || accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO) { log.WarnFormat("Could not read Basler property {0}: Access mode not supported. (The property is not readable).", symbol); return(p); } EGenApiNodeType type = GenApi.NodeGetType(nodeHandle); if (type != EGenApiNodeType.IntegerNode) { log.WarnFormat("Could not read Basler property {0}: the node is of the wrong type. Expected: Integer. Received:{1}", symbol, type.ToString()); return(p); } p.Supported = true; p.Type = CameraPropertyType.Integer; p.ReadOnly = accessMode != EGenApiAccessMode.RW; long min = GenApi.IntegerGetMin(nodeHandle); long max = GenApi.IntegerGetMax(nodeHandle); long step = GenApi.IntegerGetInc(nodeHandle); EGenApiRepresentation repr = GenApi.IntegerGetRepresentation(nodeHandle); // Fix values that should be log. double range = Math.Log10(max) - Math.Log10(min); if (range > 4 && repr == EGenApiRepresentation.Linear) { repr = EGenApiRepresentation.Logarithmic; } long currentValue = GenApi.IntegerGetValue(nodeHandle); p.Minimum = min.ToString(CultureInfo.InvariantCulture); p.Maximum = max.ToString(CultureInfo.InvariantCulture); p.Step = step.ToString(CultureInfo.InvariantCulture); p.Representation = ConvertRepresentation(repr); p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture); return(p); }
public static string DeviceGetStringFeature(PYLON_DEVICE_HANDLE handle, string featureName) { NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(handle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, featureName); string featureValue = GenApi.NodeToString(nodeHandle); return(featureValue); }
private static CameraProperty ReadIntegerProperty(PYLON_DEVICE_HANDLE deviceHandle, string symbol) { CameraProperty p = new CameraProperty(); p.Identifier = symbol; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, symbol); if (!nodeHandle.IsValid) { return(p); } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA || accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO) { return(p); } p.Supported = true; p.ReadOnly = accessMode != EGenApiAccessMode.RW; EGenApiNodeType type = GenApi.NodeGetType(nodeHandle); if (type != EGenApiNodeType.IntegerNode) { return(p); } p.Type = CameraPropertyType.Integer; long min = GenApi.IntegerGetMin(nodeHandle); long max = GenApi.IntegerGetMax(nodeHandle); long step = GenApi.IntegerGetInc(nodeHandle); EGenApiRepresentation repr = GenApi.IntegerGetRepresentation(nodeHandle); // Fix values that should be log. double range = Math.Log(max - min, 10); if (range > 4 && repr == EGenApiRepresentation.Linear) { repr = EGenApiRepresentation.Logarithmic; } long currentValue = GenApi.IntegerGetValue(nodeHandle); p.Minimum = min.ToString(CultureInfo.InvariantCulture); p.Maximum = max.ToString(CultureInfo.InvariantCulture); p.Step = step.ToString(CultureInfo.InvariantCulture); p.Representation = ConvertRepresentation(repr); p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture); return(p); }
public static void Write(PYLON_DEVICE_HANDLE deviceHandle, CameraProperty property) { if (!property.Supported || string.IsNullOrEmpty(property.Identifier)) { return; } NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, property.Identifier); if (!nodeHandle.IsValid) { return; } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode != EGenApiAccessMode.RW) { return; } switch (property.Type) { case CameraPropertyType.Integer: { long value = long.Parse(property.CurrentValue, CultureInfo.InvariantCulture); long step = long.Parse(property.Step, CultureInfo.InvariantCulture); long remainder = value % step; if (remainder > 0) { value = value - remainder; } GenApi.IntegerSetValue(nodeHandle, value); break; } case CameraPropertyType.Float: { double value = double.Parse(property.CurrentValue, CultureInfo.InvariantCulture); GenApi.FloatSetValue(nodeHandle, value); break; } case CameraPropertyType.Boolean: { bool value = bool.Parse(property.CurrentValue); GenApi.BooleanSetValue(nodeHandle, value); break; } default: break; } }
public static void WriteStreamFormat(PYLON_DEVICE_HANDLE deviceHandle, string selectedFormatSymbol) { string enumerationName = "PixelFormat"; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName); if (!nodeHandle.IsValid) { return; } try { bool available = GenApi.NodeIsAvailable(nodeHandle); if (!available) { return; } uint itemCount = GenApi.EnumerationGetNumEntries(nodeHandle); for (uint i = 0; i < itemCount; i++) { NODE_HANDLE entryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i); if (!GenApi.NodeIsAvailable(entryHandle)) { continue; } string value = GenApi.EnumerationEntryGetSymbolic(entryHandle); if (value != selectedFormatSymbol) { continue; } if (GenApi.NodeToString(nodeHandle) == value) { continue; } GenApi.NodeFromString(nodeHandle, value); break; } } catch { // Silent catch. } }
/* The node state has changed. Update the control. */ private void NodeCallbackEventHandler(NODE_HANDLE handle) { if (InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new NodeCallbackHandler.NodeCallback(NodeCallbackEventHandler), handle); return; } if (handle.Equals(m_hNode)) { /* Update the control values. */ UpdateValues(); } }
/* Get the current values from the node and display them. */ private void UpdateValues() { try { if (m_hNode.IsValid) { if (GenApi.NodeGetType(m_hNode) == EGenApiNodeType.EnumerationNode) /* Check is proper node type. */ { /* Check is writable. */ bool writable = GenApi.NodeIsWritable(m_hNode); /* Get the number of enumeration values. */ uint itemCount = GenApi.EnumerationGetNumEntries(m_hNode); /* Clear the combo box. */ comboBox.Items.Clear(); /* Get all enumeration values, add them to the combo box, and set the selected item. */ string aa = PylonC.NET.Pylon.DeviceFeatureToString((PylonC.NET.PYLON_DEVICE_HANDLE)m_imageProvider.m_hDevice, NodeName); string selected = GenApi.NodeToString(m_hNode); for (uint i = 0; i < itemCount; i++) { NODE_HANDLE hEntry = GenApi.EnumerationGetEntryByIndex(m_hNode, i); if (GenApi.NodeIsAvailable(hEntry)) { comboBox.Items.Add(GenApi.NodeGetDisplayName(hEntry)); if (selected == GenApi.EnumerationEntryGetSymbolic(hEntry)) { comboBox.SelectedIndex = comboBox.Items.Count - 1; } } } /* Update accessibility. */ comboBox.Enabled = writable; labelName.Enabled = writable; return; } } } catch { /* If errors occurred disable the control. */ } Reset(); }
public static List <StreamFormat> GetSupportedStreamFormats(PYLON_DEVICE_HANDLE deviceHandle) { // We get a list of all possible values from GenICam API. // We cannot use the Pylon .NET enum names because of casing mismatches. // Then for each possible value, we poll for availability through Pylon API. string enumerationName = "PixelFormat"; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName); if (!nodeHandle.IsValid) { return(null); } EGenApiNodeType nodeType = GenApi.NodeGetType(nodeHandle); if (nodeType != EGenApiNodeType.EnumerationNode) { return(null); } List <StreamFormat> supportedList = new List <StreamFormat>(); uint total = GenApi.EnumerationGetNumEntries(nodeHandle); for (uint i = 0; i < total; i++) { NODE_HANDLE enumEntryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i); string symbol = GenApi.EnumerationEntryGetSymbolic(enumEntryHandle); //string symbol = GenApi.NodeGetDisplayName(entryHandle); //string featureName = string.Format("EnumEntry_{0}_{1}", enumerationName, symbol); //bool supported = Pylon.DeviceFeatureIsAvailable(deviceHandle, featureName); bool supported = GenApi.NodeIsAvailable(enumEntryHandle); if (supported) { string displayName = GenApi.NodeGetDisplayName(enumEntryHandle); supportedList.Add(new StreamFormat(symbol, displayName)); } } return(supportedList); }
public static void WriteEnum(NODE_HANDLE nodeHandle, string enumerationName, string enumerationValue) { if (!nodeHandle.IsValid) { return; } try { bool available = GenApi.NodeIsAvailable(nodeHandle); if (!available) { return; } uint itemCount = GenApi.EnumerationGetNumEntries(nodeHandle); for (uint i = 0; i < itemCount; i++) { NODE_HANDLE entryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i); if (!GenApi.NodeIsAvailable(entryHandle)) { continue; } string value = GenApi.EnumerationEntryGetSymbolic(entryHandle); if (value != enumerationValue) { continue; } if (GenApi.NodeToString(nodeHandle) == value) { continue; } GenApi.NodeFromString(nodeHandle, value); break; } } catch { // Silent catch. } }
/// <summary> /// Read the auto property value and put it into a boolean. /// </summary> private static bool ReadAuto(NODE_HANDLE nodeHandle, string identifier) { switch (identifier) { case "AcquisitionFrameRateEnable": { string currentAutoValue = GenApi.BooleanGetValue(nodeHandle).ToString(CultureInfo.InvariantCulture).ToLower(); return(currentAutoValue == GetAutoTrue(identifier)); } case "GainAuto": case "ExposureAuto": default: { string currentAutoValue = GenApi.NodeToString(nodeHandle); return(currentAutoValue == GetAutoTrue(identifier)); } } }
private static CameraProperty ReadBooleanProperty(PYLON_DEVICE_HANDLE deviceHandle, string symbol) { CameraProperty p = new CameraProperty(); p.Identifier = symbol; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, symbol); if (!nodeHandle.IsValid) { log.WarnFormat("Could not read Basler property {0}: node handle is not valid. (The property is not supported).", symbol); return(p); } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA || accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO) { log.WarnFormat("Could not read Basler property {0}: Access mode not supported. (The property is not readable).", symbol); return(p); } EGenApiNodeType type = GenApi.NodeGetType(nodeHandle); if (type != EGenApiNodeType.BooleanNode) { log.WarnFormat("Could not read Basler property {0}: the node is of the wrong type. Expected: Boolean. Received:{1}", symbol, type.ToString()); return(p); } p.Supported = true; p.Type = CameraPropertyType.Boolean; p.ReadOnly = accessMode != EGenApiAccessMode.RW; bool currentValue = GenApi.BooleanGetValue(nodeHandle); p.Representation = CameraPropertyRepresentation.Checkbox; p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture); return(p); }
/* Callback will be fired when an event message contains an end-of-exposure event. */ private static void endOfExposureCallback(NODE_HANDLE hNode) { try { long frame; frame = GenApi.IntegerGetValue(hNode); Console.WriteLine("Got end-of-exposure event. Frame number: {0}.", frame); } catch (Exception e) { string msg = GenApi.GetLastErrorMessage() + "\n" + GenApi.GetLastErrorDetail(); Console.Error.WriteLine("Exception caught:"); Console.Error.WriteLine(e.Message); if (msg != "\n") { Console.Error.WriteLine("Last error message:"); Console.Error.WriteLine(msg); } } }
/* Handle selection changes. */ private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if (m_hNode.IsValid) { try { /* If writable and combo box selection ok. */ if (GenApi.NodeIsAvailable(m_hNode) && comboBox.SelectedIndex >= 0) { /* Get the displayed selected enumeration value. */ string selectedDisplayName = comboBox.GetItemText(comboBox.Items[comboBox.SelectedIndex]); /* Get the number of enumeration values. */ uint itemCount = GenApi.EnumerationGetNumEntries(m_hNode); /* Determine the symbolic name of the selected item and set it if different. */ for (uint i = 0; i < itemCount; i++) { NODE_HANDLE hEntry = GenApi.EnumerationGetEntryByIndex(m_hNode, i); if (GenApi.NodeIsAvailable(hEntry)) { if (GenApi.NodeGetDisplayName(hEntry) == selectedDisplayName) { /* Get the value to set. */ string value = GenApi.EnumerationEntryGetSymbolic(hEntry); /* Set the value if other than the current value of the node. */ if (GenApi.NodeToString(m_hNode) != value) { GenApi.NodeFromString(m_hNode, value); } } } } } } catch { /* Ignore any errors here. */ } } }
public void SetCameraTriggerMode() { bool bval; NODE_HANDLE m_hNode = new NODE_HANDLE(); m_hNode = m_imageProvider.GetNodeFromDevice("TriggerSelector"); if (!m_hNode.IsValid) { return; } bval = GenApi.NodeIsWritable(m_hNode); if (!bval) { return; } GenApi.NodeFromString(m_hNode, "FrameStart"); m_hNode = m_imageProvider.GetNodeFromDevice("TriggerMode"); if (!m_hNode.IsValid) { return; } bval = GenApi.NodeIsWritable(m_hNode); if (!bval) { return; } GenApi.NodeFromString(m_hNode, "On"); m_hNode = m_imageProvider.GetNodeFromDevice("TriggerSource"); if (!m_hNode.IsValid) { return; } bval = GenApi.NodeIsWritable(m_hNode); if (!bval) { return; } GenApi.NodeFromString(m_hNode, "Software"); }
private static CameraProperty ReadBooleanProperty(PYLON_DEVICE_HANDLE deviceHandle, string symbol) { CameraProperty p = new CameraProperty(); p.Identifier = symbol; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, symbol); if (!nodeHandle.IsValid) { return(p); } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA || accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO) { return(p); } p.Supported = true; p.ReadOnly = accessMode != EGenApiAccessMode.RW; EGenApiNodeType type = GenApi.NodeGetType(nodeHandle); if (type != EGenApiNodeType.BooleanNode) { return(p); } p.Type = CameraPropertyType.Boolean; bool currentValue = GenApi.BooleanGetValue(nodeHandle); p.Representation = CameraPropertyRepresentation.Checkbox; p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture); return(p); }
/// <summary> /// Takes a boolean of whether auto is ON or OFF, convert it to the correct representation and write it in the auto property. /// </summary> private static void WriteAuto(NODE_HANDLE nodeHandle, string identifier, bool isAuto) { string newValue = isAuto ? GetAutoTrue(identifier) : GetAutoFalse(identifier); switch (identifier) { case "AcquisitionFrameRateEnable": { bool newValueBool = bool.Parse(newValue); GenApi.BooleanSetValue(nodeHandle, newValueBool); break; } case "GainAuto": case "ExposureAuto": default: { PylonHelper.WriteEnum(nodeHandle, identifier, newValue); break; } } }
public static StreamFormat GetCurrentStreamFormat(PYLON_DEVICE_HANDLE deviceHandle) { StreamFormat sf = null; string enumerationName = "PixelFormat"; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName); if (!nodeHandle.IsValid) { return(null); } string selected = GenApi.NodeToString(nodeHandle); uint itemCount = GenApi.EnumerationGetNumEntries(nodeHandle); for (uint i = 0; i < itemCount; i++) { NODE_HANDLE entryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i); string symbol = GenApi.EnumerationEntryGetSymbolic(entryHandle); if (selected != symbol) { continue; } if (!GenApi.NodeIsAvailable(entryHandle)) { continue; } string displayName = GenApi.NodeGetDisplayName(entryHandle); sf = new StreamFormat(symbol, displayName); break; } return(sf); }
public void GetGainValue() { bool bval; //ExposureTimeRaw NODE_HANDLE m_hNode = new NODE_HANDLE(); m_hNode = m_imageProvider.GetNodeFromDevice("GainRaw"); if (m_hNode.IsValid) { if (!m_hNode.IsValid) { return; } bval = GenApi.NodeIsWritable(m_hNode); if (!bval) { return; } double result = GenApi.IntegerGetValue(m_hNode); Console.WriteLine(result); } }
private static void WriteCenter(PYLON_DEVICE_HANDLE deviceHandle) { // Force write the CenterX and CenterY properties if supported. // https://docs.baslerweb.com/center-x-and-center-y.html // This is apparently required in order for the MaxWidth/MaxHeight properties to behave correctly // and independently of the offset property. // To summarize we use the following approach: // 1. If CenterX/CenterY are supported properties, we use them and OffsetX/OffsetY will be automated by Pylon. // 2. Otherwise we use manually write OffsetX/OffsetY to center the image. NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandleX = GenApi.NodeMapGetNode(nodeMapHandle, "CenterX"); NODE_HANDLE nodeHandleY = GenApi.NodeMapGetNode(nodeMapHandle, "CenterY"); if (nodeHandleX.IsValid && nodeHandleY.IsValid) { EGenApiAccessMode accessModeOffsetX = GenApi.NodeGetAccessMode(nodeHandleX); EGenApiAccessMode accessModeOffsetY = GenApi.NodeGetAccessMode(nodeHandleY); if (accessModeOffsetX == EGenApiAccessMode.RW && accessModeOffsetY == EGenApiAccessMode.RW) { GenApi.BooleanSetValue(nodeHandleX, true); GenApi.BooleanSetValue(nodeHandleY, true); } } }
private static CameraProperty ReadFramerate(PYLON_DEVICE_HANDLE deviceHandle, Dictionary <string, CameraProperty> properties) { CameraProperty p = new CameraProperty(); p.Identifier = "AcquisitionFrameRate"; p.Supported = false; p.Type = CameraPropertyType.Float; NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, p.Identifier); if (!nodeHandle.IsValid) { p.Identifier = "AcquisitionFrameRateAbs"; nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, p.Identifier); if (!nodeHandle.IsValid) { return(p); } } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA || accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO) { log.WarnFormat("Could not read Basler property {0}: Access mode not supported. (The property is not readable).", p.Identifier); return(p); } EGenApiNodeType type = GenApi.NodeGetType(nodeHandle); if (type != EGenApiNodeType.FloatNode) { log.WarnFormat("Could not read Basler property {0}: the node is of the wrong type. Expected: Float. Received:{1}", p.Identifier, type.ToString()); return(p); } p.ReadOnly = false; p.Supported = true; double currentValue = GenApi.FloatGetValue(nodeHandle); double min = GenApi.FloatGetMin(nodeHandle); double max = GenApi.FloatGetMax(nodeHandle); double step = 1.0; min = Math.Max(1.0, min); p.Minimum = min.ToString(CultureInfo.InvariantCulture); p.Maximum = max.ToString(CultureInfo.InvariantCulture); p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture); p.Step = step.ToString(CultureInfo.InvariantCulture); // Fix values that should be log. double range = Math.Log10(max) - Math.Log10(min); p.Representation = (range >= 4) ? CameraPropertyRepresentation.LogarithmicSlider : CameraPropertyRepresentation.LinearSlider; // AcquisitionFrameRateEnable=false: the framerate is automatically set to the max value possible. // AcquisitionFrameRateEnable=true: use the custom framerate set by the user in AcquisitionFrameRate. string autoIdentifier = "AcquisitionFrameRateEnable"; p.AutomaticIdentifier = autoIdentifier; NODE_HANDLE nodeHandleAuto = GenApi.NodeMapGetNode(nodeMapHandle, autoIdentifier); p.CanBeAutomatic = nodeHandleAuto.IsValid && GenApi.NodeIsWritable(nodeHandleAuto); p.Automatic = false; if (p.CanBeAutomatic) { string currentAutoValue = GenApi.BooleanGetValue(nodeHandleAuto).ToString(CultureInfo.InvariantCulture).ToLower(); p.Automatic = currentAutoValue == GetAutoTrue(autoIdentifier); } if (properties != null) { properties.Add("framerate", p); } return(p); }
/// <summary> /// Write either width or height as a centered region of interest. /// </summary> private static void WriteSize(PYLON_DEVICE_HANDLE deviceHandle, CameraProperty property, string identifierOffset) { if (property.ReadOnly) { return; } NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, property.Identifier); if (!nodeHandle.IsValid) { return; } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode != EGenApiAccessMode.RW) { return; } long value = long.Parse(property.CurrentValue, CultureInfo.InvariantCulture); long min = GenApi.IntegerGetMin(nodeHandle); long max = GenApi.IntegerGetMax(nodeHandle); long step = GenApi.IntegerGetInc(nodeHandle); value = FixValue(value, min, max, step); // Offset handling. // Some cameras have a CenterX/CenterY property. // When it is set, the offset is automatic and becomes read-only. bool setOffset = false; NODE_HANDLE nodeHandleOffset = GenApi.NodeMapGetNode(nodeMapHandle, identifierOffset); if (nodeHandleOffset.IsValid) { EGenApiAccessMode accessModeOffset = GenApi.NodeGetAccessMode(nodeHandleOffset); if (accessModeOffset == EGenApiAccessMode.RW) { setOffset = true; } } if (setOffset) { long offset = (max - value) / 2; long minOffset = GenApi.IntegerGetMin(nodeHandleOffset); long stepOffset = GenApi.IntegerGetInc(nodeHandleOffset); long remainderOffset = (offset - minOffset) % stepOffset; if (remainderOffset != 0) { offset = offset - remainderOffset + stepOffset; } // We need to be careful with the order and not write a value that doesn't fit due to the offset, or vice versa. long currentValue = GenApi.IntegerGetValue(nodeHandle); if (value > currentValue) { GenApi.IntegerSetValue(nodeHandleOffset, offset); GenApi.IntegerSetValue(nodeHandle, value); } else { GenApi.IntegerSetValue(nodeHandle, value); GenApi.IntegerSetValue(nodeHandleOffset, offset); } } else { GenApi.IntegerSetValue(nodeHandle, value); } }
/// <summary> /// Write generic property with optional auto flag. /// </summary> private static void WriteProperty(PYLON_DEVICE_HANDLE deviceHandle, CameraProperty property) { if (property.ReadOnly) { return; } NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); // Switch OFF the auto flag if needed, to be able to write the main property. if (!string.IsNullOrEmpty(property.AutomaticIdentifier)) { NODE_HANDLE nodeHandleAuto = GenApi.NodeMapGetNode(nodeMapHandle, property.AutomaticIdentifier); if (nodeHandleAuto.IsValid) { bool writeable = GenApi.NodeIsWritable(nodeHandleAuto); bool currentAuto = ReadAuto(nodeHandleAuto, property.AutomaticIdentifier); if (writeable && property.CanBeAutomatic && currentAuto && !property.Automatic) { WriteAuto(nodeHandleAuto, property.AutomaticIdentifier, false); } } } // At this point the auto flag is off. Write the main property. NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, property.Identifier); if (!nodeHandle.IsValid) { return; } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode != EGenApiAccessMode.RW) { return; } try { switch (property.Type) { case CameraPropertyType.Integer: { long value = long.Parse(property.CurrentValue, CultureInfo.InvariantCulture); long min = GenApi.IntegerGetMin(nodeHandle); long max = GenApi.IntegerGetMax(nodeHandle); long step = GenApi.IntegerGetInc(nodeHandle); value = FixValue(value, min, max, step); GenApi.IntegerSetValue(nodeHandle, value); break; } case CameraPropertyType.Float: { double value = double.Parse(property.CurrentValue, CultureInfo.InvariantCulture); double min = GenApi.FloatGetMin(nodeHandle); double max = GenApi.FloatGetMax(nodeHandle); value = FixValue(value, min, max); GenApi.FloatSetValue(nodeHandle, value); break; } case CameraPropertyType.Boolean: { bool value = bool.Parse(property.CurrentValue); GenApi.BooleanSetValue(nodeHandle, value); break; } default: break; } } catch { log.ErrorFormat("Error while writing Basler Pylon GenICam property {0}.", property.Identifier); } // Finally, switch ON the auto flag if needed. if (!string.IsNullOrEmpty(property.AutomaticIdentifier)) { NODE_HANDLE nodeHandleAuto = GenApi.NodeMapGetNode(nodeMapHandle, property.AutomaticIdentifier); if (nodeHandleAuto.IsValid && GenApi.NodeIsWritable(nodeHandleAuto) && property.CanBeAutomatic && property.Automatic) { WriteAuto(nodeHandleAuto, property.AutomaticIdentifier, true); } } }
/* Traverse the feature tree, displaying all categories and all features. */ private static void handleCategory(NODE_HANDLE hRoot, string indentation) { uint numfeat, i; string rootname = GenApi.NodeGetName(hRoot); /* Get the number of feature nodes in this category. */ numfeat = GenApi.CategoryGetNumFeatures(hRoot); Console.WriteLine("{0} category has {1} children:", indentation + rootname, numfeat); indentation += " "; /* Now loop over all feature nodes. */ for (i = 0; i < numfeat; ++i) { NODE_HANDLE hNode; EGenApiNodeType nodeType; /* Get next feature node and check its type. */ hNode = GenApi.CategoryGetFeatureByIndex(hRoot, i); nodeType = GenApi.NodeGetType(hNode); if (EGenApiNodeType.Category != nodeType) { /* A regular feature. */ EGenApiAccessMode am; string amode; string name = GenApi.NodeGetName(hNode); am = GenApi.NodeGetAccessMode(hNode); switch (am) { case EGenApiAccessMode.NI: amode = "not implemented"; break; case EGenApiAccessMode.NA: amode = "not available"; break; case EGenApiAccessMode.WO: amode = "write only"; break; case EGenApiAccessMode.RO: amode = "read only"; break; case EGenApiAccessMode.RW: amode = "read and write"; break; default: amode = "undefined"; break; } Console.WriteLine("{0} feature - access: {1}", indentation + name, amode); } else { /* Another category node. */ handleCategory(hNode, indentation + " "); } } }
/// <summary> /// A device has been opened. Update the control. /// </summary> public void DeviceOpenedEventHandler() { if (InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new MethodInvoker(DeviceOpenedEventHandler)); //new ImageProvider.DeviceOpenedEventHandler (DeviceOpenedEventHandler)); return; } try { /* Get the node. */ m_hNode = m_imageProvider.GetNodeFromDevice(name); /* Features, like 'Gain', 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. * * Some cameras, e.g. cameras compliant to the USB3 Vision standard, use a later SFNC version than * previous Basler GigE and Firewire cameras. Accordingly, the behavior of these cameras and * some parameters names will be different. */ if (!m_hNode.IsValid && /* No node has been found using the provided name. */ (name == "GainRaw" || name == "ExposureTimeRaw")) /* This means probably that the camera is compliant to a later SFNC version. */ { /* Check to see if a compatible node exists. The SFNC 2.0, implemented by Basler USB Cameras for instance, defines Gain * and ExposureTime as features of type Float.*/ if (name == "GainRaw") { m_hNode = m_imageProvider.GetNodeFromDevice("Gain"); } else if (name == "ExposureTimeRaw") { m_hNode = m_imageProvider.GetNodeFromDevice("ExposureTime"); } /* Update the displayed name. */ labelName.Text = GenApi.NodeGetDisplayName(m_hNode) + ":"; /* The underlying integer representation of Gain and ExposureTime can be accessed using * the so called alias node. The alias is another representation of the original parameter. * * Since this slider control can only be used with Integer nodes we have to use * the alias node here to display and modify Gain and ExposureTime. */ m_hNode = GenApi.NodeGetAlias(m_hNode); /* Register for changes. */ m_hCallbackHandle = GenApi.NodeRegisterCallback(m_hNode, m_nodeCallbackHandler); } else { /* Update the displayed name. */ labelName.Text = GenApi.NodeGetDisplayName(m_hNode) + "مقدار:"; /* Register for changes. */ m_hCallbackHandle = GenApi.NodeRegisterCallback(m_hNode, m_nodeCallbackHandler); } /* Update the control values. */ UpdateValues(); } catch { /* If errors occurred disable the control. */ Reset(); } }
public static void Write(PYLON_DEVICE_HANDLE deviceHandle, CameraProperty property) { if (!property.Supported || string.IsNullOrEmpty(property.Identifier) || !deviceHandle.IsValid) { return; } // If "auto" flag is OFF we should write it first. On some cameras the value is not writable until the corresponding auto flag is off. // If it's ON (continuous), it doesn't matter as our value will be overwritten soon anyway. if (!string.IsNullOrEmpty(property.AutomaticIdentifier)) { string enumValue = property.Automatic ? "Continuous" : "Off"; PylonHelper.WriteEnum(deviceHandle, property.AutomaticIdentifier, enumValue); } NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle); NODE_HANDLE nodeHandle = GenApi.NodeMapGetNode(nodeMapHandle, property.Identifier); if (!nodeHandle.IsValid) { return; } EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle); if (accessMode != EGenApiAccessMode.RW) { if (!string.IsNullOrEmpty(property.AutomaticIdentifier) && !property.Automatic) { log.ErrorFormat("Error while writing Basler Pylon GenICam property {0}.", property.Identifier); log.ErrorFormat("The property is not writable."); } return; } try { switch (property.Type) { case CameraPropertyType.Integer: { long value = long.Parse(property.CurrentValue, CultureInfo.InvariantCulture); long step = long.Parse(property.Step, CultureInfo.InvariantCulture); long remainder = value % step; if (remainder > 0) { value = value - remainder; } GenApi.IntegerSetValue(nodeHandle, value); break; } case CameraPropertyType.Float: { double max = GenApi.FloatGetMax(nodeHandle); double min = GenApi.FloatGetMin(nodeHandle); double value = double.Parse(property.CurrentValue, CultureInfo.InvariantCulture); value = Math.Min(Math.Max(value, min), max); GenApi.FloatSetValue(nodeHandle, value); break; } case CameraPropertyType.Boolean: { bool value = bool.Parse(property.CurrentValue); GenApi.BooleanSetValue(nodeHandle, value); break; } default: break; } } catch { log.ErrorFormat("Error while writing Basler Pylon GenICam property {0}.", property.Identifier); } }