/// <summary> /// 注册回调 /// </summary> /// <returns></returns> private bool CreateObjects() { // Create acquisition object if (m_AcqDevice != null && !m_AcqDevice.Initialized) { if (m_AcqDevice.Create() == false) { DestroyObjects(); return(false); } } // Create buffer object if (m_Buffers != null && !m_Buffers.Initialized) { if (m_Buffers.Create() == false) { DestroyObjects(); return(false); } m_Buffers.Clear(); } // Create view object if (m_View != null && !m_View.Initialized) { if (m_View.Create() == false) { DestroyObjects(); return(false); } } if (m_Xfer != null && m_Xfer.Pairs[0] != null) { m_Xfer.Pairs[0].Cycle = SapXferPair.CycleMode.NextWithTrash; if (m_Xfer.Pairs[0].Cycle != SapXferPair.CycleMode.NextWithTrash) { DestroyObjects(); return(false); } } // Create Xfer object if (m_Xfer != null && !m_Xfer.Initialized) { if (m_Xfer.Create() == false) { DestroyObjects(); return(false); } } return(true); }
private bool CreateObjects() { // Create acquisition object if (m_Acquisition != null && !m_Acquisition.Initialized) { if (m_Acquisition.Create() == false) { DestroyObjects(); return(false); } } // Create buffer object if (m_Buffers != null && !m_Buffers.Initialized) { if (m_Buffers.Create() == false) { DestroyObjects(); return(false); } m_Buffers.Clear(); } // Create view object if (m_View != null && !m_View.Initialized) { if (m_View.Create() == false) { DestroyObjects(); return(false); } } // Create Xfer object if (m_Xfer != null && !m_Xfer.Initialized) { if (m_Xfer.Create() == false) { DestroyObjects(); return(false); } } return(true); }
static void Main(string[] args) { SapAcquisition Acq = null; SapAcqDevice AcqDevice = null; SapBuffer Buffers = null; SapTransfer Xfer = null; SapView View = null; //Console.WriteLine("Sapera Console Grab Example (C# version)\n"); MyAcquisitionParams acqParams = new MyAcquisitionParams(); // Call GetOptions to determine which acquisition device to use and which config // file (CCF) should be loaded to configure it. if (!GetOptions(args, acqParams)) { Console.WriteLine("\nPress any key to terminate\n"); Console.ReadKey(true); return; } SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex); if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0) { Acq = new SapAcquisition(loc, acqParams.ConfigFileName); Buffers = new SapBuffer(1, Acq, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqToBuf(Acq, Buffers); // Create acquisition object if (!Acq.Create()) { Console.WriteLine("Error during SapAcquisition creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } } if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0) { AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName); Buffers = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqDeviceToBuf(AcqDevice, Buffers); // Create acquisition object if (!AcqDevice.Create()) { Console.WriteLine("Error during SapAcqDevice creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } } View = new SapView(Buffers); // End of frame event Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; Xfer.XferNotify += new SapXferNotifyHandler(xfer_XferNotify); Xfer.XferNotifyContext = View; //Console.WriteLine("gggggwhat is new line"); // Create buffer object if (!Buffers.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Create buffer object if (!Xfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Create buffer object if (!View.Create()) { Console.WriteLine("Error during SapView creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Grab as fast as possible, wait for a key to be pressed, if it's p, // write the file, otherwise if it's q exit the program. Designed to be run by and monitored // through a pipe Boolean stop_snap = false; int curr_code = 0; string new_cmd = ""; while (stop_snap == false) { Console.WriteLine("Press a key to trigger snap"); new_cmd = Console.ReadLine(); Xfer.Snap(); Console.WriteLine("Press a key to trigger save"); new_cmd = Console.ReadLine(); View.Buffer.Save("test.raw", "-format raw"); var dsb = new StringBuilder("frame: " + frame_count); Console.WriteLine(dsb); frame_count = frame_count + 1; Console.WriteLine("File saved, Press a key to repeat, q to quit:"); new_cmd = Console.ReadLine(); if (new_cmd == "q") { stop_snap = true; } //if (curr_code == 113) { stop_snap = true; } } DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); loc.Dispose(); }
//static void Main(string[] args) public static void Done() { SapAcqDevice camera = null; SapView view = null; SapTransfer transfer = null; SapBuffer buffer = null; Console.WriteLine("Sapera Console GigE Cameras AutoWhiteBalance Example (C# version)\n"); MyAcquisitionParams acqParams = new MyAcquisitionParams(); /*if (!GetOptions(args, acqParams)) * { * Console.WriteLine("\nPress any key to terminate\n"); * Console.ReadKey(); * return; * }*/ SapLocation location = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex); camera = new SapAcqDevice(location, acqParams.ConfigFileName); buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather); transfer = new SapAcqDeviceToBuf(camera, buffer); view = new SapView(buffer); // End of frame event transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; transfer.XferNotify += new SapXferNotifyHandler(Xfer_XferNotify); transfer.XferNotifyContext = view; if (!camera.Create()) { Console.WriteLine("Error during SapAcquisition creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Monochrome models are not supported for White Balance Calibration. int colorType = 0; bool isAvailable = false; if (isAvailable = camera.IsFeatureAvailable("ColorType")) { if (camera.GetFeatureValue("ColorType", out colorType)) { if (colorType == 0) { Console.WriteLine("This camera model does not support Auto White Balance calibration.\n"); DestroysObjects(camera, buffer, transfer, view); return; } } } //activate feature only if camera has 3 separate gains Boolean bRedGain = false; Boolean bGreenGain = false; Boolean bBlueGain = false; bRedGain = camera.IsFeatureAvailable("GainRed"); bGreenGain = camera.IsFeatureAvailable("GainGreen"); bBlueGain = camera.IsFeatureAvailable("GainBlue"); if (!bRedGain && !bGreenGain && !bBlueGain) { Console.WriteLine("This camera model does not support Auto White Balance calibration.\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create buffer object if (!buffer.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create transfer object if (!transfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create view object if (!view.Create()) { Console.WriteLine("Error during SapView creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } Console.WriteLine("Press any key to start Grab. Press 'q' to quit."); ConsoleKeyInfo info = Console.ReadKey(true); char key = info.KeyChar; if (key != 0) { if (key == 'q') { DestroysObjects(camera, buffer, transfer, view); return; } } // Start continous grab transfer.Grab(); Console.WriteLine("Press any key to stop grab\n"); Console.ReadKey(); // Stop grab transfer.Freeze(); transfer.Wait(5000); Console.WriteLine("Press any key to start Auto White Balance calibration. Press 'q' to quit.\n"); info = Console.ReadKey(true); key = info.KeyChar; if (key != 0) { if (key == 'q') { DestroysObjects(camera, buffer, transfer, view); return; } } int oldPixelFormat = 0; isAvailable = false; if (isAvailable = camera.IsFeatureAvailable("PixelFormat")) { camera.GetFeatureValue("PixelFormat", out oldPixelFormat); } else { Console.WriteLine("This camera model does not support Auto White Balance calibration.\n"); DestroysObjects(camera, buffer, transfer, view); return; } if (oldPixelFormat != GVSP_PIX_BAYRG8) { // Camera Pixel Format defined is not Raw Bayer. // We change the value DestroysObjects(null, buffer, transfer, view); camera.SetFeatureValue("PixelFormat", GVSP_PIX_BAYRG8); // Instantiation of new buffer object buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather); // Instantiation of new view object view = new SapView(buffer); // Instantiation of new transfer object transfer = new SapAcqDeviceToBuf(camera, buffer); // End of frame event transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; transfer.XferNotify += new SapXferNotifyHandler(Xfer_XferNotify); transfer.XferNotifyContext = view; if (!camera.Create()) { Console.WriteLine("Error during SapAcquisition creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create buffer object if (!buffer.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create transfer object if (!transfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create view object if (!view.Create()) { Console.WriteLine("Error during SapView creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } } if (!AutoWhiteBalanceOperations(camera, buffer, transfer)) { Console.WriteLine("Auto WhiteBalamce has failed"); DestroysObjects(camera, buffer, transfer, view); return; } if (oldPixelFormat != GVSP_PIX_BAYRG8) { // Camera Pixel Format was changed for Raw Bayer. // We set the original value. DestroysObjects(null, buffer, transfer, view); camera.SetFeatureValue("PixelFormat", oldPixelFormat); // Instantiation of new buffer object buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather); // Instantiation of new view object view = new SapView(buffer); // Instantiation of new transfer object transfer = new SapAcqDeviceToBuf(camera, buffer); // End of frame event transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; transfer.XferNotify += new SapXferNotifyHandler(Xfer_XferNotify); transfer.XferNotifyContext = view; // Create buffer object if (!buffer.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create transfer object if (!transfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } // Create view object if (!view.Create()) { Console.WriteLine("Error during SapView creation!\n"); DestroysObjects(camera, buffer, transfer, view); return; } } Console.WriteLine("Press any key to start Grab. Press 'q' to quit.\n"); info = Console.ReadKey(true); key = info.KeyChar; if (key != 0) { if (key == 'q') { DestroysObjects(camera, buffer, transfer, view); return; } } // Start continous grab transfer.Grab(); Console.WriteLine("Press any key to stop grab\n"); Console.ReadKey(); // Stop grab transfer.Freeze(); transfer.Wait(5000); DestroysObjects(camera, buffer, transfer, view); location.Dispose(); }
static void Main(string[] args) { SapAcquisition Acq = null; SapAcqDevice AcqDevice = null; SapBuffer Buffers = null; SapTransfer Xfer = null; SapView View = null; //Console.WriteLine("Sapera Console Grab Example (C# version)\n"); MyAcquisitionParams acqParams = new MyAcquisitionParams(); // Call GetOptions to determine which acquisition device to use and which config // file (CCF) should be loaded to configure it. if (!GetOptions(args, acqParams)) { Console.WriteLine("\nPress any key to terminate\n"); Console.ReadKey(true); return; } SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex); if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0) { Acq = new SapAcquisition(loc, acqParams.ConfigFileName); Buffers = new SapBuffer(1, Acq, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqToBuf(Acq, Buffers); // Create acquisition object if (!Acq.Create()) { Console.WriteLine("Error during SapAcquisition creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } } if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0) { AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName); Buffers = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqDeviceToBuf(AcqDevice, Buffers); // Create acquisition object if (!AcqDevice.Create()) { Console.WriteLine("Error during SapAcqDevice creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } } View = new SapView(Buffers); // End of frame event Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; Xfer.XferNotify += new SapXferNotifyHandler(xfer_XferNotify); Xfer.XferNotifyContext = View; //Console.WriteLine("gggggwhat is new line"); // Create buffer object if (!Buffers.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Create buffer object if (!Xfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Create buffer object if (!View.Create()) { Console.WriteLine("Error during SapView creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Grab as fast as possible, wait for a key to be pressed, if it's p, // write the file, otherwise if it's q exit the program. Designed to be run by and monitored // through a pipe Boolean stop_snap = false; int curr_code = 0; string new_cmd = ""; while (stop_snap == false) { Console.WriteLine("Press a key to trigger snap"); new_cmd = Console.ReadLine(); Xfer.Snap(); Console.WriteLine("Press a key to trigger save"); new_cmd = Console.ReadLine(); View.Buffer.Save("test.raw", "-format raw"); var dsb = new StringBuilder("frame: " + frame_count); Console.WriteLine(dsb); frame_count = frame_count + 1; Console.WriteLine("File saved, Press a key to repeat, q to quit:"); new_cmd = Console.ReadLine(); if (new_cmd == "q") { stop_snap = true; } //if (curr_code == 113) { stop_snap = true; } } DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); loc.Dispose(); }
static void Main(string[] args) { SapAcquisition Acq = null; SapAcqDevice AcqDevice = null; SapBuffer Buffers = null; SapTransfer Xfer = null; SapView View = null; Console.WriteLine("Sapera Console Grab Example (C# version)\n"); MyAcquisitionParams acqParams = new MyAcquisitionParams(); // Call GetOptions to determine which acquisition device to use and which config // file (CCF) should be loaded to configure it. if (!GetOptions(args, acqParams)) { Console.WriteLine("\nPress any key to terminate\n"); Console.ReadKey(true); return; } SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex); if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0) { Acq = new SapAcquisition(loc, acqParams.ConfigFileName); Buffers = new SapBufferWithTrash(2, Acq, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqToBuf(Acq, Buffers); // Create acquisition object if (!Acq.Create()) { Console.WriteLine("Error during SapAcquisition creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } Acq.EnableEvent(SapAcquisition.AcqEventType.StartOfFrame); } else if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0) { AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName); Buffers = new SapBufferWithTrash(2, AcqDevice, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqDeviceToBuf(AcqDevice, Buffers); // Create acquisition object if (!AcqDevice.Create()) { Console.WriteLine("Error during SapAcqDevice creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } } View = new SapView(Buffers); // End of frame event Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; Xfer.XferNotify += new SapXferNotifyHandler(xfer_XferNotify); Xfer.XferNotifyContext = View; // Create buffer object if (!Buffers.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Create buffer object if (!Xfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } // Create buffer object if (!View.Create()) { Console.WriteLine("Error during SapView creation!\n"); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); return; } Xfer.Grab(); Console.WriteLine("\n\nGrab started, press a key to freeze"); Console.ReadKey(true); Xfer.Freeze(); Xfer.Wait(1000); DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View); loc.Dispose(); }