// Callback called when a frame is done. static void FrameDoneCB(ref tFrame pFrame, ref tCamera Camera) { GCHandle pFrame1 = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned); tFrameCallback FrameCB = new tFrameCallback(FrameDummyCB); // If the frame was completed, re-enqueue it. if (pFrame.Status != tErr.eErrUnplugged && pFrame.Status != tErr.eErrCancelled) { Pv.CaptureQueueFrame(Camera.Handle, pFrame1.AddrOfPinnedObject(), FrameCB); } }
// Callback for when the frame is completed. static void FrameDoneCB(IntPtr pFrame) { // Marshal the pointer into a frame structure. tFrame Frame = (tFrame)Marshal.PtrToStructure(pFrame, typeof(tFrame)); // If the frame was completed (or if data were missing/lost), re-enqueue it. if (Frame.Status == tErr.eErrSuccess || Frame.Status == tErr.eErrDataLost || Frame.Status == tErr.eErrDataMissing) { Pv.CaptureQueueFrame(GCamera.Handle, pFrame, FrameCB); } }
// Callback for when the frame is completed. static void FrameDoneCB(IntPtr pFrame) { // Marshal the pointer into a frame structure. tFrame Frame = (tFrame)Marshal.PtrToStructure(pFrame, typeof(tFrame)); Console.WriteLine("Frame recieved {0}.", (uint)Frame.Status); // If the frame was completed (or if data were missing/lost), re-enqueue it. if (Frame.Status != tErr.eErrUnplugged && Frame.Status != tErr.eErrCancelled) { Pv.CaptureQueueFrame(GCamera.Handle, pFrame, FrameDoneCB); } }
// 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); } }
// 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); }
internal bool QueueFrame(IntPtr framePointer, tFrameCallback callback) { if (!camera.HasValue) { throw new PvException(tErr.eErrUnavailable); } tErr error; lock (serial) { error = Pv.CaptureQueueFrame(camera.Value, framePointer, callback); } if (error != tErr.eErrSuccess) { return(false); } return(true); }
// 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); }
// 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); } }
// 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); }
// Setup the camera up for streaming. static bool CameraStart() { UInt32 FrameSize = 0; // Adjust packet size for optimal performance. Pv.CaptureAdjustPacketSize(GCamera.Handle, 8228); // Determines how big the frame buffers should be. if (Pv.AttrUint32Get(GCamera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0) { tFrame Frame = new tFrame(); byte[] Buffer = new byte[FrameSize]; GCHandle pBuffer = GCHandle.Alloc(Buffer, GCHandleType.Pinned); // Set the frame's fields. // Handle to the Camera. Frame.Context.Field0 = new IntPtr(GCamera.Handle); // Address of the pinned object. Frame.ImageBuffer = pBuffer.AddrOfPinnedObject(); // Buffer size. Frame.ImageBufferSize = FrameSize; // Start the capture mode. if (Pv.CaptureStart(GCamera.Handle) == 0) { // Set the camera in continuous acquisition mode,and in "Freerun". if (Pv.AttrEnumSet(GCamera.Handle, "FrameStartTriggerMode", "Freerun") == 0) { // Set the acquisition mode into continuous. if (Pv.CommandRun(GCamera.Handle, "AcquisitionStart") != 0) { // If that fails, reset the camera to non-capture mode. Pv.CaptureEnd(GCamera.Handle); Console.WriteLine("Failed to start."); return(false); } else { // Pin down a copy of the frame structure. GCHandle pFrame = GCHandle.Alloc(Frame, GCHandleType.Pinned); // Enqueue the frame. Pv.CaptureQueueFrame(GCamera.Handle, pFrame.AddrOfPinnedObject(), FrameCB); return(true); } } else { return(false); } } else { return(false); } } else { return(false); } }
// Setup the camera up for streaming. static bool CameraStart() { tFrameCallback lFrameCB = new tFrameCallback(FrameDoneCB); tCameraEventCallback lEventCB = new tCameraEventCallback(EventDone); UInt32 FrameSize = 0; IntPtr Context = IntPtr.Zero; if (Pv.AttrExists(GCamera.Handle, "EventsEnable1") == tErr.eErrNotFound) { Console.WriteLine("This camera does not support event notifications."); return(false); } // Adjust packet size for optimal performance. Pv.CaptureAdjustPacketSize(GCamera.Handle, 8228); // Determines how big the frame buffers should be. if (Pv.AttrUint32Get(GCamera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0) { tFrame Frame = new tFrame(); byte[] Buffer = new byte[FrameSize]; GCHandle pBuffer = GCHandle.Alloc(Buffer, GCHandleType.Pinned); // Set the frame's fields. // Handle to the Camera. Frame.Context.Field0 = new IntPtr(GCamera.Handle); // Address of the pinned object. Frame.ImageBuffer = pBuffer.AddrOfPinnedObject(); // Buffer size. Frame.ImageBufferSize = FrameSize; // Setup the event channel. Pv.AttrUint32Set(GCamera.Handle, "EventsEnable1", 0); Pv.AttrEnumSet(GCamera.Handle, "EventSelector", "AcquisitionStart"); Pv.AttrEnumSet(GCamera.Handle, "EventNotification", "On"); Pv.AttrEnumSet(GCamera.Handle, "EventSelector", "AcquisitionEnd"); Pv.AttrEnumSet(GCamera.Handle, "EventNotification", "On"); Pv.AttrEnumSet(GCamera.Handle, "EventSelector", "FrameTrigger"); Pv.AttrEnumSet(GCamera.Handle, "EventNotification", "On"); if (Pv.CameraEventCallbackRegister(GCamera.Handle, lEventCB, Context) != tErr.eErrSuccess) { Console.WriteLine("There was an error accessing the driver."); return(false); } // Start the capture mode. if (Pv.CaptureStart(GCamera.Handle) == 0) { if (Pv.AttrFloat32Set(GCamera.Handle, "FrameRate", 5) == 0) { // Set the camera in continuous acquisition mode,and in "Freerun". if (Pv.AttrEnumSet(GCamera.Handle, "FrameStartTriggerMode", "FixedRate") == 0) { // Set the acquisition mode into continuous. if (Pv.CommandRun(GCamera.Handle, "AcquisitionStart") != 0) { // If that fails, reset the camera to non-capture mode. Pv.CaptureEnd(GCamera.Handle); Console.WriteLine("Failed to start."); return(false); } else { // Pin down a copy of the frame structure. GCHandle pFrame = GCHandle.Alloc(Frame, GCHandleType.Pinned); // Enqueue the frame. Pv.CaptureQueueFrame(GCamera.Handle, pFrame.AddrOfPinnedObject(), lFrameCB); return(true); } } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } }