HikVision.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //海康相机操作类
  2. using MvCameraControl;
  3. using MvvmScaffoldFrame48.Model.StorageModel.HikVisionCamera;
  4. using System.Collections.Generic;
  5. namespace MvvmScaffoldFrame48.DLL.CameraTools
  6. {
  7. /// <summary>
  8. /// HIKVISION相机类
  9. /// </summary>
  10. public static class HikVision
  11. {
  12. #region 常量
  13. private readonly static DeviceTLayerType enumTLayerType = DeviceTLayerType.MvGigEDevice | DeviceTLayerType.MvUsbDevice
  14. | DeviceTLayerType.MvGenTLGigEDevice | DeviceTLayerType.MvGenTLCXPDevice
  15. | DeviceTLayerType.MvGenTLCameraLinkDevice | DeviceTLayerType.MvGenTLXoFDevice;
  16. #endregion
  17. #region 变量
  18. #endregion
  19. #region 实例
  20. /// <summary>
  21. /// 相机列表
  22. /// </summary>
  23. private static List<IDeviceInfo> CamList;
  24. #endregion
  25. #region 公共方法
  26. /// <summary>
  27. /// 获取相机列表
  28. /// </summary>
  29. /// <param name="CamList"></param>
  30. /// <returns></returns>
  31. public static void GetCameraList(out List<CameraInfoModel> CameraInfoList)
  32. {
  33. CamList = new List<IDeviceInfo>();
  34. CameraInfoList = new List<CameraInfoModel>();
  35. int nRet = DeviceEnumerator.EnumDevices(enumTLayerType, out CamList);
  36. if (nRet != MvError.MV_OK)
  37. {
  38. return;
  39. }
  40. else
  41. {
  42. //输出相机名称及SN码以方便选择设备
  43. foreach (var item in CamList)
  44. {
  45. CameraInfoList.Add(new CameraInfoModel
  46. {
  47. DeviceName = item.ModelName,
  48. DeviceSN = item.SerialNumber,
  49. });
  50. }
  51. }
  52. return;
  53. }
  54. /// <summary>
  55. /// 获取相机列表
  56. /// </summary>
  57. /// <param name="CamList"></param>
  58. /// <returns></returns>
  59. public static void GetCameraList(out List<IDeviceInfo> CameraInfoList)
  60. {
  61. CamList = new List<IDeviceInfo>();
  62. int nRet = DeviceEnumerator.EnumDevices(enumTLayerType, out CamList);
  63. if (nRet != MvError.MV_OK)
  64. {
  65. CameraInfoList = null;
  66. return;
  67. }
  68. else
  69. {
  70. CameraInfoList = CamList;
  71. }
  72. return;
  73. }
  74. /// <summary>
  75. /// 获取相机
  76. /// </summary>
  77. /// <param name="CameraInfo"></param>
  78. /// <param name="CameraSN"></param>
  79. public static void GetCamera(out IDeviceInfo CameraInfo, string CameraSN)
  80. {
  81. if (CamList == null|| CamList.Count == 0)
  82. {
  83. CameraInfo = null;
  84. return;
  85. }
  86. CameraInfo = CamList.Find(x => x.SerialNumber == CameraSN);
  87. }
  88. #endregion
  89. }
  90. }