Пример #1
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            if (checkBox_configfile.Checked)
            {
                m_ConfigFile = m_currentConfigDir + "\\" + m_currentConfigFileName;
            }
            else
            {
                m_ConfigFile = "";
            }

            if (ServCategory == ServerCategory.ServerAll)
            {
                if (
                    SapManager.GetResourceCount(new SapLocation(m_ServerName, m_ResourceIndex),
                                                SapManager.ResourceType.Acq) > 0)
                {
                    ServCategory = ServerCategory.ServerAcq;
                }
                else if (
                    SapManager.GetResourceCount(new SapLocation(m_ServerName, m_ResourceIndex),
                                                SapManager.ResourceType.AcqDevice) > 0)
                {
                    ServCategory = ServerCategory.ServerAcqDevice;
                }
            }

            SaveSettings();
        }
Пример #2
0
        public bool CAM_connect()
        {
            try
            {
                //server名称
                int    ServerCount = SapManager.GetServerCount();
                int    ServerIndex = ServerCount - 1;
                string ServerName  = SapManager.GetServerName(ServerIndex);
                //设备Index
                int CameraCount   = SapManager.GetResourceCount(ServerName, SapManager.ResourceType.AcqDevice);
                int ResourceIndex = CameraCount - 1;
                //if (CameraCount == 0) MessageBox.Show("没有相机。");

                loc = new SapLocation(ServerName, ResourceIndex);

                //配置文件
                string   ConfigFileName;
                string   ConfigPath      = Environment.GetEnvironmentVariable("SAPERADIR") + "\\camFiles\\User\\";
                string[] ccffiles        = Directory.GetFiles(ConfigPath, "*.ccf");
                int      configFileCount = ccffiles.Length;
                ConfigFileName = ccffiles[0];
                //创建对象
                if (SapManager.GetResourceCount(ServerName, SapManager.ResourceType.AcqDevice) > 0)
                {
                    AcqDevice = new SapAcqDevice(loc, ConfigFileName);
                    Buffers   = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                    Xfer      = new SapAcqDeviceToBuf(AcqDevice, Buffers);
                    if (!AcqDevice.Create())
                    {
                        return(false);
                    }
                }

                if (!Buffers.Create())
                {
                    return(false);
                }
                if (!Xfer.Create())
                {
                    return(false);
                }


                ////ManagedBusManager busMgr = new ManagedBusManager();
                ////uint numCameras = busMgr.GetNumOfCameras();
                ////ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);
                ////m_camera = new ManagedCamera();
                ////m_camera.Connect(guid);
                //m_camera.IsConnected()
                //CameraInfo camInfo = m_camera.GetCameraInfo();
            }
            catch (FC2Exception ex)//要修改
            {
                MessageBox.Show("相机连接失败。");
                MessageBox.Show("Failed to load form successfully: " + ex.Message);
                return(false);
            }
            return(true);
        }
        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;
        }
Пример #4
0
        public void InitDevice(MyAcquisitionParams acqParams = null)
        {
            _acqParams = acqParams;

            if (acqParams == null)
            {
                string[] args = new string[0];
                if (!ExampleUtils.GetOptions(args, acqParams))
                {
                    Console.WriteLine("\nPress any key to terminate\n");
                    Console.ReadKey(true);
                    return;
                }
            }



            _loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);
            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                _acqDevice = new SapAcqDevice(_loc, acqParams.ConfigFileName);
                _buffers   = new SapBufferWithTrash(2, _acqDevice, SapBuffer.MemoryType.ScatterGather);
                _transfer  = new SapAcqDeviceToBuf(_acqDevice, _buffers);

                // Create acquisition object
                if (!_acqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(null, _acqDevice, _buffers, _transfer, _view);
                    return;
                }
            }

            _transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            _transfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            _transfer.XferNotifyContext  = _buffers;

            // Create buffer object
            if (!_buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(null, _acqDevice, _buffers, _transfer, _view);
                return;
            }

            // Create buffer object
            if (!_transfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(null, _acqDevice, _buffers, _transfer, _view);
                return;
            }

            _transfer.Grab();
        }
Пример #5
0
        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);
        }
