Exemple #1
0
        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);
        }
Exemple #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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Expo値読み出し[us]
        /// </summary>
        public double GetExposureTime()
        {
            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. */

                featureName = "ExposureTimeAbs";

                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)
                {
                    /* Query the value range and the current value. */
                    val = GenApi.FloatGetValue(hNode);

                    return(val); // [us]
                }
                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;
            }
        }
Exemple #4
0
        /* Saves float nodes. */
        private void SaveFloatNode(params string [] nodeNames)
        {
            foreach (var name in nodeNames)
            {
                var node = managedCamera.ImageProvider.GetNodeFromDevice(name);



                if (node.IsValid)
                {
                    var value = GenApi.FloatGetValue(node);
                    config.SetConfig(name, value.ToString());
                }
            }
        }
        /* Get the current values from the node and display them. */
        private void UpdateValues()
        {
            try {
                if (m_hNode.IsValid)
                {
                    var nodeType = GenApi.NodeGetType(m_hNode);
                    /* Check if proper node type. */
                    if (GenApi.NodeGetType(m_hNode) == EGenApiNodeType.FloatNode)
                    {
                        /* Get the values. */
                        bool writable = GenApi.NodeIsWritable(m_hNode);

                        maxValue = checked ((float)GenApi.FloatGetMax(m_hNode));
                        minValue = checked ((float)GenApi.FloatGetMin(m_hNode));

                        float val = checked ((float)GenApi.FloatGetValue(m_hNode));



                        int inc = 50;

                        int max = 1000;
                        int min = 0;

                        float valueOfThousand = InverseLerp(maxValue, minValue, val) * 1000;

                        int value = (int)valueOfThousand;


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

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

                        /* Update the slider. */
                        slider.Minimum       = min;
                        slider.Maximum       = max;
                        slider.Value         = value;
                        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 = "" + value;

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