Beispiel #1
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)
        {
            string featureName = "Gamma";  /* The name of the feature used. */
            bool   isAvailable;            /* Is the feature available? */
            bool   isWritable;             /* Is the feature writable? */
            double min, max, value;        /* Value range and current value. */

            isAvailable = Pylon.DeviceFeatureIsAvailable(hDev, featureName);

            if (isAvailable)
            {
                /* Query the value range and the current value. */
                min   = Pylon.DeviceGetFloatFeatureMin(hDev, featureName);
                max   = Pylon.DeviceGetFloatFeatureMax(hDev, featureName);
                value = Pylon.DeviceGetFloatFeature(hDev, featureName);

                Console.WriteLine("{0}: min = {1}, max = {2}, value = {3}", featureName, min, max, value);

                /* Set a new value. */
                isWritable = Pylon.DeviceFeatureIsWritable(hDev, featureName);
                if (isWritable)
                {
                    value = 0.5 * (min + max);
                    Console.WriteLine("Setting {0} to {1}.", featureName, value);
                    Pylon.DeviceSetFloatFeature(hDev, featureName, value);
                }
            }
            else
            {
                Console.WriteLine("The {0} feature isn't available.", featureName);
            }
        }
        /* 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. */
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 設定 Device Handle 功能
        /// </summary>
        /// <param name="hDev"></param>
        /// <param name="features"></param>
        /// <returns></returns>
        public bool SetPylonDeviceHandleFeatures(List <PylonFeature> features)
        {
            var  success = true;
            bool isAvail, isWritable;

            _latestMessage = "";
            foreach (var feature in features)
            {
                isAvail    = Pylon.DeviceFeatureIsAvailable(_pylonDevHandle, feature.Name);
                isWritable = Pylon.DeviceFeatureIsWritable(_pylonDevHandle, feature.Key);
                if (!isAvail)
                {
                    _latestMessage += "Device doesn't support the " + feature.Name + ";";
                    success         = false;
                }
                else if (!isWritable)
                {
                    _latestMessage += "Writable doesn't support the " + feature.Name + ";";
                    success         = false;
                }
                else
                {
                    Type valueType = feature.Value.GetType();
                    switch (valueType.Name)
                    {
                    case "Boolean":
                        Pylon.DeviceSetBooleanFeature(_pylonDevHandle, feature.Key, (bool)feature.Value);
                        break;

                    case "String":
                        Pylon.DeviceFeatureFromString(_pylonDevHandle, feature.Key, (string)feature.Value);
                        break;

                    case "Int32":
                        Pylon.DeviceSetIntegerFeature(_pylonDevHandle, feature.Key, (int)feature.Value);
                        break;

                    case "Double":
                        Pylon.DeviceSetFloatFeature(_pylonDevHandle, feature.Key, (double)feature.Value);
                        break;
                    }
                }
            }
            return(success);
        }