Пример #6
0
        private bool InitServerCombo()
        {
            comboBox_Server.Items.Clear();
            for (int i = 0; i < SapManager.GetServerCount(); i++)
            {
                // Does this server support "Acq" (frame-grabber) or "AcqDevice" (camera)?
                bool bAcq = (m_ServerCategory == ServerCategory.ServerAcq || m_ServerCategory == ServerCategory.ServerAll) &&
                            (SapManager.GetResourceCount(i, SapManager.ResourceType.Acq) > 0);
                bool bAcqDevice = (m_ServerCategory == ServerCategory.ServerAcqDevice || m_ServerCategory == ServerCategory.ServerAll) &&
                                  (SapManager.GetResourceCount(i, SapManager.ResourceType.AcqDevice) > 0);

                if (bAcq)
                {
                    string serverName = SapManager.GetServerName(i);
                    comboBox_Server.Items.Add(new MyListBoxItem(serverName, true));
                }
                else if (bAcqDevice)
                {
                    string serverName = SapManager.GetServerName(i);
                    if (serverName.Contains("CameraLink_") == false)
                    {
                        comboBox_Server.Items.Add(new MyListBoxItem(serverName, false));
                    }
                }
            }
            if (comboBox_Server.Items.Count <= 0)
            {
                return(false);
            }
            else
            {
                if (string.IsNullOrEmpty(m_ServerName) || comboBox_Server.FindString(m_ServerName, 0) == -1)
                {
                    comboBox_Server.SelectedIndex = 0;
                    m_ServerName = comboBox_Server.SelectedItem.ToString();
                }
                else
                {
                    comboBox_Server.SelectedIndex = comboBox_Server.FindString(m_ServerName, 0);
                }

                InitResourceCombo();
                return(true);
            }
        }
Пример #7
0
        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;
        }
Пример #8
0
        //////// 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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        const int MAX_CONFIG_FILES = 36;       // 10 numbers + 26 letters
        //static char configFileNames[MAX_CONFIG_FILES][MAX_PATH] = {0};


        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);
        }
Пример #11
0
        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();
        }
Пример #12
0
        //////// 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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
Пример #15
0
        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();
        }
Пример #16
0
        private void btn_findcamera_Click(object sender, EventArgs e)
        {
            Console.WriteLine(cb_cameraselect.SelectedIndex);
            switch (cb_cameraselect.SelectedIndex)
            {
            case 0:
                Console.WriteLine("\n\nCameras listed by User Defined Name:\n");

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get User Defined Name Feature Value
                            status = acqDevice.GetFeatureValue("DeviceUserID", new SapLut(tx_commandparameter.Text.ToString()));
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, status ? userDefinedName : "N/A");
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 1:
                Console.WriteLine("\n\nCameras listed by Serial Number:\n");
                string serialNumberName = "";

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get Serial Number Feature Value
                            status = acqDevice.GetFeatureValue("DeviceID", out serialNumberName);
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, status ? serialNumberName : "N/A");
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 2:
                Console.WriteLine("\n\nCameras listed by Server Name:\n");

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get Server Name Value
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, SapManager.GetServerName(serverIndex));
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 3:
                Console.WriteLine("\n\nCameras listed by Model Name:\n");
                string deviceModelName = "";

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get Model Name Feature Value
                            status = acqDevice.GetFeatureValue("DeviceModelName", out deviceModelName);
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, status ? deviceModelName : "N/A");
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 4:
                Console.WriteLine("Please type the user defined name:\n");
                userDefinedName = Console.ReadLine();
                serverName      = SapManager.GetServerName(userDefinedName);
                if (serverName.Length > 0)
                {
                    Console.WriteLine("\nServer name for {0} is {1}", userDefinedName, serverName);
                }
                else
                {
                    Console.WriteLine("\nNo server found for {0}", userDefinedName);
                }
                break;

            case 5:
                Console.Write("\nDetecting new CameraLink camera servers... ");
                if (SapManager.DetectAllServers(SapManager.DetectServerType.All))
                {
                    // let time for the detection to execute
                    Thread.Sleep(5000);

                    // get the new server count
                    serverCount = SapManager.GetServerCount();

                    Console.WriteLine("complete\n");
                }
                else
                {
                    Console.WriteLine("failed\n");
                }
                break;
            }
        }