| | |
| | | } |
| | | |
| | | /// <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); |
| | | } |
| | | } |
| | | 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> |
| | | /// 初始化相机设备 |
| | | /// </summary> |
| | | /// <param name="SN">相机序列号</param> |
| | |
| | | } |
| | | |
| | | // 枚举设备并匹配SN |
| | | List<string> cameraList = GetListEnum(); |
| | | List<string> cameraList = GetListEnumAll(); |
| | | int cameraIndex = -1; |
| | | |
| | | for (int i = 0; i < cameraList.Count; i++) |