static bool GetOptions(string[] args, MyAcquisitionParams acparams) { // Check if arguments were passed if (args.Length > 1) { return(ExampleUtils.GetAcqDeviceOptionsFromCommandLine(args, acparams)); } else { return(ExampleUtils.GetCorAcqDeviceOptionsFromQuestions(acparams, true)); } }
static public bool GetAcqDeviceOptionsFromCommandLine(string[] args, MyAcquisitionParams acparams) { // Check the command line for user commands if (args[1].Equals("/?") || args[1].Equals("-?")) { // print help Console.WriteLine("Usage:\n"); Console.WriteLine("GigECameraLut [<acquisition server name> <acquisition device index>]\n"); return(false); } // Check if enough arguments were passed if (args.Length < 3) { Console.WriteLine("Invalid command line!\n"); return(false); } // Validate server name if (SapManager.GetServerIndex(args[1]) < 0) { Console.WriteLine("Invalid acquisition server name!\n"); return(false); } // Does the server support acquisition? int deviceCount = SapManager.GetResourceCount(args[1], SapManager.ResourceType.AcqDevice); if (deviceCount == 0) { Console.WriteLine("This server does not support acquisition!\n"); return(false); } // Validate device index if (int.Parse(args[2]) < 0 || int.Parse(args[2]) >= deviceCount) { Console.WriteLine("Invalid acquisition device index!\n"); return(false); } // Fill-in output variables acparams.ServerName = args[1]; acparams.ResourceIndex = int.Parse(args[2]); return(true); }
//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(); }
//////// Ask questions to user to select acquisition board/device and config file //////// static public bool GetOptionsFromQuestions(MyAcquisitionParams acqParams) { // Get total number of boards in the system int serverCount = SapManager.GetServerCount(); if (serverCount == 0) { Console.WriteLine("No device found!\n"); return(false); } Console.WriteLine("\nSelect the acquisition server (or 'q' to quit)"); Console.WriteLine(".............................................."); // Scan the boards to find those that support acquisition int serverIndex; bool serverFound = false; bool cameraFound = false; for (serverIndex = 0; serverIndex < serverCount; serverIndex++) { if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.Acq) != 0) { string serverName = SapManager.GetServerName(serverIndex); Console.WriteLine(serverIndex.ToString() + ": " + serverName); serverFound = true; } else if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0) { string serverName = SapManager.GetServerName(serverIndex); Console.WriteLine(serverIndex.ToString() + ": " + serverName); cameraFound = true; } } // At least one acquisition server must be available if (!serverFound && !cameraFound) { Console.WriteLine("No acquisition server found!\n"); return(false); } ConsoleKeyInfo info = Console.ReadKey(true); char key = info.KeyChar; if (key == 'q') { return(false); } int serverNum = key - '0'; // char-to-int conversion if ((serverNum >= 1) && (serverNum < serverCount)) { acqParams.ServerName = SapManager.GetServerName(serverNum); } else { Console.WriteLine("Invalid selection!\n"); return(false); } // Scan all the acquisition devices on that server and show menu to user int deviceCount = SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq); int cameraCount = (deviceCount == 0) ? SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) : 0; int allDeviceCount = deviceCount + cameraCount; Console.WriteLine("\nSelect the acquisition device (or 'q' to quit)"); Console.WriteLine("..............................................\n"); for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { string deviceName = SapManager.GetResourceName(acqParams.ServerName, SapManager.ResourceType.Acq, deviceIndex); Console.WriteLine(((int)(deviceIndex + 1)).ToString() + ": " + deviceName); } if (deviceCount == 0) { for (int cameraIndex = 0; cameraIndex < cameraCount; cameraIndex++) { string cameraName = SapManager.GetResourceName(acqParams.ServerName, SapManager.ResourceType.AcqDevice, cameraIndex); Console.WriteLine(((int)(cameraIndex + 1)).ToString() + ": " + cameraName); } } info = Console.ReadKey(true); key = info.KeyChar; if (key == 'q') { return(false); } int deviceNum = key - '0'; if ((deviceNum >= 1) && (deviceNum <= allDeviceCount)) { acqParams.ResourceIndex = deviceNum - 1; } else { Console.WriteLine("Invalid selection!\n"); return(false); } //////////////////////////////////////////////////////////// // List all files in the config directory string configPath = Environment.GetEnvironmentVariable("SAPERADIR") + "\\CamFiles\\User\\"; if (!Directory.Exists(configPath)) { Console.WriteLine("Directory : {0} Does not exist", configPath); return(false); } string[] ccffiles = Directory.GetFiles(configPath, "*.ccf"); int configFileCount = ccffiles.Length; string[] configFileNames = new string[configFileCount + 1]; if (configFileCount == 0) { if (cameraCount == 0) { Console.WriteLine("No config file found.\nUse CamExpert to generate a config file before running this example.\n"); return(false); } else { Console.WriteLine("\nSelect the config file (or 'q' to quit.)"); Console.WriteLine("\n........................................\n"); Console.WriteLine("1: No config File.\n"); configFileCount = 1; } } else { Console.WriteLine("\nSelect the config file (or 'q' to quit)"); Console.WriteLine(".......................................\n"); configFileCount = 0; if (deviceCount == 0 && cameraCount != 0) { configFileCount = 1; Console.WriteLine("1: No config File."); } int configFileShow = 0; foreach (string ccfFileName in ccffiles) { string fileName = ccfFileName.Replace(configPath, ""); if (configFileCount < 9) { configFileShow = configFileCount + 1; Console.WriteLine(configFileShow.ToString() + ": " + fileName); } else if (configFileCount < MAX_CONFIG_FILES - 1) { configFileShow = configFileCount - 9 + 'a'; Console.WriteLine(Convert.ToChar(configFileShow) + ": " + fileName); } configFileNames[configFileCount] = ccfFileName; configFileCount++; } } info = Console.ReadKey(true); key = info.KeyChar; if (key == 'q') { return(false); } int configNum = 0; // Use numbers 0 to 9, then lowercase letters if there are more than 10 files if (key >= '1' && key <= '9') { configNum = key - '0'; // char-to-int conversion } else { configNum = key - 'a' + 10; // char-to-int conversion } if ((configNum >= 1) && (configNum <= configFileCount)) { acqParams.ConfigFileName = configFileNames[configNum - 1]; } else { Console.WriteLine("\nInvalid selection!\n"); return(false); } Console.WriteLine("\n"); return(true); }
static public bool GetCorAcqDeviceOptionsFromQuestions(MyAcquisitionParams acqParams, bool showGigEOnly) { int serverCount = SapManager.GetServerCount(); int GenieIndex = 0; ArrayList listServerNames = new System.Collections.ArrayList(); if (serverCount == 0) { Console.WriteLine("No device found!\n"); return(false); } bool cameraFound = false; for (int serverIndex = 0; serverIndex < serverCount; serverIndex++) { if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0) { string serverName = SapManager.GetServerName(serverIndex); if (!showGigEOnly || (showGigEOnly && SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.Acq) == 0)) { listServerNames.Add(serverName); GenieIndex++; cameraFound = true; } } } // At least one acquisition server must be available if (!cameraFound) { Console.WriteLine("No GigE camera found!\n"); return(false); } #if GRAB_CAMERA_LINK Console.WriteLine("\nNote:\nOnly CameraLink cameras will work with this example !\nBehavior is undefined for any other devices.\n"); #endif Console.WriteLine("\nSelect one of the camera(s) detected (or 'q' to quit)"); int count = 1; foreach (string serverName in listServerNames) { Console.WriteLine("\n........................................"); Console.WriteLine(Convert.ToString(count) + ": " + serverName); string deviceName = SapManager.GetResourceName(serverName, SapManager.ResourceType.AcqDevice, 0); Console.WriteLine("User defined Name : " + deviceName); Console.Write("........................................\n"); count++; } ConsoleKeyInfo info = Console.ReadKey(true); char key = info.KeyChar; if (key == 'q') { return(false); } int serverNum = key - '0'; // char-to-int conversion if ((serverNum >= 1) && (serverNum <= GenieIndex)) { acqParams.ServerName = Convert.ToString(listServerNames[serverNum - 1]); acqParams.ResourceIndex = 0; } else { Console.WriteLine("Invalid selection!\n"); return(false); } Console.WriteLine("\n"); return(true); }
const int MAX_CONFIG_FILES = 36; // 10 numbers + 26 letters static public bool GetOptionsFromCommandLine(string[] argv, MyAcquisitionParams acqParams) { // Check the command line for user commands if (argv[1].Equals("/?") || argv[1].Equals("-?")) { // print help Console.WriteLine("Usage:\n"); Console.WriteLine("Grab [<acquisition server name> <acquisition device index> <config filename>]\n"); return(false); } // Check if enough arguments were passed if (argv.Length < 4) { Console.WriteLine("Invalid command line!\n"); return(false); } // Validate server name if (SapManager.GetServerIndex(argv[1]) < 0) { Console.WriteLine("Invalid acquisition server name!\n"); return(false); } // Does the server support acquisition? int deviceCount = SapManager.GetResourceCount(argv[1], SapManager.ResourceType.Acq); int cameraCount = SapManager.GetResourceCount(argv[1], SapManager.ResourceType.AcqDevice); if (deviceCount + cameraCount == 0) { Console.WriteLine("This server does not support acquisition!\n"); return(false); } // Validate device index if (int.Parse(argv[2]) < 0 || int.Parse(argv[2]) >= deviceCount + cameraCount) { Console.WriteLine("Invalid acquisition device index!\n"); return(false); } if (cameraCount == 0) { if (!File.Exists(argv[3])) { Console.WriteLine("The specified config file (" + argv[3] + "is invalid!\n"); return(false); } } // Fill-in output variables acqParams.ServerName = argv[1]; acqParams.ResourceIndex = int.Parse(argv[2]); if (cameraCount == 0) { acqParams.ConfigFileName = argv[3]; } return(true); }