Ejemplo n.º 1
0
 /* A device has been opened. Update the control. */
 private void DeviceOpenedEventHandler()
 {
     if (InvokeRequired)
     {
         /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */
         BeginInvoke(new ImageProvider.DeviceOpenedEventHandler(DeviceOpenedEventHandler));
         return;
     }
     try
     {
         /* Get the node. */
         m_hNode = m_imageProvider.GetNodeFromDevice(name);
         /* Register for changes. */
         m_hCallbackHandle = GenApi.NodeRegisterCallback(m_hNode, m_nodeCallbackHandler);
         /* Update the displayed name. */
         labelName.Text = GenApi.NodeGetDisplayName(m_hNode) + ":";
         /* Update the control values. */
         UpdateValues();
     }
     catch
     {
         /* If errors occurred disable the control. */
         Reset();
     }
 }
Ejemplo n.º 2
0
        public void OneFrame()
        {
            try
            {
                lock (dev)
                {
                    Pylon.DeviceOpen(dev, Pylon.cPylonAccessModeControl | Pylon.cPylonAccessModeStream);

                    PylonGrabResult_t  grabResult;
                    PylonBuffer <Byte> imgBuf = null;

                    if (!Pylon.DeviceGrabSingleFrame(dev, 0, ref imgBuf, out grabResult, 500))
                    {
                        Console.WriteLine("timeout");
                    }

                    if (grabResult.Status == EPylonGrabStatus.Grabbed)
                    {
                        OnGrabAndDispose(GrabResultToImage(grabResult, imgBuf));
                    }
                    else if (grabResult.Status == EPylonGrabStatus.Failed)
                    {
                        Console.Error.WriteLine("Frame wasn't grabbed successfully.  Error code = {1}", grabResult.ErrorCode);
                    }

                    Pylon.DeviceClose(dev);
                }
            }
            catch
            {
                Console.WriteLine(GenApi.GetLastErrorDetail());
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /*
         * Regardless of the parameter's type, any parameter value can be retrieved as a string. Likewise, each parameter
         * can be set by passing in a string. This function illustrates how to set and get the
         * Width parameter as a string. As demonstrated above, the Width parameter is of the integer type.
         */
        private static void demonstrateFromStringToString(PYLON_DEVICE_HANDLE hDev)
        {
            string featureName = "Width";   /* The name of the feature. */
            string value;

            /* Get the value of a feature as a string. */
            value = Pylon.DeviceFeatureToString(hDev, featureName);

            Console.WriteLine("{0}: {1}", featureName, value);

            /* A feature can be set as a string using the PylonDeviceFeatureFromString() function.
             * If the content of a string can not be converted to the type of the feature, an
             * error is returned. */

            try
            {
                Pylon.DeviceFeatureFromString(hDev, featureName, "fourty-two"); /* Cannot be converted to an integer. */
            }
            catch (Exception e)
            {
                /* Retrieve the error message. */
                string msg = GenApi.GetLastErrorMessage() + "\n" + GenApi.GetLastErrorDetail();
                Console.WriteLine("Exception caught:");
                Console.WriteLine(e.Message);
                if (msg != "\n")
                {
                    Console.WriteLine("Last error message:");
                    Console.WriteLine(msg);
                }
            }
        }
Ejemplo n.º 6
0
        public static void WriteEnum(PYLON_DEVICE_HANDLE deviceHandle, string enumerationName, string enumerationValue)
        {
            NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle);
            NODE_HANDLE    nodeHandle    = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName);

            WriteEnum(nodeHandle, enumerationName, enumerationValue);
        }
Ejemplo n.º 7
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);



                        float divided = slider.Value / 1000f;

                        var lerped = Lerp(maxValue, minValue, divided);
                        /* Set the value. */

                        Pylon.DeviceSetFloatFeature(m_imageProvider.m_hDevice, NodeName, lerped);
                    }
                }
                catch {
                    /* Ignore any errors here. */
                }
            }
        }
Ejemplo n.º 8
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);
                    }
                }
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        /* Load a boolean node. */
        private void LoadBooleanNode(string nodeName)
        {
            var nodeConf = Config.GetConfig(nodeName);

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



            var node = ImageProvider.GetNodeFromDevice(nodeName);



            if (node.IsValid)
            {
                if (GenApi.NodeIsWritable(node))
                {
                    GenApi.BooleanSetValue(node, value);
                }
            }
        }
Ejemplo n.º 11
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.º 12
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);
            }
        }
 /* Returns a GenICam parameter node handle of the device identified by the name of the node. */
 public NODE_HANDLE GetNodeFromDevice( string name )
 {
     if( m_open && !m_removed ) {
         NODEMAP_HANDLE hNodemap = Pylon.DeviceGetNodeMap( m_hDevice );
         return GenApi.NodeMapGetNode( hNodemap, name );
     }
     return new NODE_HANDLE();
 }
