public tErr InitCamera() { tErr err = 0; if (Inited) { return(0); } // Initialize the API. if ((err = Pv.Initialize()) == 0) { lLinkCB = new tLinkCallback(LinkCB); // Register callbacks. Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero); Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero); Inited = true; } else { Console.Write("无法加载相机API,错误代码: "); Console.WriteLine(err); err_string = "无法加载相机API,错误代码: " + err.ToString(); } return(err); }
static void Main(string[] args) { tErr err = 0; // Initialize the API. if ((err = Pv.Initialize()) == 0) { tLinkCallback lLinkCB = new tLinkCallback(LinkCB); // Register callbacks. Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero); Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero); // Wait for the user to terminate or to unplug the camera. WaitForEver(); // Unregister the callbacks. Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd); Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove); // Uninitialize the API. Pv.UnInitialize(); } else { Console.Write("Failed to initialize the API : "); Console.WriteLine(err); } }
static void Main(string[] args) { tErr err = 0; // Initialize the API. if ((err = Pv.Initialize()) == 0) { tLinkCallback lLinkCB = new tLinkCallback(LinkCB); // Register callbacks. Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero); Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero); WaitForCamera(); if (CameraGrab()) { if (CameraSetup()) { if (CameraStart()) { Console.WriteLine("The camera will be streaming for the next 10 seconds."); Thread.Sleep(10000); CameraStop(); } else { Console.WriteLine("The camera failed to start streaming."); } CameraClose(); } else { Console.WriteLine("The camera could not be setup."); } } else { Console.WriteLine("The was no camera grabbed."); } // Unregister the callbacks. Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd); Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove); // Uninitialize the API. Pv.UnInitialize(); } else { Console.Write("Failed to initialize the API : "); Console.WriteLine(err); } }
public GigEVision() { tErr error = Pv.Initialize(); this.connectionChangedCallback = OnCameraConnectionChanged; if (error == tErr.eErrSuccess) { error = Pv.LinkCallbackRegister(this.connectionChangedCallback, tLinkEvent.eLinkAdd, IntPtr.Zero); if (error == tErr.eErrSuccess) { error = Pv.LinkCallbackRegister(this.connectionChangedCallback, tLinkEvent.eLinkRemove, IntPtr.Zero); } } if (error != tErr.eErrSuccess) { throw new PvException(error); } }
static void Main(string[] args) { tErr err = 0; // Initialize the API. if ((err = Pv.Initialize()) == 0) { tCamera Camera = new tCamera(); tLinkCallback lLinkCB = new tLinkCallback(LinkCB); // Add callbacks for camera events. if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero) != 0) { Console.WriteLine("Failed to register the callback."); } if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero) != 0) { Console.WriteLine("Failed to register the callback."); } // Wait for a camera to be plugged in. WaitForCamera(); // Grab a camera from the list. if (CameraGrab(ref Camera)) { // Setup the camera. if (CameraSetup(ref Camera)) { DoSnap(ref Camera); DoSnap(ref Camera); DoStream(ref Camera); DoStream(ref Camera); DoSnap(ref Camera); DoStream(ref Camera); DoStream(ref Camera); // Unsetup the camera. CameraUnsetup(ref Camera); } else { Console.WriteLine("Camera {0} failed to be setup.", Camera.UID); } } else { Console.WriteLine("Failed to find a camera."); } // Remove callbacks. if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd) != 0) { Console.WriteLine("Failed to unregister the callback."); } if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove) != 0) { Console.WriteLine("Failed to unregister the callback."); } // Uninitialize the API. Pv.UnInitialize(); } else { Console.Write("Failed to initialize the API."); Console.WriteLine(err); } }
static void Main(string[] args) { tErr err = 0; // Initialize the API. if ((err = Pv.Initialize()) == 0) { tCamera Camera = new tCamera(); tLinkCallback lLinkCB = new tLinkCallback(LinkCB); // Add callbacks for camera events. if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero) != 0) { Console.WriteLine("Failed to register callback."); } if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero) != 0) { Console.WriteLine("Failed to register callback."); } WaitForCamera(); if (CameraGrab(ref Camera)) { if (CameraSetup(ref Camera)) { // Stream as long as CTRL C isn't pressed. while (close == false) { if (CameraStart(ref Camera)) { Console.WriteLine("Camera is now streaming."); // Stream the Camera until the use stops it. Abort(); CameraStop(ref Camera); } else { Console.WriteLine("Failed to start the streaming process."); } CameraClose(ref Camera); } } else { Console.WriteLine("Camera {0} failed to be setup.", Camera.UID); } } else { Console.WriteLine("Failed to find a camera."); } //remove callbacks if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd) != 0) { Console.WriteLine("Failed to unregister the callback."); } if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove) != 0) { Console.WriteLine("Failed to unregister the callback."); } Pv.UnInitialize(); } else { Console.Write("Failed to initialize the API : "); Console.WriteLine(err); } Thread.Sleep(800); }