예제 #1
0
 /// <summary>
 /// 刷新设备列表
 /// </summary>
 private void RefreshDeviceList()
 {
     try
     {
         // 先删除列表中的所有相机
         deviceList.Nodes[0].Nodes.Clear();
         // 再添加已探测到的相机
         // 建立链表存放所有已经找到的 CameraInfo
         List <ICameraInfo> allCamerasInfo = CameraFinder.Enumerate();
         foreach (ICameraInfo cameraInfo in allCamerasInfo)
         {
             Camera   tempCamera = new Camera(cameraInfo);
             TreeNode tempNode   = new TreeNode(cameraInfo[CameraInfoKey.ModelName]);
             //在 nodeBasler 节点下新增节点
             tempNode.Tag = tempCamera;
             deviceList.Nodes[0].Nodes.Add(tempNode);
         }
         //刷新后默认的相机为第一个相机
         myCamera = (Camera)(deviceList.Nodes[0].FirstNode.Tag);
     }
     catch (Exception E)
     {
         ShowException(E);
     }
 }
        internal static void PrintCameraList(String headline)
        {
            List <ICameraInfo> deviceList = CameraFinder.Enumerate();

            Console.WriteLine("Available Devices " + headline);
            Console.WriteLine(String.Format("{0,-32}{1,-14}{2,-17}{3,-17}{4,-15}{5,-8}",
                                            "Friendly Name", "MAC", "IP Address", "Subnet Mask", "Gateway", "Mode"));

            foreach (var device in deviceList)
            {
                // Determine currently active configuration method
                String currentConfig;
                if (IpConfigurator.IsPersistentIpActive(device))
                {
                    currentConfig = "StaticIP";
                }
                else if (IpConfigurator.IsDhcpActive(device))
                {
                    currentConfig = "DHCP";
                }
                else if (IpConfigurator.IsAutoIpActive(device))
                {
                    currentConfig = "AutoIP";
                }
                else
                {
                    currentConfig = "Unknown";
                }

                Console.WriteLine(String.Format("{0,-32}{1,-14}{2,-17}{3,-17}{4,-15}{5,-8}",
                                                device[CameraInfoKey.FriendlyName], device[CameraInfoKey.DeviceMacAddress], device[CameraInfoKey.DeviceIpAddress],
                                                device[CameraInfoKey.SubnetMask], device[CameraInfoKey.DefaultGateway], currentConfig));
            }
        }
예제 #3
0
        /// <summary>
        /// 创建连接,传入相机类型,使用DeviceType类进行有效赋值,检测所有可能的usb相机设备的连接,并返回连接相机数目,以及相机信息列表;
        /// 若存在连接返回true,若无连接返回false
        /// </summary>
        /// <param name="DeviceType"></param>
        /// <param name="DeviceNum"></param>
        /// <param name="AllCameraInfo"></param>
        /// <param name="ErrorMessage"></param>
        /// <returns></returns>
        public bool TryGetConnect(string DeviceType, out int DeviceNum, out List <ICameraInfo> AllCameraInfo, out string ErrorMessage)
        {
            List <ICamera> cameras = new List <ICamera>();

            try
            {
                AllCameraInfo = CameraFinder.Enumerate(Basler.Pylon.DeviceType.GigE);
                DeviceNum     = AllCameraInfo.Count;
                if (DeviceNum == 0)
                {
                    DeviceNum     = 0;
                    AllCameraInfo = null;
                    ErrorMessage  = "0个设备连接";
                    return(false);
                }
                else
                {
                    ErrorMessage = null;
                    return(true);
                }
            }
            catch (Exception exception)
            {
                ErrorMessage  = exception.Message;
                DeviceNum     = 0;
                AllCameraInfo = null;
                return(false);
            }
        }
예제 #4
0
 public BaslerCamera(IVisionCameraInfo info) : base(info)
 {
     this.UserID = Info.UserID;
     Image       = new HImage();
     timer       = new HiPerfTimer();
     try
     {
         Image = new HImage();
         // 枚举相机列表,获取固定相机名称
         List <ICameraInfo> allCameraInfos = CameraFinder.Enumerate();
         foreach (ICameraInfo cameraInfo in allCameraInfos)
         {
             if (this.UserID == cameraInfo[CameraInfoKey.UserDefinedName])
             {
                 camera         = new Camera(cameraInfo);
                 Info.CameraIP  = cameraInfo[CameraInfoKey.DeviceIpAddress].ToString();
                 info.CameraMac = cameraInfo[CameraInfoKey.DeviceMacAddress].ToString();
             }
         }
         if (camera == null)
         {
             WriteErrorLog("It can not recognite the camera of  " + UserID);
         }
     }
     catch (Exception e)
     {
         WriteErrorLog(e.ToString());
     }
 }
예제 #5
0
        /// <summary>
        /// 根据相机序列号实例化相机
        /// </summary>
        /// <param name="SN"></param>
        //public BaslerCam(string SN)
        //{
        //    camera = new Camera(SN);
        //}

        /// <summary>
        /// 根据相机UserID实例化相机
        /// </summary>
        /// <param name="UserID"></param>
        public CameraBasler(string UserID)
        {
            try
            {
                strUserID = UserID;     //掉线重连用

                // 枚举相机列表
                List <ICameraInfo> allCameraInfos = CameraFinder.Enumerate();

                foreach (ICameraInfo cameraInfo in allCameraInfos)
                {
                    // MessageBox.Show(cameraInfo[CameraInfoKey.ModelName]);

                    if (strUserID == cameraInfo[CameraInfoKey.UserDefinedName])
                    {
                        camera = new Camera(cameraInfo);
                    }
                }

                if (camera == null)
                {
                    MessageBox.Show("未识别到UserID为“" + strUserID + "”的相机!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception e)
            {
                ShowException(e);
            }
        }
예제 #6
0
        private void Monitor(object state)
        {
            var availableCameras = CameraFinder.Enumerate();

            if (availableCameras.Any() && ConnectedCamera == null)
            {
                try
                {
                    var camera = new Camera();
                    camera.Open();
                    ConnectedCamera = new CameraBasler(camera);
                    ConnectedCamera.SetDefaultSettings();
                    ConnectedCamera.Camera.ConnectionLost += Camera_ConnectionLost;
                    OnCameraConnected();
                    timer.Dispose();
                }
                catch (Exception)
                {
                    OnCameraFailed("The camera is in use by another application. Close the other application to start recording");
                }
            }
            else
            {
                OnCameraFailed("Camera not found");
            }
        }
예제 #7
0
            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                var cameras = from camera in CameraFinder.Enumerate()
                              where camera.ContainsKey(CameraInfoKey.SerialNumber)
                              select camera[CameraInfoKey.SerialNumber];

                return(new StandardValuesCollection(cameras.ToArray()));
            }
예제 #8
0
파일: Basler.cs 프로젝트: 22860364/Xvision
        public override List <string> GetCameraList()// 获得相机列表
        {
            List <string>      cameraList = new List <string>();
            List <ICameraInfo> listInfo   = CameraFinder.Enumerate(DeviceType.GigE);//枚举相机列表

            foreach (ICameraInfo info in listInfo)
            {
                cameraList.Add(info.GetValueOrDefault("VendorName", "") + ":" + info.GetValueOrDefault("SerialNumber", ""));
            }
            return(cameraList);
        }
예제 #9
0
 /// <summary>
 /// 获取当前连接的所有相机名字
 /// </summary>
 /// <param name="serial">序列号</param>
 /// <param name="display">显示名</param>
 public static void GetConnectedCameras(ref IList <string> serial, ref IList <string> display)
 {
     serial.Clear();
     display.Clear();
     foreach (ICameraInfo c in CameraFinder.Enumerate())
     {
         string s = c[CameraInfoKey.SerialNumber];
         string n = c[CameraInfoKey.FriendlyName];
         serial.Add(s);
         display.Add($"{n}({s})");
     }
 }
        public System.Collections.ObjectModel.ReadOnlyCollection <ICamera> Discover()
        {
            cameras.Clear();

            List <ICameraInfo> allCameras = CameraFinder.Enumerate();

            foreach (ICameraInfo cameraInfo in allCameras)
            {
                string t = cameraInfo[CameraInfoKey.FullName];
                cameras.Add(new BaslerCamera(cameraInfo, this));
            }

            return(cameras.AsReadOnly());
        }
예제 #11
0
        /// <summary>
        /// 根据相机序列号实例化相机
        /// </summary>
        /// <param name="UserID"></param>
        public BalserCognexCamera(string SerialNumber)
        {
            // 枚举相机列表
            List <ICameraInfo> allCameraInfos = CameraFinder.Enumerate();

            foreach (ICameraInfo cameraInfo in allCameraInfos)
            {
                if (SerialNumber == cameraInfo[CameraInfoKey.SerialNumber])
                {
                    cameraName         = cameraInfo[CameraInfoKey.ModelName] + "[" + SerialNumber + "]";
                    cameraSerialNumber = SerialNumber;
                    cameraDeviceID     = cameraInfo[CameraInfoKey.FriendlyName].Substring(0, cameraInfo[CameraInfoKey.FriendlyName].IndexOf("("));
                    camera             = new Camera(cameraInfo);
                }
            }
        }
예제 #12
0
        public static List <ICameraInfo> GetDeviceList()
        {
            List <ICameraInfo> lstDevInfo = null;

            try
            {
                // Ask the camera finder for a list of camera devices.
                lstDevInfo = CameraFinder.Enumerate();
            }
            catch (Exception exception)
            {
                //ShowException(exception);
                System.Windows.Forms.MessageBox.Show("Exception caught:\n" + exception.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }

            return(lstDevInfo);
        }
예제 #13
0
        public BaslerCamera(string ip)
        {
            foreach (ICameraInfo INFO in CameraFinder.Enumerate())
            {
                if (INFO.GetValueOrDefault("IpAddress", "0") == ip)
                {
                    camera = new Camera(INFO);
                    break;
                }
            }
            if (camera == null)
            {
                camera = new Camera();
            }

            grabbing = false;
        }
예제 #14
0
        /// <summary>
        /// 创建一个相机,相机初始化
        /// </summary>
        public CCamera( string name)
        {
            try
            {
                isopen = false;
                imageTools = new List<ImageTools>();
                isfirst = true;
                List<ICameraInfo> allCameraInfos = CameraFinder.Enumerate();
                bool isconnect = false;
                foreach (ICameraInfo cameraInfo in allCameraInfos)
                {
                    Console.WriteLine(cameraInfo[CameraInfoKey.FriendlyName] + "--" + name);
                    if (cameraInfo[CameraInfoKey.FriendlyName] == name)
                    {
                        physicsname = cameraInfo[CameraInfoKey.FriendlyName];
                        camera = new Camera(cameraInfo);
                        isconnect = true;
                    }
                }

                if (isconnect == false)
                {
                    MessageBox.Show(name + "没有连接");
                }
                resultHTuple = new HTuple();
                result = new Result();
                HOperatorSet.GenEmptyObj(out RegionToDisp);
                HOperatorSet.GenEmptyObj(out Image);
                HOperatorSet.GenEmptyObj(out TImage);
                HOperatorSet.GenEmptyObj(out tempImage);
                m_lockObject = new Object();
                dataSelectedShowed = new List<DataSelected>();
                exposureTime = 100;
                gain = 300;
                pixelDist = 1;
                getcpu = true;
                listimage = new List<HObject>();
                listimage1 = new Queue<HObject>();
                goodcountlist = new List<int>();
                badcountlist = new List<int>();
            }
            catch (Exception)
            {
                MessageBox.Show("相机初始化失败");
            }
        }
예제 #15
0
        /// <summary>
        /// 巴斯勒相机
        /// </summary>
        /// <returns></returns>
        public static List <string> GetBaslerCameraListInfo()
        {
            List <string> cameralist = new List <string>();

            try
            {
                List <ICameraInfo> allCameraInfos = CameraFinder.Enumerate();
                foreach (ICameraInfo cameraInfo in allCameraInfos)
                {
                    cameralist.Add(cameraInfo[CameraInfoKey.UserDefinedName]);
                }
            }
            catch (Exception e)
            {
                LogFileManager.Error("Camera", e.ToString());
            }
            return(cameralist);
        }
예제 #16
0
 /// <summary>
 /// 枚举设备
 /// </summary>
 public bool EnumDevice()
 {
     listCameraInfo = CameraFinder.Enumerate();
     if (listCameraInfo.Count == 0)
     {
         return(false);
     }
     else
     {
         for (int i = 0; i < listCameraInfo.Count; i++)
         {
             BaslerCam objCamera = new BaslerCam();
             objCamera.strName = listCameraInfo[i][CameraInfoKey.UserDefinedName];
             objCamera.objDev  = new Basler.Pylon.Camera(listCameraInfo[i]);
             listCamera.Add(objCamera);//添加相机列队
         }
         return(true);
     }
 }
예제 #17
0
        /// <summary>
        /// 根据相机序列号实例化相机
        /// </summary>
        /// <param name="SN"></param>
        //public BaslerCam(string SN)
        //{
        //    camera = new Camera(SN);
        //}
        public static List <string> GetAllCamerasSerialNumber()
        {
            try
            {
                List <string> listSerialNumer = new List <string>();

                // 枚举相机列表
                List <ICameraInfo> allCameraInfos = CameraFinder.Enumerate();
                foreach (ICameraInfo cameraInfo in allCameraInfos)
                {
                    listSerialNumer.Add(cameraInfo[CameraInfoKey.SerialNumber]);
                }
                return(listSerialNumer);
            }
            catch
            {
                return(null);
            }
        }
        Image <Bgr, byte> QueryFrameBP(int CameraNum, int SWidth, int SHeigth)
        {
            string            Resultado = string.Empty;
            Camera            _Camera   = null;
            Image <Bgr, byte> _imageCV  = null;

            List <ICameraInfo> _cameras = new List <ICameraInfo>();

            _cameras = CameraFinder.Enumerate();

            string _CameraModelName = _cameras[CameraNum][CameraInfoKey.ModelName];

            _Camera = new Camera(_cameras[CameraNum]);

            _Camera.CameraOpened += Configuration.AcquireContinuous;

            _Camera.Open();

            _Camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(5);

            _Camera.StreamGrabber.Start();

            IGrabResult grabResult = _Camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);

            if (grabResult.GrabSucceeded)
            {
                Bitmap _tempImg = GrabResult2Bmp(grabResult);
                _imageCV = new Image <Bgr, byte>(_tempImg);
                _imageCV = _imageCV.Resize(SWidth, SHeigth, Inter.Linear);
                _Camera.StreamGrabber.Stop();
                _Camera.Close();
                _Camera.Dispose();
            }

            if (!grabResult.GrabSucceeded)
            {
                _Camera.StreamGrabber.Stop();
                _Camera.Close();
                _Camera.Dispose();
            }
            return(_imageCV);
        }
예제 #19
0
 public override void OpenCamera()
 {
     lock (m_lock)
     {
         List <ICameraInfo> allCameras = CameraFinder.Enumerate();
         foreach (ICameraInfo cameraInfo in allCameras)
         {
             if (this.m_Cameraname == cameraInfo[CameraInfoKey.UserDefinedName])
             {
                 camera = new Camera(cameraInfo);
                 if (!camera.Open(1000, TimeoutHandling.Return))
                 {
                     throw new Exception($"faile to open the camera{this.m_Cameraname}");
                 }
                 return;
             }
         }
         throw new Exception($"cannot find the camera named as{this.m_Cameraname}");
     }
 }
예제 #20
0
 public override string GetCameraIPAddress()
 {
     try
     {
         List <ICameraInfo> allCameras = CameraFinder.Enumerate();
         foreach (ICameraInfo camerainfo in allCameras)
         {
             if (this.UserID == camerainfo[CameraInfoKey.UserDefinedName])
             {
                 Info.CameraIP = camerainfo[CameraInfoKey.DeviceIpAddress].ToString();
                 break;
             }
         }
     }
     catch (Exception e)
     {
         WriteErrorLog(UserID + "相机-----" + e.ToString());
     }
     return(Info.CameraIP);
 }
예제 #21
0
        /// <summary>
        /// 获取DeviceID
        /// </summary>
        /// <returns></returns>
        public static List <string> GetAllCamerasDeviceID()
        {
            try
            {
                List <string> listDeviceID = new List <string>();

                // 枚举相机列表
                List <ICameraInfo> allCameraInfos = CameraFinder.Enumerate();
                foreach (ICameraInfo cameraInfo in allCameraInfos)
                {
                    string DeviceID = cameraInfo[CameraInfoKey.FriendlyName].Substring(0, cameraInfo[CameraInfoKey.FriendlyName].IndexOf("("));
                    listDeviceID.Add(cameraInfo[CameraInfoKey.FriendlyName]);
                }
                return(listDeviceID);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #22
0
 /// <summary>
 /// 初始化设备上所有的相机信息
 /// </summary>
 public bool Init()
 {
     try
     {
         allCameras = CameraFinder.Enumerate(); // 查找设备上所有的相机
         if (allCameras.Count == 0)
         {
             return(false);
         }
         //遍历所有相机
         foreach (ICameraInfo cameraInfo in allCameras)
         {
             dicCameraInfo.Add(cameraInfo[CameraInfoKey.UserDefinedName], cameraInfo[CameraInfoKey.SerialNumber]);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
        public int OpenCamera()
        {
            List <ICameraInfo> allCameras = CameraFinder.Enumerate();

            foreach (ICameraInfo tempinfo in allCameras)
            {
                if (tempinfo[CameraInfoKey.UserDefinedName] == name)
                {
                    getonecamera = new Camera(tempinfo);
                    if (getonecamera.IsOpen)
                    {
                        return(0);
                    }

                    TriggerConfiguration();
                    getonecamera.Open();
                    SetExposureTime();
                    SetImageROI();
                }
            }
            return(1);
        }
예제 #24
0
        public void CameraInit()
        {
            // Ask the camera finder for a list of camera devices.
            List <ICameraInfo> allCameras = CameraFinder.Enumerate();

            camera = new Camera();

            if (camera != null)
            {
                // Print the model name of the camera.
                Console.WriteLine("Using camera {0}.", camera.CameraInfo[CameraInfoKey.ModelName]);
                camera.CameraOpened               += Configuration.AcquireContinuous;
                camera.ConnectionLost             += Camera_ConnectionLost;
                camera.StreamGrabber.GrabStarted  += StreamGrabber_GrabStarted;
                camera.StreamGrabber.ImageGrabbed += StreamGrabber_ImageGrabbed;
                camera.StreamGrabber.GrabStopped  += StreamGrabber_GrabStopped;
                camera.Open();
                camera.Parameters[PLCamera.GevSCPSPacketSize].SetValue(8192);   //Réglage du packet Size à 8192
                camera.Parameters[PLCamera.GevSCPD].SetValue(10000);            //Réglage de l'inter packet delay à 10000
            }
            //SetValue(PLCamera.AcquisitionMode.Continuous);
            KeepShot();
        }
        public bool Init()
        {
            cameras.Clear();

            List <ICameraInfo> allCameras = CameraFinder.Enumerate();

            foreach (ICameraInfo camerainfo in allCameras)
            {
                AqBaslerCamera camera = new AqBaslerCamera();
                camera.Name = camerainfo[CameraInfoKey.UserDefinedName];
                //camera.Id = camerainfo[CameraInfoKey.DeviceID];//ID无法获取,加入此代码则异常
                camera.Mac = camerainfo[CameraInfoKey.DeviceMacAddress];
                camera.Ip  = camerainfo[CameraInfoKey.DeviceIpAddress];
                cameras.Add(camera);
            }

            if (cameras.Count == 0)
            {
                return(false);
            }

            return(true);
        }
예제 #26
0
        public void CameraInit()
        {
            // Ask the camera finder for a list of camera devices.
            List <ICameraInfo> allCameras = CameraFinder.Enumerate();

            camera = new Camera("22427616");

            if (camera != null)
            {
                configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                // Print the model name of the camera.
                Console.WriteLine("Using camera {0}.", camera.CameraInfo[CameraInfoKey.ModelName]);
                camera.CameraOpened               += Basler.Pylon.Configuration.AcquireContinuous;
                camera.ConnectionLost             += Camera_ConnectionLost;
                camera.StreamGrabber.GrabStarted  += StreamGrabber_GrabStarted;
                camera.StreamGrabber.ImageGrabbed += StreamGrabber_ImageGrabbed;
                camera.StreamGrabber.GrabStopped  += StreamGrabber_GrabStopped;

                camera.Open();
                SetUpCamera();
            }
            //SetValue(PLCamera.AcquisitionMode.Continuous);
        }
예제 #27
0
        private void UpdateDeviceList()
        {
            try
            {
                // Ask the camera finder for a list of camera devices.
                List <ICameraInfo> allCameras = CameraFinder.Enumerate();

                ItemCollection items = deviceListView.Items;

                // Loop over all cameras found.
                foreach (ICameraInfo cameraInfo in allCameras)
                {
                    // Loop over all cameras in the list of cameras.
                    bool newitem = true;
                    foreach (ListViewItem item in items)
                    {
                        ICameraInfo tag = item.Tag as ICameraInfo;

                        // Is the camera found already in the list of cameras?
                        if (tag[CameraInfoKey.FullName] == cameraInfo[CameraInfoKey.FullName])
                        {
                            tag     = cameraInfo;
                            newitem = false;
                            break;
                        }
                    }

                    // If the camera is not in the list, add it to the list.
                    if (newitem)
                    {
                        // Create the item to display.
                        ListViewItem item = new ListViewItem
                        {
                            Content = cameraInfo[CameraInfoKey.FriendlyName]
                        };
                        // Create the tool tip text.
                        string toolTipText = "";
                        foreach (KeyValuePair <string, string> kvp in cameraInfo)
                        {
                            toolTipText += kvp.Key + ": " + kvp.Value + "\n";
                        }
                        item.ToolTip = toolTipText;

                        // Store the camera info in the displayed item.
                        item.Tag = cameraInfo;
                        // Attach the device data.
                        deviceListView.Items.Add(item);
                    }
                }


                // Remove old camera devices that have been disconnected.
                foreach (ListViewItem item in items)
                {
                    bool exists = false;

                    // For each camera in the list, check whether it can be found by enumeration.
                    foreach (ICameraInfo cameraInfo in allCameras)
                    {
                        if (((ICameraInfo)item.Tag)[CameraInfoKey.FullName] == cameraInfo[CameraInfoKey.FullName])
                        {
                            exists = true;
                            break;
                        }
                    }
                    // If the camera has not been found, remove it from the list view.
                    if (!exists)
                    {
                        deviceListView.Items.Remove(item);
                    }
                }
            }
            catch (Exception exception)
            {
                ShowException(exception);
            }
        }
예제 #28
0
        internal static void Main()
        {
            int           exitCode = 0;
            List <Camera> cameras  = new List <Camera>();

            try
            {
                // Ask the camera finder for a list of all GigE camera devices.
                // Note that this sample only works with GigE camera devices.
                List <ICameraInfo> allDeviceInfos = CameraFinder.Enumerate(DeviceType.GigE);

                if (allDeviceInfos.Count == 0)
                {
                    throw new ApplicationException("No GigE cameras present.");
                }

                // Open all cameras to fulfill preconditions for Configure(ICamera())
                allDeviceInfos.ForEach(cameraInfo => cameras.Add(new Camera(cameraInfo)));
                cameras.ForEach(camera => camera.Open());

                // Prepare all cameras for action commands
                ActionCommandTrigger actionCommandTrigger = new ActionCommandTrigger();

                // Configure all cameras to wait for the action command. If a camera doesn't support action commands, an exception will be thrown.
                actionCommandTrigger.Configure(cameras.ToArray());

                // Starts grabbing on all cameras.
                // The cameras won't transmit any image data because they are configured to wait for an action command.
                cameras.ForEach(camera => camera.StreamGrabber.Start());

                // Now we issue the action command to all devices without any DeviceKey, GroupKey, or GroupMask
                // because Configure(ICamera()) had already set these parameters.
                actionCommandTrigger.Issue();

                // Retrieve images from all cameras.
                foreach (Camera camera in cameras)
                {
                    // Camera will return grab results in the order they arrive.
                    IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                    using (grabResult)
                    {
                        // Image grabbed successfully?
                        if (grabResult.GrabSucceeded)
                        {
                            // Print the model name and the IP address of the camera.
                            Console.WriteLine("Image grabbed successfully for: {0} ({1})",
                                              camera.CameraInfo.GetValueOrDefault(CameraInfoKey.FriendlyName, null),
                                              camera.CameraInfo.GetValueOrDefault(CameraInfoKey.DeviceIpAddress, null));
                        }
                        else
                        {
                            // If a buffer hasn't been grabbed completely, the network bandwidth is possibly insufficient for transferring
                            // multiple images simultaneously. See note above c_maxCamerasToUse.
                            Console.WriteLine("Error: {0} {1}", grabResult.ErrorCode, grabResult.ErrorDescription);
                        }
                    }
                }
                // To avoid overtriggering, you should call cameras[0].WaitForFrameTriggerReady
                // (see Grab_UsingGrabLoopThread sample for details).
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
                exitCode = 1;
            }
            finally
            {
                // Stop stream grabber and close all cameras.
                cameras.ForEach(camera => { camera.StreamGrabber.Stop(); camera.Close(); camera.Dispose(); });
                // Comment the following two lines to disable waiting on exit.
                Console.Error.WriteLine("\nPress enter to exit.");
                Console.ReadLine();
            }

            Environment.Exit(exitCode);
        }
예제 #29
0
        private void UpdateBaslerDeviceList()
        {
            try
            {
                // Ask the camera finder for a list of camera devices.
                BaslerCameraAll = CameraFinder.Enumerate();

                foreach (ICameraInfo cameraInfo in BaslerCameraAll)
                {
                    // Loop over all cameras in the list of cameras.
                    bool newitem = true;
                    foreach (CAM cam in CAMs)
                    {
                        ICameraInfo tag = cam.Tag as ICameraInfo;

                        // Is the camera found already in the list of cameras?
                        if (tag[CameraInfoKey.FullName] == cameraInfo[CameraInfoKey.FullName])
                        {
                            tag     = cameraInfo;
                            newitem = false;
                            break;
                        }
                    }

                    // If the camera is not in the list, add it to the list.
                    if (newitem)
                    {
                        // Create the item to display.
                        CAM cam = new CAM()
                        {
                            Name    = cameraInfo[CameraInfoKey.FullName],
                            Tag     = cameraInfo,
                            CAMType = CAMTYPE.BASLER
                        };

                        CAMs.Add(cam);
                    }
                }

                // Remove old camera devices that have been disconnected.
                foreach (CAM cam in CAMs)
                {
                    bool exists = false;

                    // For each camera in the list, check whether it can be found by enumeration.
                    foreach (ICameraInfo cameraInfo in BaslerCameraAll)
                    {
                        if (((ICameraInfo)cam.Tag)[CameraInfoKey.FullName] == cameraInfo[CameraInfoKey.FullName])
                        {
                            exists = true;
                            break;
                        }
                    }
                    // If the camera has not been found, remove it from the list view.
                    if (!exists)
                    {
                        CAMs.Remove(cam);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: {0}", e.Message);
            }
        }
예제 #30
0
 // 枚举相机
 public List <ICameraInfo> CameraEnum()
 {
     // 相机个数
     allCameraInfos = CameraFinder.Enumerate();
     return(allCameraInfos);
 }