private void InitResourceCombo() { comboBox_Device.Items.Clear(); int i = 0; Object selectedItem = comboBox_Server.SelectedItem; // Add "Acq" resources (cameras) to combo for (i = 0; i < SapManager.GetResourceCount(selectedItem.ToString(), SapManager.ResourceType.Acq); i++) { string resourceName = SapManager.GetResourceName(selectedItem.ToString(), SapManager.ResourceType.Acq, i); if (SapManager.IsResourceAvailable(selectedItem.ToString(), SapManager.ResourceType.Acq, i)) { comboBox_Device.Items.Add(resourceName); if (i == m_ResourceIndex) { comboBox_Device.SelectedItem = resourceName; } } else { comboBox_Device.Items.Add("Not Available - Resource in Use"); comboBox_Device.SelectedIndex = 0; } } // Add "AcqDevice" resources (cameras) to combo for (i = 0; i < SapManager.GetResourceCount(selectedItem.ToString(), SapManager.ResourceType.AcqDevice); i++) { string resourceName; //Removed this code to fix a crash with the latest GigE driver. To be reapplied for CLHS /* * SapLocation location = new SapLocation(m_ServerName, i); * SapAcqDevice camera = new SapAcqDevice(location, false); * * bool status = camera.Create(); * int nPort = 1; //default to 1 streaming port * if (status && camera.IsParameterAvailable(SapAcqDevice.Prm.NUM_PORTS)) * camera.GetParameter(SapAcqDevice.Prm.NUM_PORTS, out nPort); * * // Destroy acquisition device object * if (!camera.Destroy()) * continue; * if (nPort == 0) * { * continue; //skip this AcqDevice since it doesn't have a video streaming port. * } */ resourceName = SapManager.GetResourceName(selectedItem.ToString(), SapManager.ResourceType.AcqDevice, i); comboBox_Device.Items.Add(resourceName); if (i == m_ResourceIndex) { comboBox_Device.SelectedItem = resourceName; } } m_ResourceIndex = comboBox_Device.SelectedIndex; }
private void InitResourceCombo() { comboBox_Device.Items.Clear(); int i = 0; Object selectedItem = comboBox_Server.SelectedItem; // Add "Acq" resources (cameras) to combo for (i = 0; i < SapManager.GetResourceCount(selectedItem.ToString(), SapManager.ResourceType.Acq); i++) { string resourceName = SapManager.GetResourceName(selectedItem.ToString(), SapManager.ResourceType.Acq, i); if (SapManager.IsResourceAvailable(selectedItem.ToString(), SapManager.ResourceType.Acq, i)) { comboBox_Device.Items.Add(resourceName); if (i == m_ResourceIndex) { comboBox_Device.SelectedItem = resourceName; } } else { comboBox_Device.Items.Add("Not Available - Resource in Use"); comboBox_Device.SelectedIndex = 0; } } // Add "AcqDevice" resources (cameras) to combo if (SapManager.GetResourceCount(selectedItem.ToString(), SapManager.ResourceType.Acq) == 0) { for (i = 0; i < SapManager.GetResourceCount(selectedItem.ToString(), SapManager.ResourceType.AcqDevice); i++) { string resourceName; resourceName = SapManager.GetResourceName(selectedItem.ToString(), SapManager.ResourceType.AcqDevice, i); comboBox_Device.Items.Add(resourceName); if (i == m_ResourceIndex) { comboBox_Device.SelectedItem = resourceName; } } } m_ResourceIndex = comboBox_Device.SelectedIndex; }
//////// 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 string[] configFileNames = new string[MAX_CONFIG_FILES]; int serverCount = SapManager.GetServerCount(); //string configFileIndexToPrint; 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 = SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice); 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; 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 { 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); }
//////// 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 string[] configFileNames = new string[MAX_CONFIG_FILES]; int serverCount = SapManager.GetServerCount(); //string configFileIndexToPrint; if (serverCount == 0) { MessageBox.Show("No device found!"); return(false); } int serverIndex = serverCount - 1; // Scan the boards to find those that support acquisition 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); serverFound = true; } if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0) { string serverName = SapManager.GetServerName(serverIndex); cameraFound = true; } } // At least one acquisition server must be available if (!serverFound && !cameraFound) { MessageBox.Show("No acquisition server found!"); return(false); } int serverNum = 1; // char-to-int conversion if ((serverNum >= 1) && (serverNum < serverCount)) { acqParams.ServerName = SapManager.GetServerName(serverNum); } else { MessageBox.Show("Invalid selection!"); 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 = SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice); int allDeviceCount = deviceCount + cameraCount; for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { string deviceName = SapManager.GetResourceName(acqParams.ServerName, SapManager.ResourceType.Acq, deviceIndex); } for (int cameraIndex = 0; cameraIndex < cameraCount; cameraIndex++) { string cameraName = SapManager.GetResourceName(acqParams.ServerName, SapManager.ResourceType.AcqDevice, cameraIndex); } int deviceNum = 1; if ((deviceNum >= 1) && (deviceNum <= allDeviceCount)) { acqParams.ResourceIndex = deviceNum - 1; } else { MessageBox.Show("Invalid selection!"); return(false); } //////////////////////////////////////////////////////////// // List all files in the config directory if (!Directory.Exists(configPath)) { MessageBox.Show("Îļþ²»´æÔÚ!"); return(false); } string[] ccffiles = Directory.GetFiles(configPath, "*.ccf"); int configFileCount = ccffiles.Length; if (configFileCount == 0) { if (cameraCount == 0) { return(false); } else { configFileCount = 1; } } else { if (cameraCount == 0) { if (configFileCount >= 2) { Console.Write(" to "); Console.Write(configFileCount.ToString()); } configFileCount = 0; } else { configFileCount += 1; configFileCount = 1; } int configFileShow = 0; foreach (string ccfFileName in ccffiles) { string fileName = ccfFileName.Replace(configPath, ""); if (configFileCount < 9) { configFileShow = configFileCount + 1; } else { configFileShow = configFileCount - 9 + 'a'; } configFileNames[configFileCount] = ccfFileName; configFileCount++; } } int configNum = 1; if ((configNum >= 1) && (configNum <= configFileCount)) { acqParams.ConfigFileName = configFileNames[configNum - 1]; } else { MessageBox.Show("Invalid selection!"); return(false); } return(true); }
static public bool GetCorAcquisitionOptionsFromQuestions(MyAcquisitionParams acqParams) { // Get total number of boards in the system string[] configFileNames = new string[MAX_CONFIG_FILES]; int serverCount = SapManager.GetServerCount(); int GrabberIndex = 0; if (serverCount == 0) { Console.WriteLine("No device found!\n"); return(false); } // Scan the boards to find those that support acquisition bool serverFound = false; for (int serverIndex = 0; serverIndex < serverCount; serverIndex++) { if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.Acq) != 0) { GrabberIndex++; serverFound = true; } } // At least one acquisition server must be available if (!serverFound) { Console.WriteLine("No acquisition server found!\n"); return(false); } Console.Write("\nSelect the acquisition server: Press "); Console.Write("1"); if (GrabberIndex >= 2) { Console.Write(" to "); Console.Write(GrabberIndex.ToString()); } Console.Write(" or 'q' to quit."); Console.WriteLine("........................................"); string serverName = ""; for (int serverIndex = 0; serverIndex < serverCount; serverIndex++) { if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.Acq) != 0) { serverName = SapManager.GetServerName(serverIndex); Console.WriteLine(serverIndex.ToString() + ": " + serverName); } } 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); #if GRAB_CAMERA_LINK Console.Write("\nSelect the device you wish to use on this server: Press "); #else Console.Write("\nSelect the acquisition device: Press "); #endif if (deviceCount >= 2) { Console.Write(" to "); Console.Write(deviceCount.ToString()); } Console.Write(" or 'q' to quit."); Console.WriteLine("........................................"); string deviceName = ""; for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { deviceName = SapManager.GetResourceName(acqParams.ServerName, SapManager.ResourceType.Acq, deviceIndex); Console.WriteLine(((int)(deviceIndex + 1)).ToString() + ": " + deviceName); } info = Console.ReadKey(true); key = info.KeyChar; if (key == 'q') { return(false); } int deviceNum = key - '0'; if ((deviceNum >= 1) && (deviceNum <= deviceCount)) { acqParams.ResourceIndex = deviceNum - 1; } else { Console.WriteLine("Invalid selection!\n"); return(false); } //////////////////////////////////////////////////////////// // List all files in the config directory if (!Directory.Exists(configPath)) { Console.WriteLine("Directory : {0} Does not exist", configPath); return(false); } string[] ccffiles = Directory.GetFiles(configPath, "*.ccf"); if (ccffiles.Length == 0) { Console.WriteLine("No config file found.\nUse CamExpert to generate a config file before running this example.\n"); return(false); } else { Console.Write("\nSelect the config file: Press "); Console.Write("1"); if (ccffiles.Length >= 2) { Console.Write(" to "); Console.Write(ccffiles.Length.ToString()); } Console.Write(" or 'q' to quit."); Console.WriteLine("........................................"); int configFileCount = 0; 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 { 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); }
public override bool DoInit() { int DalsaCardCount = SapManager.GetServerCount(); //获取图像采集卡的数量 for (int i = 0; i < DalsaCardCount; i++) { bool bAcq = false; bool bAcqDevice = false; if (SapManager.GetResourceCount(i, SapManager.ResourceType.Acq) > 0) { bAcq = true; //卡的数量大于0 } if (SapManager.GetResourceCount(i, SapManager.ResourceType.AcqDevice) > 0) { bAcqDevice = true; //相机数量大于0 } if (bAcq) { string ServerName = SapManager.GetServerName(i); if (this.myCamPara.ServerName == ServerName) { bServerFound = true; //发现图像采集卡 string DeviceName = SapManager.GetResourceName(ServerName, SapManager.ResourceType.Acq, 0); if (this.myCamPara.DeviceName != DeviceName) { Logger.PopError("采集卡上找到的相机名字和campara里的名字不同"); return(false); } } } else if (bAcqDevice) //没有采集卡,相机直接传给电脑 { CameraIsFound = true; string serverName = SapManager.GetServerName(i); } } if (!bServerFound && !CameraIsFound) //至少需要一张采集卡,或者相机装置 { m_Buffers = new SapBuffer(); return(false); } else { SapLocation location = new SapLocation(this.myCamPara.ServerName, 0); if (SapManager.GetResourceCount(this.myCamPara.ServerName, SapManager.ResourceType.Acq) > 0) { m_Acquisition = new SapAcquisition(location, System.Windows.Forms.Application.StartupPath + "\\ccf\\" + this.myCamPara.CcfPath + ".ccf"); //m_AcqDevice = new SapAcqDevice(location, System.Windows.Forms.Application.StartupPath + "\\ccf\\" + this.myCamPara.CcfPath + ".ccf"); if (SapBuffer.IsBufferTypeSupported(location, SapBuffer.MemoryType.ScatterGather)) { m_Buffers = new SapBuffer(m_RingBufCount, m_Acquisition, SapBuffer.MemoryType.ScatterGather); //buffer里有10段内存,用来循环存储从相机采集的图片 } else { m_Buffers = new SapBufferWithTrash(m_RingBufCount, m_Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical); } m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers); m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; m_Xfer.XferNotify += new SapXferNotifyHandler(AcqCallback1); m_Xfer.XferNotifyContext = this; // event for signal status if (!SeparaInterface_CreateObjects()) { Logger.PopError(" 创建 相关的采集、传输、缓存对象失败"); this.SeparaInterface_DisposeObjects(); return(false); } this.FrameImgHei = this.SeparaInterface_GetImageHeight(); this.FrameImgWid = this.SeparaInterface_GetImageWidth(); return(true); } } return(false); }