示例#1
0
        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);
            }
        }
示例#2
0
        /* Loads config nodes and configures the basler camera. */
        private void LoadConfigNodes(params string[] nodeNames)
        {
            foreach (var name in nodeNames)
            {
                var nodeConf = Config.GetConfig(name);


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



                var node = ImageProvider.GetNodeFromDevice(name);

                if (node.IsValid)
                {
                    /* Is Writtable. */
                    if (GenApi.NodeIsWritable(node))
                    {
                        GenApi.IntegerSetValue(node, value);
                    }
                }
            }
        }
示例#3
0
        /* If the device provides a heartbeat timeout, this function will set the heartbeat timeout.
         * When the device provides the parameter, the old value is returned, -1 otherwise.
         * The heartbeat timeout is a parameter provided by the transport layer.
         * The transport layer parameters are exposed as a GenApi node map that
         * can be retrieved from the device.
         */
        private static long setHeartbeatTimeout(PYLON_DEVICE_HANDLE hDev, long timeout_ms)
        {
            NODEMAP_HANDLE hNodemap;   /* Handle to the node map. */
            NODE_HANDLE    hNode;      /* Handle to a node, i.e., a feature. */
            long           oldTimeout; /* The current timeout value. */

            /* Get the node map for the transport layer parameters. */
            hNodemap = Pylon.DeviceGetTLNodeMap(hDev);

            if (!hNodemap.IsValid)
            {
                /* The device doesn't provide a transport layer node map. Nothing to do. */
                Console.WriteLine("The device doesn't provide a transport layer node map. Cannot set heartbeat timeout.");
                return(-1);
            }
            /* Get the node for the heartbeat timeout parameter. */
            hNode = GenApi.NodeMapGetNode(hNodemap, "HeartbeatTimeout");

            if (!hNode.IsValid)
            {
                /* There is no heartbeat timeout parameter. Nothing to do. */
                Console.WriteLine("There is no heartbeat timeout parameter. Cannot set heartbeat timeout.");
                return(-1);
            }

            /* Get the current value. */
            oldTimeout = GenApi.IntegerGetValue(hNode);

            /* Set the new value. */
            GenApi.IntegerSetValue(hNode, timeout_ms);

            /* Return the old value. */
            return(oldTimeout);
        }
示例#4
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;
            }
        }
示例#5
0
 private void OnValueChanged(object sender, EventArgs e)
 {
     if (m_hNode.IsValid)
     {
         try {
             if (GenApi.NodeIsWritable(m_hNode))
             {
                 /* Correct the increment of the new value. */
                 int value = (int)labelCurrentValue.Value;
                 /* Set the value. */
                 GenApi.IntegerSetValue(m_hNode, value);
             }
         }
         catch {
             /* Ignore any errors here. */
         }
     }
 }
示例#6
0
 /* Handle slider position changes. */
 private void slider_Scroll(object sender, EventArgs e)
 {
     if (m_hNode.IsValid)
     {
         try {
             if (GenApi.NodeIsWritable(m_hNode))
             {
                 /* Correct the increment of the new value. */
                 int value = slider.Value - ((slider.Value - slider.Minimum) % slider.SmallChange);
                 /* Set the value. */
                 GenApi.IntegerSetValue(m_hNode, value);
             }
         }
         catch {
             /* Ignore any errors here. */
         }
     }
 }
示例#7
0
 public void valueChanged(int value)
 {
     if (m_hNode.IsValid)
     {
         try
         {
             if (GenApi.NodeIsWritable(m_hNode))
             {
                 /* Correct the increment of the new value. */
                 /* Set the value. */
                 GenApi.IntegerSetValue(m_hNode, value);
             }
         }
         catch
         {
             /* Ignore any errors here. */
         }
     }
 }
示例#8
0
        /* This function demonstrates how to handle integer camera parameters. */
        private static void demonstrateIntFeature(PYLON_DEVICE_HANDLE hDev)
        {
            NODEMAP_HANDLE  hNodeMap;
            NODE_HANDLE     hNode;
            string          featureName = "Width"; /* Name of the feature used in this sample: AOI Width. */
            long            val, min, max, incr;   /* Properties of the feature. */
            EGenApiNodeType nodeType;
            bool            bval;

            /* 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 an integer feature node. */
            nodeType = GenApi.NodeGetType(hNode);

            if (EGenApiNodeType.IntegerNode != nodeType)
            {
                Console.WriteLine("'" + featureName + "' is not an integer feature.");
                return;
            }

            /*
             * Query the current value, the range of allowed values, and the increment of the feature.
             * For some integer features, you are not allowed to set every value within the
             * value range. For example, for some cameras the Width parameter must be a multiple
             * of 2. These constraints are expressed by the increment value. Valid values
             * follow the rule: val >= min && val <= max && val == min + n * inc.
             */

            bval = GenApi.NodeIsReadable(hNode);


            if (bval)
            {
                min  = GenApi.IntegerGetMin(hNode);      /* Get the minimum value. */
                max  = GenApi.IntegerGetMax(hNode);      /* Get the maximum value. */
                incr = GenApi.IntegerGetInc(hNode);      /* Get the increment value. */
                val  = GenApi.IntegerGetValue(hNode);    /* Get the current value. */

                Console.WriteLine("{0}: min= {1}  max= {2}  incr={3}  Value={4}", featureName, min, max, incr, val);

                bval = GenApi.NodeIsWritable(hNode);

                if (bval)
                {
                    /* Set the Width parameter half-way between minimum and maximum. */
                    val = min + (max - min) / incr / 2 * incr;
                    Console.WriteLine("Setting {0} to {1}", featureName, val);
                    GenApi.IntegerSetValue(hNode, val);
                }
                else
                {
                    Console.WriteLine("Cannot set value for feature '{0}' - node not writable.", featureName);
                }
            }
            else
            {
                Console.WriteLine("Cannot read feature '{0}' - node not readable.", featureName);
            }
        }
        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);
            }
        }
示例#10
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);
                }
            }
        }
示例#11
0
        /// <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);
            }
        }