public void ConvertToNetTimeTest() { DateTime tim = DateTime.Now; NET_DVR_TIME t1 = SDK_HikClientSDK.ConvertToNetTime(tim); DateTime tim2 = ConvertToDateTime(t1); Assert.AreEqual(tim.ToString("yyyyMMddHHmmss"), tim2.ToString("yyyyMMddHHmmss")); }
private void btnFind_Click(object sender, EventArgs e) { if (comboBox1.Text.Contains("通道")) { MessageBox.Show("请选择通道号再进行查询!"); return; } NET_DVR_TIME Stime = new NET_DVR_TIME(); Stime.dwYear = uint.Parse(dateTimePicker1.Value.Year.ToString()); Stime.dwMonth = uint.Parse(dateTimePicker1.Value.Month.ToString()); Stime.dwDay = uint.Parse(dateTimePicker1.Value.Day.ToString()); Stime.dwHour = uint.Parse(dateTimePicker2.Value.Hour.ToString()); Stime.dwMinute = uint.Parse(dateTimePicker2.Value.Minute.ToString()); Stime.dwSecond = uint.Parse(dateTimePicker2.Value.Second.ToString()); NET_DVR_TIME Etime = new NET_DVR_TIME(); Etime.dwYear = uint.Parse(dateTimePicker3.Value.Year.ToString()); Etime.dwMonth = uint.Parse(dateTimePicker3.Value.Month.ToString()); Etime.dwDay = uint.Parse(dateTimePicker3.Value.Day.ToString()); Etime.dwHour = uint.Parse(dateTimePicker4.Value.Hour.ToString()); Etime.dwMinute = uint.Parse(dateTimePicker4.Value.Minute.ToString()); Etime.dwSecond = uint.Parse(dateTimePicker4.Value.Second.ToString()); iFindfileHandle = NET_DVR_FindFile(m_lUserID, Convert.ToInt32(comboBox1.Text), 0xff, ref Stime, ref Etime); if (iFindfileHandle == -1) { MessageBox.Show("没有电子标签录像文件,请注意"); return; } else { lvFlieList.Items.Clear(); } NET_DVR_FIND_DATA FindNextFile = new NET_DVR_FIND_DATA(); Label_017C: switch (NET_DVR_FindNextFile(this.iFindfileHandle, ref FindNextFile)) { case 1000: { string[] str = { FindNextFile.sFileName.ToString() + ".mp4", FindNextFile.dwFileSize.ToString() + "MB" }; AddListViewItem(lvFlieList, str, Color.Black, Color.White); goto Label_017C; } case 1002: System.Threading.Thread.Sleep(5); goto Label_017C; } NET_DVR_FindClose(this.iFindfileHandle); }
/// <summary> /// 设置设备时间 /// </summary> /// <param name="userId">登陆设备时的用户ID</param> /// <param name="time">时间</param> /// <returns>成功返回true,否则失败</returns> public static bool SetDeviceDate(int userId, DateTime time) { NET_DVR_TIME deviceTime = new NET_DVR_TIME { dwDay = (uint)time.Day, dwHour = (uint)time.Hour, dwMinute = (uint)time.Minute, dwSecond = (uint)time.Second, dwMonth = (uint)time.Month, dwYear = (uint)time.Year }; uint dwSize = (uint)Marshal.SizeOf(deviceTime); IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(deviceTime, ptrIpParaCfgV40, false); return(HikApi.NET_DVR_SetDVRConfig(userId, (uint)DwCommand.NET_DVR_SET_TIMECFG, 0, ptrIpParaCfgV40, dwSize)); }
public static NET_DVR_TIME DateTimeToHCDeviceTime(DateTime dateTime) { NET_DVR_TIME hcDevTime = new NET_DVR_TIME(); hcDevTime.dwYear = (uint)dateTime.Year; hcDevTime.dwMonth = (uint)dateTime.Month; hcDevTime.dwDay = (uint)dateTime.Day; hcDevTime.dwHour = (uint)dateTime.Hour; hcDevTime.dwMinute = (uint)dateTime.Minute; hcDevTime.dwSecond = (uint)dateTime.Second; return(hcDevTime); }
/// <summary> /// 获取设备时间 /// </summary> /// <param name="userId">用户ID</param> /// <returns>返回设备时间字符串</returns> /// <remarks>获取失败返回空</remarks> public static string GetDeviceTime(int userId) { NET_DVR_TIME deviceTime = new NET_DVR_TIME(); uint dwSize = (uint)Marshal.SizeOf(deviceTime); IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(deviceTime, ptrIpParaCfgV40, false); uint dwReturn = 0; bool b = HikApi.NET_DVR_GetDVRConfig(userId, (uint)DwCommand.NET_DVR_GET_TIMECFG, 0, ptrIpParaCfgV40, dwSize, ref dwReturn); if (b) { deviceTime = (NET_DVR_TIME)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(NET_DVR_TIME)); return(string.Format("{0}-{1}-{2} {3}:{4}:{5}", deviceTime.dwYear, deviceTime.dwMonth, deviceTime.dwDay, deviceTime.dwHour, deviceTime.dwMinute, deviceTime.dwSecond)); } else { return(""); } }
public static extern int NET_DVR_FindFile(int lUserID, int lChannel, uint dwFileType, ref NET_DVR_TIME lpStartTime, ref NET_DVR_TIME lpStopTime);
public static extern int NET_DVR_PlayBackByTime(int lUserID, int lChannel, ref NET_DVR_TIME lpStartTime, ref NET_DVR_TIME lpStopTime, IntPtr hWnd);
public static extern bool NET_DVR_GetPlayBackOsdTime(int lPlayHandle, out NET_DVR_TIME lpOsdTime);
public static extern int NET_DVR_PlayBackByTime(int lUserID, int lChannel, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime, IntPtr hWnd);
public static extern int NET_DVR_FindFile_Card(int lUserID, int lChannel, uint dwFileType, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime);
public static extern int NET_DVR_GetFileByTime(int lUserID, int lChannel, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime, string sSavedFileName);
public static extern int NET_DVR_FindDVRLog_V30(int lUserID, int lSelectMode, uint dwMajorType, uint dwMinorType, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime, bool bOnlySmart);
private void M_oPlaybackBtn_Click(object sender, EventArgs e) { try { if (m_iLogID < 0) { Log.Error("EYESON APP", "please login on a device first"); ShowFancyMessage(GetApplicationContext(), "Please login first", Color: Resource.Color.error_color_material_light); return; } if (m_iPlaybackID < 0) { if (m_iPlayID >= 0) { Log.Info("EYESON APP", "Please stop preview first"); ShowFancyMessage(GetApplicationContext(), "Please stop Preview function first", Color: Resource.Color.error_color_material_light); return; } ChangeSingleSurFace(true); NET_DVR_TIME struBegin = new NET_DVR_TIME(); NET_DVR_TIME struEnd = new NET_DVR_TIME(); struBegin.DwYear = Year; struBegin.DwMonth = Month; struBegin.DwDay = Day; struBegin.DwHour = Hour; struBegin.DwMinute = Minute; struBegin.DwSecond = 00; struEnd.DwYear = System.DateTime.UtcNow.Year; struEnd.DwMonth = System.DateTime.UtcNow.Month; struEnd.DwDay = System.DateTime.UtcNow.Day; struEnd.DwHour = System.DateTime.Now.Hour; struEnd.DwMinute = System.DateTime.UtcNow.Minute; struEnd.DwSecond = System.DateTime.UtcNow.Second; NET_DVR_VOD_PARA struVod = new NET_DVR_VOD_PARA(); struVod.StruBeginTime = struBegin; struVod.StruEndTime = struEnd; struVod.ByStreamType = 0; struVod.StruIDInfo.DwChannel = m_iStartChan == 0 ? Integer.ParseInt(m_oCam.Text.ToString()) - 1 : Integer.ParseInt(m_oCam.Text.ToString()) - 1;// getM_iStartChan(); //m_iStartChan; struVod.HWnd = playView[0].Holder.Surface; m_iPlaybackID = HCNetSDK.Instance.NET_DVR_PlayBackByTime_V40(m_iLogID, struVod); if (m_iPlaybackID >= 0) { NET_DVR_PLAYBACK_INFO struPlaybackInfo = null; if (!HCNetSDK.Instance.NET_DVR_PlayBackControl_V40(m_iPlaybackID, PlaybackControlCommand.NetDvrPlaystart, null, 0, struPlaybackInfo)) { Log.Error("EYESON APP", "net sdk playback start failed!"); ShowFancyMessage(GetApplicationContext(), "NET_SDK_Playback start failed, try again."); return; } m_bStopPlayback = false; m_oPlaybackBtn.Text = "Stop"; new System.Threading.Thread(new ThreadStart(() => { int nProgress = -1; while (true) { nProgress = HCNetSDK.Instance.NET_DVR_GetPlayBackPos(m_iPlaybackID); System.Console.WriteLine("NET_DVR_GetPlayBackPos:" + nProgress); if (nProgress < 0 || nProgress >= 100) { break; } try { System.Threading.Thread.Sleep(1000); } catch (InterruptedException er) { // TODO Auto-generated catch block er.PrintStackTrace(); } } })).Start(); } else { Log.Info("EYESON APP", "NET_DVR_PlayBackByTime failed, error code: " + HCNetSDK.Instance.NET_DVR_GetLastError()); var code = HCNetSDK.Instance.NET_DVR_GetLastError(); var msg = code == 10 ? "Connection Time out, try again" : ""; ShowFancyMessage(GetApplicationContext(), "NET_DVR_PlayBackByTime failed, error code: " + code, message: msg, Color: Resource.Color.error_color_material_light, Duration: 3000); } } else { m_bStopPlayback = true; if (!HCNetSDK.Instance.NET_DVR_StopPlayBack(m_iPlaybackID)) { Log.Error("EYESON APP", "net sdk stop playback failed"); ShowFancyMessage(GetApplicationContext(), "NET_SDK_Playback failed", Color: Resource.Color.error_color_material_light, Duration: 23000); } m_oPlaybackBtn.Text = "Playback"; m_iPlaybackID = -1; } } catch (System.Exception er) { Log.Error("EYESON APP", "Error: " + er.StackTrace); ShowFancyMessage(GetApplicationContext(), "Please login first", message: "Fatal error: " + er.StackTrace, Color: Resource.Color.error_color_material_light); } }
public void NET_DVR_FindPictureTest() { PublicClassCurrency.VideoInfo vInfo = TestDataSource.HikDataSource.GetHikData2(); SDK_HikClientSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new SDK_HikClientSDK.NET_DVR_DEVICEINFO_V30(); //登录设备 int m_lUserID = SDK_HikClientSDK.NET_DVR_Login_V30(vInfo.DVSAddress, vInfo.DVSConnectPort, vInfo.UserName, vInfo.Password, ref DeviceInfo); NET_DVR_FIND_PICTURE_PARAM para = new NET_DVR_FIND_PICTURE_PARAM(); para.dwSize = (uint)Marshal.SizeOf(para); para.lChannel = 1; para.byFileType = 0; DateTime tim = DateTime.Parse("2018-05-30 21:41:30"); //DateTime timStart = DateTime.Now.AddSeconds(-70); DateTime timStart = tim.AddSeconds(-70); SDK_HikClientSDK.NET_DVR_TIME Stime = new SDK_HikClientSDK.NET_DVR_TIME(); Stime.dwYear = uint.Parse(timStart.Year.ToString()); Stime.dwMonth = uint.Parse(timStart.Month.ToString()); Stime.dwDay = uint.Parse(timStart.Day.ToString()); Stime.dwHour = uint.Parse(timStart.Hour.ToString()); Stime.dwMinute = uint.Parse(timStart.Minute.ToString()); Stime.dwSecond = uint.Parse(timStart.Second.ToString()); para.struStartTime = Stime; //DateTime timEnd = DateTime.Now.AddSeconds(-60); DateTime timEnd = tim.AddSeconds(-60); SDK_HikClientSDK.NET_DVR_TIME Etime = new SDK_HikClientSDK.NET_DVR_TIME(); Etime.dwYear = uint.Parse(timEnd.Year.ToString()); Etime.dwMonth = uint.Parse(timEnd.Month.ToString()); Etime.dwDay = uint.Parse(timEnd.Day.ToString()); Etime.dwHour = uint.Parse(timEnd.Hour.ToString()); Etime.dwMinute = uint.Parse(timEnd.Minute.ToString()); Etime.dwSecond = uint.Parse(timEnd.Second.ToString()); para.struStopTime = Etime; int lFindHandle = SDK_HikClientSDK.NET_DVR_FindPicture(m_lUserID, ref para); NET_DVR_FIND_PICTURE lpFindData = new NET_DVR_FIND_PICTURE(); bool bolEnd = false; string strPath = @"C:\SHIKE_Video\9999\Pic"; int Temp_intCount = 1; DateTime Temp_tim = DateTime.Now.AddYears(-10); while (!bolEnd) { long lResult = NET_DVR_FindNextPicture(lFindHandle, ref lpFindData); switch (lResult) { case 1000: //下载图片 NET_DVR_TIME t = lpFindData.struTime; StringBuilder sb = new StringBuilder(); DateTime timPic = ConvertToDateTime(lpFindData.struTime); if (Temp_tim == timPic) { Temp_intCount++; } else { Temp_tim = timPic; Temp_intCount = 1; } string strFileName = lpFindData.sFileName; sb.Append(timPic.ToString("yyyyMMddHHmmss") + "_" + Temp_intCount + "_"); sb.Append(strFileName.Substring(0, strFileName.IndexOf("_"))); string strFilePath = strPath + "\\" + sb.ToString() + ".jpg"; NET_DVR_GetPicture(m_lUserID, lpFindData.sFileName, strFilePath); Thread.Sleep(30); break; case 1002: Thread.Sleep(30); break; case 1001: //未查找到 case 1003: //查找结束 case 1004: //查找文件异常 bolEnd = true; NET_DVR_CloseFindPicture(lFindHandle); break; } } //Thread.Sleep(5000); Assert.Fail(); }
public static DateTime ToDateTime(this NET_DVR_TIME devTime) { return(HCDeviceTimeToDateTime(devTime)); }
public static DateTime HCDeviceTimeToDateTime(NET_DVR_TIME devTime) { return(new DateTime((int)devTime.dwYear, (int)devTime.dwMonth, (int)devTime.dwDay, (int)devTime.dwHour, (int)devTime.dwMinute, (int)devTime.dwSecond)); }
public static extern int NET_DVR_GetFileByTime(int lUserID, int lChannel, ref NET_DVR_TIME lpStartTime, ref NET_DVR_TIME lpStopTime, string sSavedFileName);
public static extern bool NET_DVR_GetPlayBackOsdTime(int lPlayHandle, ref NET_DVR_TIME lpOsdTime);
private void FrmRecordPlay_Load(object sender, EventArgs e) { VideoInfo v = TestDataSource.HikDataSource.GetHikData1(); CheckForIllegalCrossThreadCalls = false; bool bolResult = NET_DVR_Init();//初始化SDK NET_DVR_DEVICEINFO_V30 DeviceInfo = new NET_DVR_DEVICEINFO_V30(); //登录设备 m_lUserID = NET_DVR_Login_V30(v.DVSAddress, v.DVSConnectPort, v.UserName, v.Password, ref DeviceInfo); if (m_lUserID < 0) { //int iError=NET_DVR_GetLastError();//错误返回值 MessageBox.Show("设备登录失败,请检查网络或者参数是否错误!"); return; } sTime = DateTime.Now.AddDays(-1); NET_DVR_TIME Stime = new NET_DVR_TIME(); Stime.dwYear = uint.Parse(sTime.Year.ToString()); Stime.dwMonth = uint.Parse(sTime.Month.ToString()); Stime.dwDay = uint.Parse(sTime.Day.ToString()); Stime.dwHour = uint.Parse(sTime.Hour.ToString()); Stime.dwMinute = uint.Parse(sTime.Minute.ToString()); Stime.dwSecond = uint.Parse(sTime.Second.ToString()); eTime = DateTime.Now.AddDays(1); NET_DVR_TIME Etime = new NET_DVR_TIME(); Etime.dwYear = uint.Parse(eTime.Year.ToString()); Etime.dwMonth = uint.Parse(eTime.Month.ToString()); Etime.dwDay = uint.Parse(eTime.Day.ToString()); Etime.dwHour = uint.Parse(eTime.Hour.ToString()); Etime.dwMinute = uint.Parse(eTime.Minute.ToString()); Etime.dwSecond = uint.Parse(eTime.Second.ToString()); iFindfileHandle = NET_DVR_FindFile(m_lUserID, _iChannel, 0xff, ref Stime, ref Etime); if (iFindfileHandle == -1) { MessageBox.Show("没有电子标签录像文件,请注意"); return; } else { } NET_DVR_FIND_DATA FindNextFile = new NET_DVR_FIND_DATA(); Label_017C: switch (NET_DVR_FindNextFile(this.iFindfileHandle, ref FindNextFile)) { case 1000: { string[] str = { FindNextFile.sFileName.ToString() + ".mp4", FindNextFile.dwFileSize.ToString() + "MB" }; AddListViewItem(lvFlieList, str, Color.Black, Color.White); goto Label_017C; } case 1002: System.Threading.Thread.Sleep(5); goto Label_017C; } NET_DVR_FindClose(this.iFindfileHandle); m_lPlayHandle = NET_DVR_PlayBackByTime(m_lUserID, _iChannel, ref Stime, ref Etime, pBPlay.Handle); if (m_lPlayHandle == -1) { MessageBox.Show("录像文件回放失败!"); } int lpOutValue = -1; // 录像文件播放 if (!NET_DVR_PlayBackControl(m_lPlayHandle, 1, 0, ref lpOutValue)) { MessageBox.Show("文件播放失败!"); } // 返回文件的总时间 //NET_DVR_PlayBackControl(m_lPlayHandle, 17, 0, ref totalTime); _bytime = true; }
public static extern int NET_DVR_FindFileByCard(int lUserID, int lChannel, uint dwFileType, int nFindType, byte[] sCardNumber, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime);
public static extern int NET_DVR_FindDVRLog(int lUserID, int lSelectMode, uint dwMajorType, uint dwMinorType, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime);
public static extern int NET_DVR_FindDVRLog_Matrix(int iUserID, int lSelectMode, uint dwMajorType, uint dwMinorType, ref tagVEDIOPLATLOG lpVedioPlatLog, ref NET_DVR_TIME lpStartTime, ref NET_DVR_TIME lpStopTime);