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); }
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); }
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; } }
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); }
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); }
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); } } }
/* 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 + " "); } } }
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); } }
/// <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); } } }
/// <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); } }
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); }