Esempio n. 1
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);
                    }
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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");
        }
Esempio n. 4
0
        /* Handles the selection of cameras from the list box. The currently open device is closed and the first
         * selected device is opened. */
        private void deviceListView_SelectedIndexChanged(object sender, EventArgs ev)
        {
            /* Close the currently open image provider. */
            /* Stops the grabbing of images. */
            Stop();
            /* Close the image provider. */
            CloseTheImageProvider();


            /* Open the selected image provider. */
            if (deviceListView.SelectedItems.Count > 0)
            {
                /* Get the first selected item. */
                ListViewItem item = deviceListView.SelectedItems[0];
                /* Get the attached device data. */
                DeviceEnumerator.Device device = (DeviceEnumerator.Device)item.Tag;
                try
                {
                    /* Open the image provider using the index from the device data. */
                    m_imageProvider.Open(device.Index);
                    m_imageProvider.GetNodeFromDevice(device.Name);
                    hDev = Pylon.CreateDeviceByIndex(device.Index);
                }
                catch (Exception e)
                {
                    ShowException(e, m_imageProvider.GetLastErrorMessage());
                }
            }
            //          Console.WriteLine(m_imageProvider.get_integerParam("Width").ToString());

//            hDev = new PYLON_DEVICE_HANDLE();
//          Pylon.Initialize();

            /* Enumerate all camera devices. You must call
             * PylonEnumerateDevices() before creating a device. */

/*            if (0 == Pylon.EnumerateDevices())
 *          {
 *              throw new Exception("No devices found.");
 *          }
 */
        }
Esempio n. 5
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);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes and Opens the Pylon Image Provider to the Camera.
        /// </summary>
        /// <param name="maxExposure">Maximum Exposure.</param>
        public void Initialize(int maxExposure)
        {
            log.Info("Initializing camera on Index: " + Index + "...");


            log.Info("Creating Buffermanager(" + Index + ")...");


            ImageBuffers = new BufferManager();

            ImageBuffers.Initialize();


            log.Info("Buffermanager (" + Index + ") Created with " + ImageBuffers.ThreadCount + " threads.");



            log.Info("Initializing Worker threads on Cam(" + Index + ")...");

            worker = new JobWorker(this, ImageBuffers);

            worker.Initialize();

            log.Info("Worker Threads(" + Index + ") Created with " + worker.ThreadCount + " threads.");


            log.Info("Creating Image Providers(" + Index + ")...");

            ImageProvider = new ImageProvider();

            ImageProvider.ImageReadyAction = OnImageReadyHandler;
            //ImageProvider.ImageReadyEvent += OnImageReadyHandler;
            ImageProvider.DeviceRemovedEvent += OnDeviceRemovedHandler;



            log.Info("Image Provider(" + Index + ") created successfully.");
            log.Info("Opening the Basler(" + Index + ") device...");

            Open();

            log.Info("Basler(" + Index + ") is now open!");


            /* Config part. */
            log.Info("Loading config for '" + Name + "'...");

            Config = new ConfigManager(Name);

            LoadConfigNodes(
                "Width", "Height",
                "OffsetX", "OffsetY"
                );

            LoadFloatNodes(
                "Gain", "ExposureTime",
                "AutoTargetBrightness"
                );

            LoadStringNode("ExposureAuto");

            // Setting max Exposure.
            var node = ImageProvider.GetNodeFromDevice("AutoExposureTimeUpperLimit");

            if (node.IsValid)
            {
                if (GenApi.NodeIsWritable(node))
                {
                    Pylon.DeviceSetFloatFeature(ImageProvider.m_hDevice, "AutoExposureTimeUpperLimit", maxExposure);
                }
            }


            log.Info("Loaded configurations for the camera '" + Name + "'.");

            /* Done config part. */
        }
Esempio n. 7
0
        /// <summary>
        ///  A device has been opened. Update the control.
        /// </summary>
        public 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 MethodInvoker(DeviceOpenedEventHandler));                 //new ImageProvider.DeviceOpenedEventHandler (DeviceOpenedEventHandler));
                return;
            }
            try {
                /* Get the node. */
                m_hNode = m_imageProvider.GetNodeFromDevice(name);

                /* Features, like 'Gain', are named according to the GenICam Standard Feature Naming Convention (SFNC).
                 * The SFNC defines a common set of features, their behavior, and the related parameter names.
                 * This ensures the interoperability of cameras from different camera vendors.
                 *
                 * Some cameras, e.g. cameras compliant to the USB3 Vision standard, use a later SFNC version than
                 * previous Basler GigE and Firewire cameras. Accordingly, the behavior of these cameras and
                 * some parameters names will be different.
                 */
                if (!m_hNode.IsValid &&              /* No node has been found using the provided name. */
                    (name == "GainRaw" || name == "ExposureTimeRaw"))                        /* This means probably that the camera is compliant to a later SFNC version. */
                {
                    /* Check to see if a compatible node exists. The SFNC 2.0, implemented by Basler USB Cameras for instance, defines Gain
                     * and ExposureTime as features of type Float.*/
                    if (name == "GainRaw")
                    {
                        m_hNode = m_imageProvider.GetNodeFromDevice("Gain");
                    }
                    else if (name == "ExposureTimeRaw")
                    {
                        m_hNode = m_imageProvider.GetNodeFromDevice("ExposureTime");
                    }
                    /* Update the displayed name. */
                    labelName.Text = GenApi.NodeGetDisplayName(m_hNode) + ":";

                    /* The underlying integer representation of Gain and ExposureTime can be accessed using
                     * the so called alias node. The alias is another representation of the original parameter.
                     *
                     * Since this slider control can only be used with Integer nodes we have to use
                     * the alias node here to display and modify Gain and ExposureTime.
                     */
                    m_hNode = GenApi.NodeGetAlias(m_hNode);
                    /* Register for changes. */
                    m_hCallbackHandle = GenApi.NodeRegisterCallback(m_hNode, m_nodeCallbackHandler);
                }
                else
                {
                    /* Update the displayed name. */
                    labelName.Text = GenApi.NodeGetDisplayName(m_hNode) + "مقدار:";
                    /* Register for changes. */
                    m_hCallbackHandle = GenApi.NodeRegisterCallback(m_hNode, m_nodeCallbackHandler);
                }
                /* Update the control values. */
                UpdateValues();
            }
            catch {
                /* If errors occurred disable the control. */
                Reset();
            }
        }