Ejemplo n.º 14
0
        public static string DeviceGetStringFeature(PYLON_DEVICE_HANDLE handle, string featureName)
        {
            NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(handle);
            NODE_HANDLE    nodeHandle    = GenApi.NodeMapGetNode(nodeMapHandle, featureName);
            string         featureValue  = GenApi.NodeToString(nodeHandle);

            return(featureValue);
        }
Ejemplo n.º 15
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.º 16
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.º 17
0
        /* Some features are boolean features that can be switched on and off.
         * This function illustrates how to access boolean features. */
        private static void demonstrateBooleanFeature(PYLON_DEVICE_HANDLE hDev)
        {
            NODEMAP_HANDLE  hNodeMap;
            NODE_HANDLE     hNode;
            string          featureName = "GammaEnable"; /* The name of the feature. */
            bool            value, bval;                 /* The value of the feature. */
            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 boolean feature node. */
            nodeType = GenApi.NodeGetType(hNode);

            if (EGenApiNodeType.BooleanNode != nodeType)
            {
                Console.WriteLine("'" + featureName + "' is not a boolean feature.");
                return;
            }

            /* Check to see if the feature is readable. */
            bval = GenApi.NodeIsReadable(hNode);

            if (bval)
            {
                /* Retrieve the current state of the feature. */
                value = GenApi.BooleanGetValue(hNode);

                Console.WriteLine("The {0} feature is {1}.", featureName, value ? "on" : "off");

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

                if (bval)
                {
                    value = (bool)!value;  /* New value. */
                    Console.WriteLine("Switching the {0} feature {1}.", featureName, value ? "on" : "off");
                    GenApi.BooleanSetValue(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);
            }
        }
Ejemplo n.º 18
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;
            }
        }
Ejemplo n.º 19
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.º 20
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;
            }
        }
        /* Creates the last error text from message and detailed text. */
        private string GetLastErrorText()
        {
            string lastErrorMessage = GenApi.GetLastErrorMessage();
            string lastErrorDetail = GenApi.GetLastErrorDetail();

            string lastErrorText = lastErrorMessage;
            if( lastErrorDetail.Length > 0 ) {
                lastErrorText += "\n\nDetails:\n";
            }
            lastErrorText += lastErrorDetail;
            return lastErrorText;
        }
Ejemplo n.º 22
0
        /* Saves enumeration node. */
        private void SaveStringNode(string nodeName)
        {
            var node = managedCamera.ImageProvider.GetNodeFromDevice(nodeName);



            if (node.IsValid)
            {
                var value = GenApi.NodeToString(node);
                config.SetConfig(nodeName, value.ToString());
            }
        }
Ejemplo n.º 23
0
        private static void demonstrateCategory(PYLON_DEVICE_HANDLE hDev)
        {
            NODEMAP_HANDLE hNodeMap;
            NODE_HANDLE    hNode;

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

            /* Look up the root node. */
            hNode = GenApi.NodeMapGetNode(hNodeMap, "Root");

            handleCategory(hNode, "");
        }
Ejemplo n.º 24
0
        public static void WriteStreamFormat(PYLON_DEVICE_HANDLE deviceHandle, string selectedFormatSymbol)
        {
            string enumerationName = "PixelFormat";

            NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle);
            NODE_HANDLE    nodeHandle    = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName);

            if (!nodeHandle.IsValid)
            {
                return;
            }

            try
            {
                bool available = GenApi.NodeIsAvailable(nodeHandle);
                if (!available)
                {
                    return;
                }

                uint itemCount = GenApi.EnumerationGetNumEntries(nodeHandle);
                for (uint i = 0; i < itemCount; i++)
                {
                    NODE_HANDLE entryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i);

                    if (!GenApi.NodeIsAvailable(entryHandle))
                    {
                        continue;
                    }

                    string value = GenApi.EnumerationEntryGetSymbolic(entryHandle);
                    if (value != selectedFormatSymbol)
                    {
                        continue;
                    }

                    if (GenApi.NodeToString(nodeHandle) == value)
                    {
                        continue;
                    }

                    GenApi.NodeFromString(nodeHandle, value);
                    break;
                }
            }
            catch
            {
                // Silent catch.
            }
        }
Ejemplo n.º 25
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());
                }
            }
        }
Ejemplo n.º 26
0
        public static string GetLastError()
        {
            // Similar to ImageProvider.GetLastError().
            string lastErrorMessage = GenApi.GetLastErrorMessage();
            string lastErrorDetail  = GenApi.GetLastErrorDetail();

            string lastErrorText = lastErrorMessage;

            if (lastErrorDetail.Length > 0)
            {
                lastErrorText += "\n\nDetails:\n";
            }
            lastErrorText += lastErrorDetail;
            return(lastErrorText);
        }
Ejemplo n.º 27
0
        /* Checkbox changed for auto brightness. */
        private void AutoBrightnessChanged(object sender, EventArgs e)
        {
            var nodeAutoExposure = managedCamera.ImageProvider.GetNodeFromDevice("ExposureAuto");



            if (nodeAutoExposure.IsValid)
            {
                bool writable = GenApi.NodeIsWritable(nodeAutoExposure);

                if (writable)
                {
                    GenApi.NodeFromString(nodeAutoExposure, autoBrightnessCheckbox.Checked ? "Continuous" : "Off");
                }
            }
        }
