Esempio n. 1
0
        // Start streaming frames.
        static bool DoStream(ref tCamera Camera)
        {
            tErr           Err;
            UInt32         FrameCount = 0;
            GCHandle       pFrame     = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB    = new tFrameCallback(FrameDummyCBStream);
            uint           timeout    = 1000;

            // Adjust packet for optimal preformance.
            Pv.CaptureAdjustPacketSize(Camera.Handle, 8228);

            Console.WriteLine("Streaming has started...");

            // Set the camera in acquisition mode.
            if (((Err = Pv.CaptureStart(Camera.Handle)) == 0))
            {
                if ((Pv.CommandRun(Camera.Handle, "AcquisitionStart")) != 0)
                {
                    // If that fails, reset the camera to non capture mode.
                    Pv.CaptureEnd(Camera.Handle);
                    Console.WriteLine("PvCommandRun() failed!");
                    return(false);
                }
                else
                {
                    // Stream for a total of 30 frames.
                    while (FrameCount < 100)
                    {
                        if (Pv.CaptureQueueFrame(Camera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
                        {
                            Pv.CaptureWaitForFrameDone(Camera.Handle, pFrame.AddrOfPinnedObject(), timeout);
                            FrameCount++;
                        }
                    }
                    // After the 30 frames, stop streaming.
                    CameraStop(ref Camera);
                    Console.WriteLine("Streaming stopped.");
                    return(true);
                }
            }
            else
            {
                Console.WriteLine("PvCaptureStart() failed with error code {0}.", Err);
                return(false);
            }
        }
Esempio n. 2
0
        // Snap a frame from the camera.
        static bool CameraSnap(ref tCamera Camera)
        {
            bool           result;
            GCHandle       pFrame  = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB = new tFrameCallback(FrameDummyCB);

            // Queue the frame.
            if (Pv.CaptureQueueFrame(Camera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
            {
                Console.WriteLine("Triggering the camera ...");

                // Trigger the capture.
                if (Pv.CommandRun(Camera.Handle, "FrameStartTriggerSoftware") == 0)
                {
                    Console.WriteLine("Waiting for the frame to be done ...");

                    // Wait for the frame to be returned.
                    while (Pv.CaptureWaitForFrameDone(Camera.Handle, pFrame.AddrOfPinnedObject(), 10) == tErr.eErrTimeout)
                    {
                        Console.WriteLine("Still waiting ...");
                    }

                    // Copy the frame structure back in the frame we have.
                    Camera.Frame = (tFrame)Marshal.PtrToStructure(pFrame.AddrOfPinnedObject(), typeof(tFrame));

                    // Check the status flag.
                    if (!(result = (Camera.Frame.Status == tErr.eErrSuccess)))
                    {
                        Console.WriteLine("Frame captured un-succesfully {0}", Camera.Frame.Status);
                    }
                }
                else
                {
                    Pv.CaptureQueueClear(Camera.Handle);
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            pFrame.Free();

            return(result);
        }
Esempio n. 3
0
        // Snap a frame from the camera.
        static bool CameraSnap(ref tCamera Camera)
        {
            bool           result;
            GCHandle       pFrame  = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB = new tFrameCallback(FrameDummyCB);

            // Adjust packet for optimal preformance.
            Pv.CaptureAdjustPacketSize(Camera.Handle, 8228);

            // Queue the frame.
            if (Pv.CaptureQueueFrame(Camera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
            {
                // Trigger the capture.
                if (Pv.CommandRun(Camera.Handle, "FrameStartTriggerSoftware") == 0)
                {
                    // Then wait for the frame to be returned.
                    if (Pv.CaptureWaitForFrameDone(Camera.Handle, pFrame.AddrOfPinnedObject(), 0) == 0)
                    {
                        // Check the status flag.
                        if (!(result = (Camera.Frame.Status == tErr.eErrSuccess)))
                        {
                            Console.WriteLine("Frame captured un-succesfully {0}.", Camera.Frame.Status);
                        }
                    }
                    else
                    {
                        Pv.CaptureQueueClear(Camera.Handle);
                        result = false;
                    }
                }
                else
                {
                    Pv.CaptureQueueClear(Camera.Handle);
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            pFrame.Free();

            return(result);
        }
Esempio n. 4
0
        // Snap a frame.
        static bool DoSnap(ref tCamera Camera)
        {
            GCHandle       pFrame  = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB = new tFrameCallback(FrameDummyCBSnap);
            uint           timeout = 1000;

            // Set the camera is acquisition mode.
            if ((Pv.CaptureStart(Camera.Handle)) == 0)
            {
                // Set the acquisition mode to continuous.
                if ((Pv.CommandRun(Camera.Handle, "AcquisitionStart")) != 0)
                {
                    // If that fails,reset the camera to non capture mode.
                    Pv.CaptureEnd(Camera.Handle);
                    return(false);
                }
                else
                {
                    bool failed = false;

                    // Enqueue the single frame.
                    if (Pv.CaptureQueueFrame(Camera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
                    {
                        Console.WriteLine("Waiting for the frame...");
                        failed = Pv.CaptureWaitForFrameDone(Camera.Handle, pFrame.AddrOfPinnedObject(), timeout) != 0;
                        Console.WriteLine("Frame is done...");
                        Console.WriteLine("Snapping done.");
                    }
                    else
                    {
                        failed = true;
                    }

                    Pv.CommandRun(Camera.Handle, "AcquisitionStop");
                    Pv.CaptureEnd(Camera.Handle);
                    return(!failed);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        // Snap a frame from the camera.
        static bool CameraSnap()
        {
            bool           result;
            GCHandle       pFrame  = GCHandle.Alloc(GCamera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB = new tFrameCallback(FrameDummyCB);

            // Queue the frame.
            if (Pv.CaptureQueueFrame(GCamera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
            {
                // Trigger the capture.

                Console.WriteLine("Waiting for a frame ...");

                // Wait for the frame to be returned.
                while (Pv.CaptureWaitForFrameDone(GCamera.Handle, pFrame.AddrOfPinnedObject(), 1500) == tErr.eErrTimeout)
                {
                    if (close == false)
                    {
                        Console.WriteLine("Still waiting ...");
                    }
                    else
                    {
                        break;
                    }
                }
                // Copy the frame structure back in the frame we have.
                GCamera.Frame = (tFrame)Marshal.PtrToStructure(pFrame.AddrOfPinnedObject(), typeof(tFrame));

                // Check the status flag.
                if (!(result = (GCamera.Frame.Status == tErr.eErrSuccess)))
                {
                    Console.WriteLine("Frame captured un-succesfully {0}", GCamera.Frame.Status);
                }
            }
            else
            {
                result = false;
            }

            pFrame.Free();

            return(result);
        }