Ejemplo n.º 1
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);
            }
        }