Ejemplo n.º 28
0
        private void OnInit(object sender, EventArgs e)
        {
            var imageProvider = managedCamera.ImageProvider;

            var autoNode = imageProvider.GetNodeFromDevice("ExposureAuto");

            if (autoNode.IsValid)
            {
                string selected = GenApi.NodeToString(autoNode);


                if (selected == "Off")
                {
                    autoBrightnessCheckbox.Checked = false;
                }
                else
                {
                    autoBrightnessCheckbox.Checked = true;
                }
            }


            ExposureSlider.MyImageProvider = imageProvider;
            GainSlider.MyImageProvider     = imageProvider;
            WidthSlider.MyImageProvider    = imageProvider;
            HeightSlider.MyImageProvider   = imageProvider;
            xPosBar.MyImageProvider        = imageProvider;
            yPosBar.MyImageProvider        = imageProvider;
            BrightnessBar.MyImageProvider  = imageProvider;


            ExposureSlider.MaximumExposure = maxExposure;



            ExposureSlider.DeviceOpenedEventHandler();
            GainSlider.DeviceOpenedEventHandler();
            WidthSlider.DeviceOpenedEventHandler();
            HeightSlider.DeviceOpenedEventHandler();
            xPosBar.DeviceOpenedEventHandler();
            yPosBar.DeviceOpenedEventHandler();
            BrightnessBar.DeviceOpenedEventHandler();



            cameraLabel.Text = managedCamera.Name;
        }
Ejemplo n.º 29
0
        /* Get the current values from the node and display them. */
        private void UpdateValues()
        {
            try
            {
                if (m_hNode.IsValid)
                {
                    if (GenApi.NodeGetType(m_hNode) == EGenApiNodeType.EnumerationNode) /* Check is proper node type. */
                    {
                        /* Check is writable. */
                        bool writable = GenApi.NodeIsWritable(m_hNode);

                        /* Get the number of enumeration values. */
                        uint itemCount = GenApi.EnumerationGetNumEntries(m_hNode);

                        /* Clear the combo box. */
                        comboBox.Items.Clear();

                        /* Get all enumeration values, add them to the combo box, and set the selected item. */

                        string aa       = PylonC.NET.Pylon.DeviceFeatureToString((PylonC.NET.PYLON_DEVICE_HANDLE)m_imageProvider.m_hDevice, NodeName);
                        string selected = GenApi.NodeToString(m_hNode);
                        for (uint i = 0; i < itemCount; i++)
                        {
                            NODE_HANDLE hEntry = GenApi.EnumerationGetEntryByIndex(m_hNode, i);
                            if (GenApi.NodeIsAvailable(hEntry))
                            {
                                comboBox.Items.Add(GenApi.NodeGetDisplayName(hEntry));
                                if (selected == GenApi.EnumerationEntryGetSymbolic(hEntry))
                                {
                                    comboBox.SelectedIndex = comboBox.Items.Count - 1;
                                }
                            }
                        }

                        /* Update accessibility. */
                        comboBox.Enabled  = writable;
                        labelName.Enabled = writable;
                        return;
                    }
                }
            }
            catch
            {
                /* If errors occurred disable the control. */
            }
            Reset();
        }
Ejemplo n.º 30
0
        public static List <StreamFormat> GetSupportedStreamFormats(PYLON_DEVICE_HANDLE deviceHandle)
        {
            // We get a list of all possible values from GenICam API.
            // We cannot use the Pylon .NET enum names because of casing mismatches.
            // Then for each possible value, we poll for availability through Pylon API.

            string enumerationName = "PixelFormat";

            NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle);
            NODE_HANDLE    nodeHandle    = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName);

            if (!nodeHandle.IsValid)
            {
                return(null);
            }

            EGenApiNodeType nodeType = GenApi.NodeGetType(nodeHandle);

            if (nodeType != EGenApiNodeType.EnumerationNode)
            {
                return(null);
            }

            List <StreamFormat> supportedList = new List <StreamFormat>();
            uint total = GenApi.EnumerationGetNumEntries(nodeHandle);

            for (uint i = 0; i < total; i++)
            {
                NODE_HANDLE enumEntryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i);

                string symbol = GenApi.EnumerationEntryGetSymbolic(enumEntryHandle);
                //string symbol = GenApi.NodeGetDisplayName(entryHandle);

                //string featureName = string.Format("EnumEntry_{0}_{1}", enumerationName, symbol);
                //bool supported = Pylon.DeviceFeatureIsAvailable(deviceHandle, featureName);
                bool supported = GenApi.NodeIsAvailable(enumEntryHandle);

                if (supported)
                {
                    string displayName = GenApi.NodeGetDisplayName(enumEntryHandle);
                    supportedList.Add(new StreamFormat(symbol, displayName));
                }
            }

            return(supportedList);
        }