/// <summary> /// 获取摄像机上配置的预置点 /// </summary> /// <param name="userHandle"></param> /// <param name="camStation"></param> /// <returns></returns> private IEnumerable <FacilityCameraPresetPointDto> GetCameraPresetPoints(int userHandle, FacilityCameraDto facilityCamera) { try { var cameraPreset = new CHCNetSDK.NET_DVR_GET_PRESET_NAMES(); Int32 dwSize = Marshal.SizeOf(typeof(CHCNetSDK.NET_DVR_GET_PRESET_NAMES)); IntPtr ptrNetCfg = Marshal.AllocHGlobal(dwSize); Marshal.StructureToPtr(cameraPreset, ptrNetCfg, false); UInt32 uiOutBufferSize = 0; bool bGetCfg = false; bGetCfg = CHCNetSDK.NET_DVR_GetDVRConfig(userHandle, 3383, 1, ptrNetCfg, dwSize, ref uiOutBufferSize); if (bGetCfg == false) { var errorCode = CHCNetSDK.NET_DVR_GetLastError(); WriteLog("读取预置点失败 错误码{0}", errorCode); return(Enumerable.Empty <FacilityCameraPresetPointDto>()); } else { WriteLog("读取预置点成功"); } cameraPreset = (CHCNetSDK.NET_DVR_GET_PRESET_NAMES)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_GET_PRESET_NAMES)); //只取前3个 var points = cameraPreset.StructAs.AsEnumerable().Take(5); List <FacilityCameraPresetPointDto> list = new List <FacilityCameraPresetPointDto>(); var netDvrGetPresetNames = points as CHCNetSDK.NET_DVR_GET_PRESET_NAME[] ?? points.ToArray(); for (int i = 0; i < netDvrGetPresetNames.Count(); i++) { var p = netDvrGetPresetNames.ElementAt(i); //var positon = p.wPresetNum; //设备返回的位置,只要不是0,即为处于使用状态 //if (!positon.Equals(0)) //{ var name = Encoding.Default.GetString(p.byName).Trim(); var preset = _facilityCameraPresetPoinService.GetByPointAndId(facilityCamera.Serialnum, i + 1); if (preset == null) { preset = new FacilityCameraPresetPointDto { Serialnum = Guid.NewGuid().ToString(), FacilityCameraSerialnum = facilityCamera.Serialnum, Name = name, PresetPoint = i + 1 }; _facilityCameraPresetPoinService.Add(preset); } else { if (preset.Name.Equals(name)) { preset.Name = name; } _facilityCameraPresetPoinService.Update(preset); } list.Add(preset); //} //else //{ // CameraStationPresetPoint.DeleteByPosition(camStation.Serialnum, i + 1); //} } //释放非托管资源 Marshal.FreeHGlobal(ptrNetCfg); return(list); } catch (Exception ex) { throw; } }
/// <summary> /// 获取摄像机上配置的预置点 /// </summary> /// <param name="userHandle"></param> /// <param name="camStation"></param> /// <returns></returns> private async Task <IEnumerable <CameraStationPresetPointDto> > GetCameraPresetPoints(int userHandle, CameraStationsDto camStation) { var cameraPreset = new CHCNetSDK.NET_DVR_GET_PRESET_NAMES(); Int32 dwSize = Marshal.SizeOf(typeof(CHCNetSDK.NET_DVR_GET_PRESET_NAMES)); IntPtr ptrNetCfg = Marshal.AllocHGlobal(dwSize); Marshal.StructureToPtr(cameraPreset, ptrNetCfg, false); UInt32 uiOutBufferSize = 0; bool bGetCfg = false; bGetCfg = CHCNetSDK.NET_DVR_GetDVRConfig(userHandle, 3383, 1, ptrNetCfg, dwSize, ref uiOutBufferSize); if (bGetCfg == false) { var errorCode = CHCNetSDK.NET_DVR_GetLastError(); LogHelper.Error("读取预置点失败 错误码{0}", errorCode); return(Enumerable.Empty <CameraStationPresetPointDto>()); } else { LogHelper.Debug("读取预置点成功"); } cameraPreset = (CHCNetSDK.NET_DVR_GET_PRESET_NAMES)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_GET_PRESET_NAMES)); //只取前3个 var points = cameraPreset.StructAs.AsEnumerable().Take(5); List <CameraStationPresetPointDto> list = new List <CameraStationPresetPointDto>(); for (int i = 0; i < points.Count(); i++) { var p = points.ElementAt(i); //var positon = p.wPresetNum; //设备返回的位置,只要不是0,即为处于使用状态 //if (!positon.Equals(0)) //{ var name = Encoding.Default.GetString(p.byName).Trim(); var preset = await _cameraStationPresetPointService.GetByPointAndIdAsny(camStation.Serialnum, i + 1); if (preset == null) { preset = new CameraStationPresetPointDto(); preset.Serialnum = Guid.NewGuid().ToString(); preset.CameraStationsSerialnum = camStation.Serialnum; preset.Name = name; preset.PresetPoint = i + 1; await _cameraStationPresetPointService.AddAsny(preset); } else { if (preset.Name.Equals(name)) { preset.Name = name; } await _cameraStationPresetPointService.UpdateAsny(preset); } list.Add(preset); //} //else //{ // CameraStationPresetPoint.DeleteByPosition(camStation.Serialnum, i + 1); //} } //释放非托管资源 Marshal.FreeHGlobal(ptrNetCfg); return(list); }