| | |
| | | typeof(IMVDefine.IMV_DeviceInfo)); |
| | | |
| | | string cameraInfo = $"{deviceInfo.cameraName}[{deviceInfo.serialNumber}]"; |
| | | if (!cameraInfo.Contains("L")) |
| | | { |
| | | cameraList.Add(cameraInfo); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 记录日志或抛出异常 |
| | | //throw new Exception($"枚举设备失败,错误码:{result}"); |
| | | AsyncLogHelper.Error("枚举设备失败!"); |
| | | System.Diagnostics.Debug.WriteLine("枚举设备失败!"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录错误日志 |
| | | System.Diagnostics.Debug.WriteLine($"获取相机列表失败:{ex.Message}"); |
| | | AsyncLogHelper.Error($"获取相机列表失败:{ex.Message}"); |
| | | throw; |
| | | } |
| | | |
| | | return cameraList; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取相机SN枚举列表 |
| | | /// </summary> |
| | | /// <returns>相机SN列表</returns> |
| | | public List<string> GetListEnumAll() |
| | | { |
| | | List<string> cameraList = new List<string>(); |
| | | |
| | | try |
| | | { |
| | | // 枚举所有设备 |
| | | IMVDefine.IMV_DeviceList deviceList = new IMVDefine.IMV_DeviceList(); |
| | | IMVDefine.IMV_EInterfaceType interfaceType = IMVDefine.IMV_EInterfaceType.interfaceTypeAll; |
| | | |
| | | int result = MyCamera.IMV_EnumDevices(ref deviceList, (uint)interfaceType); |
| | | |
| | | if (result == IMVDefine.IMV_OK && deviceList.nDevNum > 0) |
| | | { |
| | | for (int i = 0; i < deviceList.nDevNum; i++) |
| | | { |
| | | IMVDefine.IMV_DeviceInfo deviceInfo = (IMVDefine.IMV_DeviceInfo) |
| | | Marshal.PtrToStructure( |
| | | deviceList.pDevInfo + Marshal.SizeOf(typeof(IMVDefine.IMV_DeviceInfo)) * i, |
| | | typeof(IMVDefine.IMV_DeviceInfo)); |
| | | |
| | | string cameraInfo = $"{deviceInfo.cameraName}[{deviceInfo.serialNumber}]"; |
| | | cameraList.Add(cameraInfo); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | // 枚举设备并匹配SN |
| | | List<string> cameraList = GetListEnum(); |
| | | List<string> cameraList = GetListEnumAll(); |
| | | int cameraIndex = -1; |
| | | |
| | | for (int i = 0; i < cameraList.Count; i++) |
| | |
| | | public override bool GetImage(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | bitmap = null; |
| | | |
| | | try |
| | | { |
| | | // 设置超时时间 |
| | |
| | | lock (CallBackImg) |
| | | { |
| | | // 保存旧 Bitmap 并释放 |
| | | bitmap = CallBackImg.Clone() as Bitmap; // 创建副本 |
| | | bitmap = CallBackImg; // 创建副本 |
| | | } |
| | | |
| | | // 释放旧资源 |
| | | CallBackImg.Dispose(); |
| | | CallBackImg = null; |
| | | //// 释放旧资源 |
| | | //CallBackImg.Dispose(); |
| | | //CallBackImg = null; |
| | | return true; |
| | | } |
| | | } |