Beispiel #4
0
        /// <summary>
        /// Set camera config.
        /// </summary>
        /// <param name="device">camera device</param>
        /// <param name="featureName">name of config</param>
        /// <param name="value">value of config</param>
        private void SetConfig(PYLON_DEVICE_HANDLE device, string featureName, object value)
        {
            try
            {
                if (value == null)
                {
                    return;
                }

                // Check to see if a feature is implemented, writable.
                bool isAvailable;
                bool isWritable;

                // Check feature
                isAvailable = Pylon.DeviceFeatureIsImplemented(device, featureName);
                isWritable  = Pylon.DeviceFeatureIsWritable(device, featureName);

                // Set config feature
                if (isAvailable && isWritable)
                {
                    if (value.GetType() == typeof(int))
                    {
                        Pylon.DeviceSetIntegerFeature(device, featureName, (int)value);
                    }

                    if (value.GetType() == typeof(float))
                    {
                        Pylon.DeviceSetFloatFeature(device, featureName, (float)value);
                    }

                    if (value.GetType() == typeof(string))
                    {
                        Pylon.DeviceFeatureFromString(device, featureName, (string)value);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void OnValueChanged(object sender, EventArgs e)
        {
            if (m_hNode.IsValid)
            {
                try {
                    if (GenApi.NodeIsWritable(m_hNode))
                    {
                        /* Correct the increment of the new value. */
                        var value = labelCurrentValue.Value;

                        float divided = (float)value / 1000f;

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

                        Pylon.DeviceSetFloatFeature(m_imageProvider.m_hDevice, NodeName, lerped);
                    }
                }
                catch {
                    /* Ignore any errors here. */
                }
            }
        }
Beispiel #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. */
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            for (uint i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case par_cameraSerialNumber:
                    arg_cameraSerialNumber = args[i + 1];
                    i++;
                    break;

                case par_pathToFile:
                    arg_pathToFile = args[i + 1];
                    i++;
                    break;

                case par_imageFormat:
                    arg_imageFormat = args[i + 1];
                    i++;
                    break;

                case par_packageSize:
                    arg_packageSize = args[i + 1];
                    i++;
                    break;

                case par_interPackageDelay:
                    arg_interPackageDelay = args[i + 1];
                    i++;
                    break;

                case par_attemptsToGrab:
                    arg_attemptsToGrab = args[i + 1];
                    i++;
                    break;

                case par_exposureTime:
                    arg_exposureTime = args[i + 1];
                    i++;
                    break;

                default:
                    break;
                }
            }

            //arg_exposureTime = "35000";

            bool error = false;

            if (arg_pathToFile.Length == 0)
            {
                Console.WriteLine("Path to file is empty");
                error = true;
            }

            if (!(arg_imageFormat.Equals("BMP") || !arg_imageFormat.Equals("PNG") || !arg_imageFormat.Equals("JPG") || !arg_imageFormat.Equals("RAW") || !arg_imageFormat.Equals("TIFF")))
            {
                Console.WriteLine("File format should be [BMP|PNG|JPG|RAW|TIFF]");
                error = true;
            }

            if (arg_cameraSerialNumber.Length == 0)
            {
                Console.WriteLine("Camera serial number is empty");
                error = true;
            }

            int exposureTime = 0;

            try
            {
                exposureTime = Int32.Parse(arg_exposureTime);
            }
            catch (Exception e)
            {
                Console.WriteLine("Wrong exposure time value");
                error = true;
            }

            int interPackageDelay = 0;

            try
            {
                interPackageDelay = Int32.Parse(arg_interPackageDelay);
            }
            catch (Exception e)
            {
                Console.WriteLine("Wrong interPackageDelay value");
                error = true;
            }

            int attemptsToGrap = 0;

            try
            {
                attemptsToGrap = Int16.Parse(arg_attemptsToGrab);
            }catch (Exception e) {
                Console.WriteLine("Wrong attempts to grab value");
                error = true;
            }
            //sodapef
            if (error)
            {
                Console.WriteLine("Parameters usage:");
                Console.WriteLine("-s  Camera serial number");
                Console.WriteLine("-o  Path to file");
                Console.WriteLine("-d  Inter package delay in ticks (default 1000)");
                Console.WriteLine("-a  Attempts tp grab image (default 1)");
                Console.WriteLine("-p  Package size (default 1500)");
                Console.WriteLine("-e  Exposure time (default 35000)");
                Console.WriteLine("-f  Image format [BMP|PNG|JPG|RAW|TIFF]");
                return;
            }

            PYLON_DEVICE_HANDLE hDev = new PYLON_DEVICE_HANDLE(); /* Handle for the pylon device. */

            try
            {
                uint               numDevices;      /* Number of available devices. */
                const int          numGrabs = 1;    /* Number of images to grab. */
                PylonBuffer <Byte> imgBuf   = null; /* Buffer used for grabbing. */
                bool               isAvail;
                Pylon.Initialize();
                numDevices = Pylon.EnumerateDevices();

                if (0 == numDevices)
                {
                    Console.WriteLine("Error: No devices found");
                    return;
                }

                bool deviceFound = false;
                uint deviceNum   = 0;
                for (uint di = 0; di < numDevices; di++)
                {
                    PYLON_DEVICE_INFO_HANDLE hDi = Pylon.GetDeviceInfoHandle((uint)di);
                    string serial = Pylon.DeviceInfoGetPropertyValueByName(hDi, Pylon.cPylonDeviceInfoSerialNumberKey);
                    deviceNum = di;
                    if (serial.Equals(arg_cameraSerialNumber))
                    {
                        deviceFound = true;
                        break;
                    }
                }

                if (!deviceFound)
                {
                    Console.WriteLine("Error: No devices found by serial number");
                    return;
                }

                hDev = Pylon.CreateDeviceByIndex(deviceNum);
                Pylon.DeviceOpen(hDev, Pylon.cPylonAccessModeControl | Pylon.cPylonAccessModeStream | Pylon.cPylonAccessModeExclusive);
                isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_PixelFormat_Mono8");

                if (!isAvail)
                {
                    Console.WriteLine("Error: Device doesn't support the Mono8 pixel format");
                    return;
                }

                Pylon.DeviceFeatureFromString(hDev, "PixelFormat", "Mono8");
                isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_TriggerSelector_AcquisitionStart");
                if (isAvail)
                {
                    Pylon.DeviceFeatureFromString(hDev, "TriggerSelector", "AcquisitionStart");
                    Pylon.DeviceFeatureFromString(hDev, "TriggerMode", "Off");
                }

                isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_TriggerSelector_FrameBurstStart");
                if (isAvail)
                {
                    Pylon.DeviceFeatureFromString(hDev, "TriggerSelector", "FrameBurstStart");
                    Pylon.DeviceFeatureFromString(hDev, "TriggerMode", "Off");
                }

                isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_TriggerSelector_FrameStart");
                if (isAvail)
                {
                    Pylon.DeviceFeatureFromString(hDev, "TriggerSelector", "FrameStart");
                    Pylon.DeviceFeatureFromString(hDev, "TriggerMode", "Off");
                }

                isAvail = Pylon.DeviceFeatureIsWritable(hDev, "GevSCPSPacketSize");

                if (isAvail)
                {
                    int packageSize = 1500;
                    try{
                        packageSize = Int32.Parse(arg_packageSize);
                    }
                    catch (Exception e) { }
                    Pylon.DeviceSetIntegerFeature(hDev, "GevSCPSPacketSize", packageSize);
                }

                isAvail = Pylon.DeviceFeatureIsWritable(hDev, "GevSCPD");

                if (isAvail)
                {
                    Pylon.DeviceSetIntegerFeature(hDev, "GevSCPD", interPackageDelay);
                }

                Pylon.DeviceFeatureFromString(hDev, "ExposureAuto", "Off");

                /*
                 * isAvail = Pylon.DeviceFeatureIsWritable(hDev, "ExposureTimeRaw");
                 * if (isAvail)
                 * {
                 *  try
                 *  {
                 *      Pylon.DeviceSetFloatFeature(hDev, "ExposureTimeRaw", exposureTime);
                 *  }
                 *  catch (Exception e)
                 *  {
                 *      Console.WriteLine("Some error 1");
                 *  }
                 * }*/


                isAvail = Pylon.DeviceFeatureIsWritable(hDev, "ExposureTimeAbs");
                if (isAvail)
                {
                    Pylon.DeviceSetFloatFeature(hDev, "ExposureTimeAbs", (long)exposureTime);

                    /*
                     * try{
                     *  Pylon.DeviceSetFloatFeature(hDev, "ExposureTimeAbs", (long)exposureTime);
                     * }catch (Exception e) {
                     *  //Console.WriteLine("Some error 2");
                     * }
                     */
                }

                Byte min, max;
                PylonGrabResult_t grabResult;

                for (int attempt = 0; attempt < attemptsToGrap; attempt++)
                {
                    if (!Pylon.DeviceGrabSingleFrame(hDev, 0, ref imgBuf, out grabResult, 5000))
                    {
                        /* Timeout occurred. */
                        //Console.WriteLine("Frame {0}: timeout.", i + 1);
                        Console.WriteLine("Error: timeout");
                    }

                    /* Check to see if the image was grabbed successfully. */
                    if (grabResult.Status == EPylonGrabStatus.Grabbed)
                    {
                        /* Success. Perform image processing. */
                        getMinMax(imgBuf.Array, grabResult.SizeX, grabResult.SizeY, out min, out max);
                        //Console.WriteLine("Grabbed frame {0}. Min. gray value = {1}, Max. gray value = {2}", i + 1, min, max);
                        Console.WriteLine("Frame grabbed success");

                        /* Display image */
                        //Pylon.ImagePersistenceSave<Byte>(EPylonImageFileFormat.ImageFileFormat_Png, "C:\\Users\\v.yakubov\\grabber\\test.png", imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        if (arg_imageFormat.Equals("PNG"))
                        {
                            Pylon.ImagePersistenceSave <Byte>(EPylonImageFileFormat.ImageFileFormat_Png, arg_pathToFile, imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        }
                        else if (arg_imageFormat.Equals("JPG"))
                        {
                            Pylon.ImagePersistenceSave <Byte>(EPylonImageFileFormat.ImageFileFormat_Jpeg, arg_pathToFile, imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        }
                        else if (arg_imageFormat.Equals("RAW"))
                        {
                            Pylon.ImagePersistenceSave <Byte>(EPylonImageFileFormat.ImageFileFormat_Raw, arg_pathToFile, imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        }
                        else if (arg_imageFormat.Equals("TIFF"))
                        {
                            Pylon.ImagePersistenceSave <Byte>(EPylonImageFileFormat.ImageFileFormat_Tiff, arg_pathToFile, imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        }
                        else if (arg_imageFormat.Equals("BMP"))
                        {
                            Pylon.ImagePersistenceSave <Byte>(EPylonImageFileFormat.ImageFileFormat_Bmp, arg_pathToFile, imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        }
                        else
                        {
                            Pylon.ImagePersistenceSave <Byte>(EPylonImageFileFormat.ImageFileFormat_Bmp, arg_pathToFile, imgBuf, grabResult.PixelType, (uint)grabResult.SizeX, (uint)grabResult.SizeY, 0, EPylonImageOrientation.ImageOrientation_TopDown);
                        }

                        break;
                    }
                    else if (grabResult.Status == EPylonGrabStatus.Failed)
                    {
                        //Console.Error.WriteLine("Frame {0} wasn't grabbed successfully.  Error code = {1}", i + 1, grabResult.ErrorCode);
                        Console.WriteLine("Error: failed");
                    }
                }

                imgBuf.Dispose();
                Pylon.DeviceClose(hDev);
                Pylon.DestroyDevice(hDev);
                imgBuf = null;
                Pylon.Terminate();
            }
            catch (Exception e)
            {
                try
                {
                    if (hDev.IsValid)
                    {
                        if (Pylon.DeviceIsOpen(hDev))
                        {
                            Pylon.DeviceClose(hDev);
                        }
                        Pylon.DestroyDevice(hDev);
                    }
                }
                catch (Exception) {}
                Pylon.Terminate();  /* Releases all pylon resources. */
                Environment.Exit(1);
            }
        }
Beispiel #8
0
    public void cameraInit(string cameraType)
    {
        //Initiates camera to run in 12 bit mode with continuous acquisition.
        int  i           = 0;
        uint NUM_BUFFERS = 10;

        if (cameraType == "basler")
        {
            Pylon.Initialize();
            numDevices = Pylon.EnumerateDevices();
            if (ConfigurationManager.AppSettings.Get("ipAddress").Length > 0)
            {
                while (ip != ConfigurationManager.AppSettings.Get("ipAddress"))
                {
                    hDev = Pylon.CreateDeviceByIndex(j);
                    prop = Pylon.DeviceGetDeviceInfoHandle(hDev);
                    ip   = Pylon.DeviceInfoGetPropertyValueByIndex(prop, 8);
                    j++;
                    if (j > numDevices)
                    {
                        break;
                    }
                }
            }
            else
            {
                numDevices = Pylon.EnumerateDevices();
                hDev       = Pylon.CreateDeviceByIndex(0);
            }
            try
            {
                Pylon.DeviceOpen(hDev, Pylon.cPylonAccessModeControl | Pylon.cPylonAccessModeStream);
            }
            catch (System.Threading.ThreadAbortException) { }
            catch (Exception ex)
            {
                EmailError.emailAlert(ex);
                throw (ex);
            }

            isAvail = Pylon.DeviceFeatureIsAvailable(hDev, "EnumEntry_PixelFormat_Mono12");
            Pylon.DeviceFeatureFromString(hDev, "PixelFormat", "Mono12");
            Pylon.DeviceFeatureFromString(hDev, "AcquisitionMode", "Continuous");
            Pylon.DeviceSetIntegerFeature(hDev, "Height", 1);
            Pylon.DeviceSetFloatFeature(hDev, "ExposureTimeAbs", exp); //Exposure time is in microseconds and rounded to the closest 100 ns.
            isAvail = Pylon.DeviceFeatureIsWritable(hDev, "GevSCPSPacketSize");
            if (isAvail)
            {
                Pylon.DeviceSetIntegerFeature(hDev, "GevSCPSPacketSize", 1500);
            }
            payloadSize = checked ((uint)Pylon.DeviceGetIntegerFeature(hDev, "PayloadSize"));
            nStreams    = Pylon.DeviceGetNumStreamGrabberChannels(hDev);
            hGrabber    = Pylon.DeviceGetStreamGrabber(hDev, 0);
            Pylon.StreamGrabberOpen(hGrabber);
            hWait = Pylon.StreamGrabberGetWaitObject(hGrabber);
            Pylon.StreamGrabberSetMaxNumBuffer(hGrabber, NUM_BUFFERS);
            Pylon.StreamGrabberSetMaxBufferSize(hGrabber, payloadSize);
            Pylon.StreamGrabberPrepareGrab(hGrabber);
            buffers = new Dictionary <PYLON_STREAMBUFFER_HANDLE, PylonBuffer <Byte> >();
            for (i = 0; i < NUM_BUFFERS; ++i)
            {
                PylonBuffer <Byte>        buffer = new PylonBuffer <byte>(payloadSize, true);
                PYLON_STREAMBUFFER_HANDLE handle = Pylon.StreamGrabberRegisterBuffer(hGrabber, ref buffer);
                buffers.Add(handle, buffer);
            }
            i = 0;
            foreach (KeyValuePair <PYLON_STREAMBUFFER_HANDLE, PylonBuffer <Byte> > pair in buffers)
            {
                Pylon.StreamGrabberQueueBuffer(hGrabber, pair.Key, i++);
            }
            Pylon.DeviceExecuteCommandFeature(hDev, "AcquisitionStart");
        }
    }
        /* Open using device.*/
        protected void Open(PYLON_DEVICE_HANDLE device)
        {
            try
            {
                /* Use provided device. */
                m_hDevice = device;

                /* Before using the device, it must be opened. Open it for configuring
                 * parameters and for grabbing images. */
                Pylon.DeviceOpen(m_hDevice, Pylon.cPylonAccessModeControl | Pylon.cPylonAccessModeStream);

                /* Register the callback function. */
                m_hRemovalCallback = Pylon.DeviceRegisterRemovalCallback(m_hDevice, m_callbackHandler);

                /* For GigE cameras, we recommend increasing the packet size for better
                 * performance. When the network adapter supports jumbo frames, set the packet
                 * size to a value > 1500, e.g., to 8192. In this sample, we only set the packet size
                 * to 1500. */
                /* ... Check first to see if the GigE camera packet size parameter is supported and if it is writable. */
                if (Pylon.DeviceFeatureIsWritable(m_hDevice, "GevSCPSPacketSize"))
                {
                    /* ... The device supports the packet size feature. Set a value. */
                    Pylon.DeviceSetIntegerFeature(m_hDevice, "GevSCPSPacketSize", 6500);
                }

                /* The sample does not work in chunk mode. It must be disabled. */
                if (Pylon.DeviceFeatureIsWritable(m_hDevice, "ChunkModeActive"))
                {
                    /* Disable the chunk mode. */
                    Pylon.DeviceSetBooleanFeature(m_hDevice, "ChunkModeActive", false);
                }

                /* Disable acquisition start trigger if available. */
                if (Pylon.DeviceFeatureIsAvailable(m_hDevice, "EnumEntry_TriggerSelector_AcquisitionStart"))
                {
                    Pylon.DeviceFeatureFromString(m_hDevice, "TriggerSelector", "AcquisitionStart");
                    Pylon.DeviceFeatureFromString(m_hDevice, "TriggerMode", "Off");
                }

                /* Disable frame start trigger if available. */
                if (Pylon.DeviceFeatureIsAvailable(m_hDevice, "EnumEntry_TriggerSelector_FrameStart"))
                {
                    Pylon.DeviceFeatureFromString(m_hDevice, "TriggerSelector", "FrameStart");
                    Pylon.DeviceFeatureFromString(m_hDevice, "TriggerMode", "Off");
                }
                if (Pylon.DeviceFeatureIsAvailable(m_hDevice, "LineSelector"))
                {
                    Pylon.DeviceFeatureFromString(m_hDevice, "LineSelector", "Line1");
                    Pylon.DeviceSetFloatFeature(m_hDevice, "LineDebouncerTimeAbs", 20);
                }
                if (Pylon.DeviceFeatureIsAvailable(m_hDevice, "TriggerActivation"))
                {
                    Pylon.DeviceFeatureFromString(m_hDevice, "TriggerActivation", "RisingEdge");
                }

                /* Image grabbing is done using a stream grabber.
                 * A device may be able to provide different streams. A separate stream grabber must
                 * be used for each stream. In this sample, we create a stream grabber for the default
                 * stream, i.e., the first stream ( index == 0 ).
                 */

                /* Get the number of streams supported by the device and the transport layer. */
                if (Pylon.DeviceGetNumStreamGrabberChannels(m_hDevice) < 1)
                {
                    throw new Exception("The transport layer doesn't support image streams.");
                }

                /* Create and open a stream grabber for the first channel. */
                m_hGrabber = Pylon.DeviceGetStreamGrabber(m_hDevice, 0);
                Pylon.StreamGrabberOpen(m_hGrabber);

                /* Get a handle for the stream grabber's wait object. The wait object
                 * allows waiting for m_buffers to be filled with grabbed data. */
                m_hWait = Pylon.StreamGrabberGetWaitObject(m_hGrabber);
            }
            catch
            {
                /* Get the last error message here, because it could be overwritten by cleaning up. */
                UpdateLastError();

                try
                {
                    Close(); /* Try to close any open handles. */
                }
                catch
                {
                    /* Another exception cannot be handled. */
                }
                throw;
            }

            /* Notify that the ImageProvider is open and ready for grabbing and configuration. */
            OnDeviceOpenedEvent();
        }