예제 #1
0
        /* Loads config nodes which have float type. */
        private void LoadFloatNodes(params string[] nodeName)
        {
            foreach (var name in nodeName)
            {
                var nodeConf = Config.GetConfig(name);


                if (nodeConf == null || string.IsNullOrWhiteSpace(nodeConf))
                {
                    continue;
                }
                if (!float.TryParse(nodeConf, out float value))
                {
                    continue;
                }



                var node = ImageProvider.GetNodeFromDevice(name);

                if (node.IsValid)
                {
                    /* Is Writtable. */
                    if (GenApi.NodeIsWritable(node))
                    {
                        GenApi.FloatSetValue(node, value);
                    }
                }
            }
        }
예제 #2
0
        /* Some features are floating point features. This function illustrates how to set and get floating
         * point parameters. */
        private static void demonstrateFloatFeature(PYLON_DEVICE_HANDLE hDev)
        {
            NODEMAP_HANDLE  hNodeMap;
            NODE_HANDLE     hNode;
            string          featureName = "Gamma"; /* The name of the feature used. */
            bool            bval;                  /* Is the feature available? */
            double          min, max, value;       /* Value range and current value. */
            EGenApiNodeType nodeType;

            /* Get a handle for the device's node map. */
            hNodeMap = Pylon.DeviceGetNodeMap(hDev);

            /* Look up the feature node. */
            hNode = GenApi.NodeMapGetNode(hNodeMap, featureName);
            if (!hNode.IsValid)
            {
                Console.WriteLine("There is no feature named '" + featureName + "'.");
                return;
            }

            /* We want a float feature node. */
            nodeType = GenApi.NodeGetType(hNode);

            if (EGenApiNodeType.FloatNode != nodeType)
            {
                Console.WriteLine("'" + featureName + "' is not an floating-point feature.");
                return;
            }

            bval = GenApi.NodeIsReadable(hNode);

            if (bval)
            {
                /* Query the value range and the current value. */
                min   = GenApi.FloatGetMin(hNode);
                max   = GenApi.FloatGetMax(hNode);
                value = GenApi.FloatGetValue(hNode);

                Console.WriteLine("{0}: min = {1}, max = {2}, value = {3}", featureName, min, max, value);

                /* Set a new value. */
                bval = GenApi.NodeIsWritable(hNode);

                if (bval)
                {
                    value = 0.5 * (min + max);
                    Console.WriteLine("Setting {0} to {1}", featureName, value);
                    GenApi.FloatSetValue(hNode, value);
                }
                else
                {
                    Console.WriteLine("Cannot set value for feature '{0}' - node not writable.", featureName);
                }
            }
            else
            {
                Console.WriteLine("Cannot read feature '{0}' - node not readable.", featureName);
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        /// <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);
                }
            }
        }