Ejemplo n.º 1
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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 ();
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 6
0
        /* Saves the nodes into config for future uses. */
        private void SaveIntegerNode(params string[] nodeNames)
        {
            foreach (var name in nodeNames)
            {
                var node = managedCamera.ImageProvider.GetNodeFromDevice(name);



                if (node.IsValid)
                {
                    var value = GenApi.IntegerGetValue(node);
                    config.SetConfig(name, value.ToString());
                }
            }
        }
Ejemplo n.º 7
0
 /* Callback will be fired when an event message contains an end-of-exposure event. */
 private static void endOfExposureCallback(NODE_HANDLE hNode)
 {
     try
     {
         long frame;
         frame = GenApi.IntegerGetValue(hNode);
         Console.WriteLine("Got end-of-exposure event. Frame number: {0}.", frame);
     }
     catch (Exception e)
     {
         string msg = GenApi.GetLastErrorMessage() + "\n" + GenApi.GetLastErrorDetail();
         Console.Error.WriteLine("Exception caught:");
         Console.Error.WriteLine(e.Message);
         if (msg != "\n")
         {
             Console.Error.WriteLine("Last error message:");
             Console.Error.WriteLine(msg);
         }
     }
 }
Ejemplo n.º 8
0
        public void GetGainValue()
        {
            bool bval;
            //ExposureTimeRaw
            NODE_HANDLE m_hNode = new NODE_HANDLE();

            m_hNode = m_imageProvider.GetNodeFromDevice("GainRaw");
            if (m_hNode.IsValid)
            {
                if (!m_hNode.IsValid)
                {
                    return;
                }
                bval = GenApi.NodeIsWritable(m_hNode);
                if (!bval)
                {
                    return;
                }
                double result = GenApi.IntegerGetValue(m_hNode);
                Console.WriteLine(result);
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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);
            }
        }