Exemple #1
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.
            }
        }
Exemple #2
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");
                }
            }
        }
Exemple #3
0
        public static void WriteEnum(NODE_HANDLE nodeHandle, string enumerationName, string enumerationValue)
        {
            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 != enumerationValue)
                    {
                        continue;
                    }

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

                    GenApi.NodeFromString(nodeHandle, value);
                    break;
                }
            }
            catch
            {
                // Silent catch.
            }
        }
Exemple #4
0
        /* Handle selection changes. */
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (m_hNode.IsValid)
            {
                try
                {
                    /* If writable and combo box selection ok. */
                    if (GenApi.NodeIsAvailable(m_hNode) && comboBox.SelectedIndex >= 0)
                    {
                        /* Get the displayed selected enumeration value. */
                        string selectedDisplayName = comboBox.GetItemText(comboBox.Items[comboBox.SelectedIndex]);

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

                        /* Determine the symbolic name of the selected item and set it if different. */
                        for (uint i = 0; i < itemCount; i++)
                        {
                            NODE_HANDLE hEntry = GenApi.EnumerationGetEntryByIndex(m_hNode, i);
                            if (GenApi.NodeIsAvailable(hEntry))
                            {
                                if (GenApi.NodeGetDisplayName(hEntry) == selectedDisplayName)
                                {
                                    /* Get the value to set. */
                                    string value = GenApi.EnumerationEntryGetSymbolic(hEntry);
                                    /* Set the value if other than the current value of the node. */
                                    if (GenApi.NodeToString(m_hNode) != value)
                                    {
                                        GenApi.NodeFromString(m_hNode, value);
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    /* Ignore any errors here. */
                }
            }
        }
Exemple #5
0
        public void SetCameraTriggerMode()
        {
            bool        bval;
            NODE_HANDLE m_hNode = new NODE_HANDLE();

            m_hNode = m_imageProvider.GetNodeFromDevice("TriggerSelector");
            if (!m_hNode.IsValid)
            {
                return;
            }
            bval = GenApi.NodeIsWritable(m_hNode);
            if (!bval)
            {
                return;
            }
            GenApi.NodeFromString(m_hNode, "FrameStart");

            m_hNode = m_imageProvider.GetNodeFromDevice("TriggerMode");
            if (!m_hNode.IsValid)
            {
                return;
            }
            bval = GenApi.NodeIsWritable(m_hNode);
            if (!bval)
            {
                return;
            }
            GenApi.NodeFromString(m_hNode, "On");

            m_hNode = m_imageProvider.GetNodeFromDevice("TriggerSource");
            if (!m_hNode.IsValid)
            {
                return;
            }
            bval = GenApi.NodeIsWritable(m_hNode);
            if (!bval)
            {
                return;
            }
            GenApi.NodeFromString(m_hNode, "Software");
        }
Exemple #6
0
        /* Load a string node. */
        private void LoadStringNode(string nodeName)
        {
            var nodeConf = Config.GetConfig(nodeName);

            if (nodeConf == null || string.IsNullOrWhiteSpace(nodeConf))
            {
                return;
            }



            var node = ImageProvider.GetNodeFromDevice(nodeName);



            if (node.IsValid)
            {
                if (GenApi.NodeIsWritable(node))
                {
                    GenApi.NodeFromString(node, nodeConf);
                }
            }
        }
Exemple #7
0
        /* There are camera features, such as AcquisitionStart, that represent a command.
         * This function that loads the default set, illustrates how to execute a command feature.  */
        private static void demonstrateCommandFeature(PYLON_DEVICE_HANDLE hDev)
        {
            string selectorName = "UserSetSelector",
                   commandName  = "UserSetLoad";
            NODEMAP_HANDLE  hNodeMap;
            NODE_HANDLE     hCommand, hSelector;
            EGenApiNodeType nodeType;
            bool            bval;

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

            /* Look up the command node. */
            hCommand = GenApi.NodeMapGetNode(hNodeMap, commandName);
            if (!hCommand.IsValid)
            {
                Console.WriteLine("There is no node named '" + commandName + "'.");
                return;
            }

            /* Look up the selector node. */
            hSelector = GenApi.NodeMapGetNode(hNodeMap, selectorName);
            if (!hSelector.IsValid)
            {
                Console.WriteLine("There is no node named '" + selectorName + "'.");
                return;
            }

            /* We want a command feature node. */
            nodeType = GenApi.NodeGetType(hCommand);

            if (EGenApiNodeType.CommandNode != nodeType)
            {
                Console.WriteLine("'" + selectorName + "' is not a command feature.");
                return;
            }

            /* Before executing the user set load command, the user set selector must be
             * set to the default set. */

            /* Check to see if the selector is writable. */
            bval = GenApi.NodeIsWritable(hSelector);

            if (bval)
            {
                /* Choose the default set (which includes one of the factory setups). */
                GenApi.NodeFromString(hSelector, "Default");
            }
            else
            {
                Console.WriteLine("Cannot set selector '{0}' - node not writable.", selectorName);
            }


            /* Check to see if the command is writable. */
            bval = GenApi.NodeIsWritable(hCommand);

            if (bval)
            {
                /* Execute the user set load command. */
                Console.WriteLine("Loading the default set.");
                GenApi.CommandExecute(hCommand);
            }
            else
            {
                Console.WriteLine("Cannot execute command '{0}' - node not writable.", commandName);
            }
        }
Exemple #8
0
        /* There are camera features that behave like enumerations. These features can take a value from a fixed
         * set of possible values. One example is the pixel format feature. This function illustrates how to deal with
         * enumeration features.
         */
        private static void demonstrateEnumFeature(PYLON_DEVICE_HANDLE hDev)
        {
            string          featureName = "PixelFormat";
            NODEMAP_HANDLE  hNodeMap;
            NODE_HANDLE     hNode;
            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 enumeration feature node. */
            nodeType = GenApi.NodeGetType(hNode);

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

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

            /* The allowed values for an enumeration feature are represented as strings. Use the
             * GenApi.NodeFromString and GenApi.NodeToString methods for setting and getting
             * the value of an enumeration feature. */

            if (bval)
            {
                /* Symbolic names of pixel formats. */
                string symMono8        = "Mono8",
                       symMono16       = "Mono16",
                       symYUV422Packed = "YUV422Packed";

                string value;   /* The current value of the feature. */
                bool   supportsMono8,
                       supportsYUV422Packed,
                       supportsMono16;
                NODE_HANDLE hEntry;


                /* Get the current value of the enumeration feature. */
                value = GenApi.NodeToString(hNode);

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

                /*
                 * For an enumeration feature, the pylon Viewer's "Feature Documentation" window lists the
                 * names of the possible values. Some of the values may not be supported by the device.
                 * To check if a certain "SomeValue" value for a "SomeFeature" feature can be set, call the
                 * GenApi.NodeIsAvailable() function on the node of the entry.
                 */
                /* Check to see if the Mono8 pixel format can be set. */
                hEntry        = GenApi.EnumerationGetEntryByName(hNode, symMono8);
                supportsMono8 = hEntry.IsValid && GenApi.NodeIsAvailable(hEntry);
                Console.WriteLine("{0} {1} a supported value for the pixel format feature.", symMono8, supportsMono8 ? "is" : "is not");

                /* Check to see if the YUV422Packed pixel format can be set. */
                hEntry = GenApi.EnumerationGetEntryByName(hNode, symYUV422Packed);
                supportsYUV422Packed = hEntry.IsValid && GenApi.NodeIsAvailable(hEntry);
                Console.WriteLine("{0} {1} a supported value for the pixel format feature.", symYUV422Packed, supportsYUV422Packed ? "is" : "is not");

                /* Check to see if the Mono16 pixel format can be set. */
                hEntry         = GenApi.EnumerationGetEntryByName(hNode, symMono16);
                supportsMono16 = hEntry.IsValid && GenApi.NodeIsAvailable(hEntry);
                Console.WriteLine("{0} {1} a supported value for the pixel format feature.", symMono16, supportsMono16 ? "is" : "is not");


                /* Before writing a value, we recommend checking to see if the enumeration feature is
                 * currently writable. */
                bval = GenApi.NodeIsWritable(hNode);

                if (bval)
                {
                    /* The PixelFormat feature is writable. Set it to one of the supported values. */
                    if (supportsMono16)
                    {
                        Console.WriteLine("Setting PixelFormat to Mono16.");
                        GenApi.NodeFromString(hNode, symMono16);
                    }
                    else if (supportsYUV422Packed)
                    {
                        Console.WriteLine("Setting PixelFormat to YUV422Packed.");
                        GenApi.NodeFromString(hNode, symYUV422Packed);
                    }
                    else if (supportsMono8)
                    {
                        Console.WriteLine("Setting PixelFormat to Mono8.");
                        GenApi.NodeFromString(hNode, symMono8);
                    }

                    /* Reset the PixelFormat feature to its previous value. */
                    GenApi.NodeFromString(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 #9
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. */
            NODEMAP_HANDLE  hNodeMap;
            NODE_HANDLE     hNode;
            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;
            }

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

            if (bval)
            {
                string valueString;

                /* Get the value of a feature as a string. */
                valueString = GenApi.NodeToString(hNode);

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

                /* A feature can be set as a string using the GenApi.NodeFromString() function.
                 * If the content of a string can not be converted to the type of the feature, an
                 * error is returned. */
                bval = GenApi.NodeIsWritable(hNode);

                if (bval)
                {
                    try
                    {
                        GenApi.NodeFromString(hNode, "fourty-two"); /* Can not 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);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Cannot set value for feature '{0}' - node not writable.", featureName);
                }
            }
            else
            {
                Console.WriteLine("Cannot read feature '{0}' - node not readable.", featureName);
            }
        }