예제 #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
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        /* Get the current values from the node and display them. */
        private void UpdateValues()
        {
            try {
                if (m_hNode.IsValid)
                {
                    /* Check if proper node type. */
                    if (GenApi.NodeGetType(m_hNode) == EGenApiNodeType.IntegerNode)
                    {
                        /* Get the values. */
                        bool writable = GenApi.NodeIsWritable(m_hNode);

                        int min = checked ((int)GenApi.IntegerGetMin(m_hNode));
                        int max = checked ((int)GenApi.IntegerGetMax(m_hNode));
                        int val = checked ((int)GenApi.IntegerGetValue(m_hNode));
                        int inc = checked ((int)GenApi.IntegerGetInc(m_hNode));

                        if (name == "ExposureTimeRaw")
                        {
                            max = MaximumExposure;

                            if (val > max)
                            {
                                val = max;
                            }
                        }

                        /* Update the slider. */
                        slider.Minimum       = min;
                        slider.Maximum       = max;
                        slider.Value         = val;
                        slider.SmallChange   = inc;
                        slider.TickFrequency = (max - min + 5) / 10;

                        labelCurrentValue.Maximum = max;
                        labelCurrentValue.Minimum = min;

                        /* Update the values. */
                        labelMin.Text          = "" + min;
                        labelMax.Text          = "" + max;
                        labelCurrentValue.Text = "" + val;

                        /* Update accessibility. */
                        slider.Enabled            = writable;
                        labelMin.Enabled          = writable;
                        labelMax.Enabled          = writable;
                        labelName.Enabled         = writable;
                        labelCurrentValue.Enabled = writable;

                        return;
                    }
                }
            }
            catch  {
                /* If errors occurred disable the control. */
            }
            //Reset ();
        }
예제 #5
0
        /// <summary>
        /// Statistic_Failed_Packet_Count 読み出し
        /// </summary>
        public long Get_Statistic_Failed_Packet_Count()
        {
            try
            {
                NODE_HANDLE     hNode;
                EGenApiNodeType nodeType;
                bool            bval;        /* Is the feature available? */
                string          featureName; /* Name of the feature used in this sample: AOI Width. */
                //bool isAvailable;              /* Is the feature available? */
                //double val = 0;      /* Properties of the feature. */
                long val, min, max, incr;      /* Properties of the feature. */
                featureName = "Statistic_Failed_Packet_Count";

                hNode = m_imageProvider.GetNodeFromDevice(featureName);
                if (!hNode.IsValid)
                {
                    Console.WriteLine("There is no feature named '" + featureName + "'.");
                    return(0);
                }
                /* We want a float feature node. */
                nodeType = GenApi.NodeGetType(hNode);

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

                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. */

                    return(val);
                }
                return(0);
            }
            catch
            {
                // UpdateLastError();   /* Get the last error message here, because it could be overwritten by cleaning up. */
                try
                {
                    Close(); /* Try to close any open handles. */
                }
                catch
                {
                    /* Another exception cannot be handled. */
                }
                throw;
            }
        }
예제 #6
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);
            }
        }
예제 #7
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);
                }
            }
        }
예제 #8
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);
            }
        }