示例#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.
            }
        }
示例#2
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();
        }
示例#3
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);
        }
示例#4
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.
            }
        }
示例#5
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. */
                }
            }
        }
示例#6
0
        public static StreamFormat GetCurrentStreamFormat(PYLON_DEVICE_HANDLE deviceHandle)
        {
            StreamFormat sf = null;

            string enumerationName = "PixelFormat";

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

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

            string selected = GenApi.NodeToString(nodeHandle);

            uint itemCount = GenApi.EnumerationGetNumEntries(nodeHandle);

            for (uint i = 0; i < itemCount; i++)
            {
                NODE_HANDLE entryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i);
                string      symbol      = GenApi.EnumerationEntryGetSymbolic(entryHandle);
                if (selected != symbol)
                {
                    continue;
                }

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

                string displayName = GenApi.NodeGetDisplayName(entryHandle);
                sf = new StreamFormat(symbol, displayName);
                break;
            }

            return(sf);
        }
示例#7
0
        /* Enumerate all possible entries for an enumerated feature. For every entry, a selection
         * of properties is displayed. A loop similar to the one shown below may be part of a
         * GUI program that wants to fill the entries of a menu. */
        private static void demonstrateEnumIteration(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);

            if (bval)
            {
                uint max, i;

                /* Check entries. */
                max = GenApi.EnumerationGetNumEntries(hNode);

                /* Write out header. */
                Console.WriteLine("Allowed values for feature '{0}':\n" +
                                  "--------------",
                                  featureName);

                /* A loop to visit every enumeration entry node once. */
                for (i = 0; i < max; i++)
                {
                    NODE_HANDLE hEntry;
                    string      name, displayName, description;
                    bool        avail;

                    /* Get handle for enumeration entry node. */
                    hEntry = GenApi.EnumerationGetEntryByIndex(hNode, i);

                    /* Get node name. */
                    name = GenApi.NodeGetName(hEntry);

                    /* Get display name. */
                    displayName = GenApi.NodeGetDisplayName(hEntry);

                    /* Get description. */
                    description = GenApi.NodeGetDescription(hEntry);

                    /* Get availability. */
                    avail = GenApi.NodeIsAvailable(hEntry);

                    /* Write out results. */
                    Console.WriteLine("Node name:    {0}\n" +
                                      "Display name: {1}\n" +
                                      "Description:  {2}\n" +
                                      "Available:    {3}\n" +
                                      "--------------",
                                      name, displayName, description, avail ? "yes" : "no");
                }
            }
            else
            {
                Console.WriteLine("Cannot read feature '{0}' - node not readable.", featureName);
            }
        }