Beispiel #1
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int NumImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            //
            // Register for End of Exposure (EoE) event. We simply create an instance of
            // the ManagedEventOptions, populate it, and register it with the camera.
            //
            ManagedEventOptions option = new ManagedEventOptions();

            option.EventCallbackFcn = OnEventReceived;
            option.EventName        = "EventExposureEnd";

            try
            {
                cam.RegisterEvent(option);

                Console.WriteLine("Successfully registered event: {0}", option.EventName);
            }
            catch (FC2Exception ex)
            {
                Console.WriteLine("Error registering EventExposureEnd : {0}", ex.Message);
                return;
            }

            //
            // Attempt to register all events. This will fail, since we only expect this
            // to be called if no events have yet been registered, but a fatal error
            // will not be generated. If the user wants to use this call, the user can
            // DeregisterAllEvents(), and then run RegisterAllEvents().
            //
            // If there are numerious different event types, and the user would like to
            // create a "default" callback and/or UserData struct, the user can run
            // RegisterAllEvents() with the default callback function, issue
            // DeregisterEvent() for the specific event that uses a custom callback, and
            // then issue RegisterEvent() with the specific callback function. This is
            // to ensure the user doesn't accidentally corrupt the callback function
            // list.
            //
            try
            {
                cam.RegisterAllEvents(option);
            }
            catch (FC2Exception ex)
            {
                // Expected error
                Console.WriteLine("Error registering EventExposureEnd : {0}", ex.Message);
            }

            // Start capturing images
            cam.StartCapture();

            // Retrieve images from buffer
            ManagedImage rawImage = new ManagedImage();

            for (ImageCount = 0; ImageCount < NumImages; ImageCount++)
            {
                try
                {
                    // Retrieve an image
                    cam.RetrieveBuffer(rawImage);
                }
                catch (FC2Exception ex)
                {
                    Console.WriteLine("Error retrieving buffer : {0}", ex.Message);
                    continue;
                }
            }

            // Stop capturing images
            cam.StopCapture();

            // Uncomment the following to deregister event handler for specific device event
            //cam.DeregisterEvent(option);

            // Deregister event handler for all events
            cam.DeregisterAllEvents();

            // Disconnect the camera
            cam.Disconnect();

            // Reset counter for next iteration
            ImageCount = 0;
        }