private static void StartRecvPicture() { IntPtr ptNetPicPara = IntPtr.Zero; try { g_tNetPicPara.iStructLen = Marshal.SizeOf(g_tNetPicPara); g_tNetPicPara.iChannelNo = 0; g_tNetPicPara.cbkPicStreamNotify = MyNETPICSTREAM_NOTIFY; g_tNetPicPara.pvUser = IntPtr.Zero; ptNetPicPara = Marshal.AllocHGlobal(Marshal.SizeOf(g_tNetPicPara)); Marshal.StructureToPtr(g_tNetPicPara, ptNetPicPara, true); int iRet = NVSSDK.NetClient_StartRecvNetPicStream(g_iLogonID, ptNetPicPara, Marshal.SizeOf(g_tNetPicPara), ref g_uiRecvID); if (0 != iRet) { Console.WriteLine("[NetClient_StartRecvNetPicStream] fail!"); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { Marshal.FreeHGlobal(ptNetPicPara); } }
//public bool GetProgress() //{ // if (m_iDLTimeId >= 0) //获取按时间段下载进度 // { // Int32 iPos = 0, iSize = 0; // NVSSDK.NetClient_NetFileGetDownloadPos(m_iDLTimeId, ref iSize, ref iPos); // Int32 iTotal = (Int32)(m_iDLStopTime - m_iDLStartTime); // Int32 iSetPos = (iPos - (Int32)m_iDLStartTime) * 100 / iTotal; // if (iSetPos > 0 && iSetPos <= 100) // { // Progress = iSetPos; // ProgressText = CommonFunc.AbsSecondsToStr(iPos); // return true; // } // else // { // return false; // } // } // else // { // return false; // } //} internal bool Stop() { if (m_iDLTimeId >= 0) { NVSSDK.NetClient_NetFileStopDownloadFile(m_iDLTimeId); m_iDLTimeId = -1; return(true); } else { return(false); } }
private static void StopRecvPicture() { int iRet = NVSSDK.NetClient_StopRecvNetPicStream(g_uiRecvID); if (0 != iRet) { Console.WriteLine("[NetClient_StopRecvNetPicStream] fail!"); } else { g_uiRecvID = CONST_INVALID_RECV_ID; } }
public bool Start() { var structureInfo = tInfo.GetStructure(); IntPtr intptr = Marshal.AllocCoTaskMem(structureInfo.m_iSize); Marshal.StructureToPtr(structureInfo, intptr, true); iRet = NVSSDK.NetClient_NetFileDownload(ref m_iDLTimeId, m_iLogonId, NetSDKCmd.DOWNLOAD_CMD_TIMESPAN, intptr, structureInfo.m_iSize); Marshal.FreeHGlobal(intptr); if (iRet < 0) { MessageBox.Show("Download file failed, ret=!" + iRet); return(false); } m_iDLStartTime = CommonFunc.NvsFileTimeToAbsSeconds(structureInfo.m_tTimeBegin); m_iDLStopTime = CommonFunc.NvsFileTimeToAbsSeconds(structureInfo.m_tTimeEnd); //timerDLTimePos.Enabled = true; //开启定时器获取下载进度 return(true); }
static void Main(string[] args) { int iLogonType = SDKTypes.SERVER_NORMAL; string strTemp; Console.WriteLine("Please input LogonType: 0----Normal 1----Active\n"); strTemp = Console.ReadLine(); iLogonType = Convert.ToInt32(strTemp); //初始化SDK if (SDKTypes.SERVER_ACTIVE == iLogonType) { Console.WriteLine("Please input listening port:"); strTemp = Console.ReadLine(); int iLlisteningPort = Convert.ToInt32(strTemp); NVSSDK.NetClient_Startup_V4(iLlisteningPort, 0, 0); } else { NVSSDK.NetClient_Startup_V4(0, 0, 0); } //设置回调函数 MainNotify_V4 = MyMAIN_NOTIFY_V4; NVSSDK.NetClient_SetNotifyFunction_V4(MainNotify_V4, null, null, null, null); //登录设备 LogonDevice(iLogonType); //创建图片流接收目录 CreateStreamDirectory(); Console.ReadLine(); //停止接收图片流 StopRecvPicture(); //注销用户 NVSSDK.NetClient_Logoff(g_iLogonID); //释放SDK资源 NVSSDK.NetClient_Cleanup(); }
private static void LogonDevice(int _iLogonType) { string strIP; string strUserName; string strPassword; string strProductID; Console.WriteLine("Please input user name: "); strUserName = Console.ReadLine(); Console.WriteLine("Please input password: "******"Please input ProductID: "); strProductID = Console.ReadLine(); tActive = new LogonActiveServer(); tActive.iSize = Marshal.SizeOf(tActive); Array.Copy(Encoding.ASCII.GetBytes(strUserName), tActive.btUserName, strUserName.Length); Array.Copy(Encoding.ASCII.GetBytes(strPassword), tActive.btUserPwd, strPassword.Length); Array.Copy(Encoding.ASCII.GetBytes(strProductID), tActive.btProductID, strProductID.Length); pvPara = Marshal.AllocHGlobal(Marshal.SizeOf(tActive)); Marshal.StructureToPtr(tActive, pvPara, true); iBufLen = Marshal.SizeOf(tActive); DsmOnline tOnline = new DsmOnline(); int length = Marshal.SizeOf(tOnline); Array.Copy(Encoding.ASCII.GetBytes(strProductID), tOnline.btProductID, strProductID.Length); IntPtr ptOnline = IntPtr.Zero; try { ptOnline = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(tOnline, ptOnline, true); NVSSDK.NetClient_GetDsmRegstierInfo(SDKConstMsg.DSM_CMD_GET_ONLINE_STATE, ptOnline, Marshal.SizeOf(tOnline)); int iOutTime = 0; while (SDKTypes.DSM_STATE_ONLINE != tOnline.iOnline) { if (iOutTime >= 20) { Console.WriteLine("Device not register!\n"); break; } Thread.Sleep(1000); NVSSDK.NetClient_GetDsmRegstierInfo(SDKConstMsg.DSM_CMD_GET_ONLINE_STATE, ptOnline, Marshal.SizeOf(tOnline)); iOutTime++; } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { Marshal.FreeHGlobal(ptOnline); } } else { string strCharSet = "UTF-8"; Console.WriteLine("Please input server IP: "); strIP = Console.ReadLine(); tNormal = new LogonPara(); tNormal.iSize = Marshal.SizeOf(tNormal); tNormal.iNvsPort = 3000; Array.Copy(Encoding.ASCII.GetBytes(strIP), tNormal.btNvsIP, strIP.Length); Array.Copy(Encoding.ASCII.GetBytes(strUserName), tNormal.btUserName, strUserName.Length); Array.Copy(Encoding.ASCII.GetBytes(strPassword), tNormal.btUserPwd, strPassword.Length); Array.Copy(Encoding.ASCII.GetBytes(strCharSet), tNormal.btCharSet, strCharSet.Length); iBufLen = Marshal.SizeOf(tNormal); pvPara = Marshal.AllocHGlobal(Marshal.SizeOf(tNormal)); Marshal.StructureToPtr(tNormal, pvPara, true); } g_iLogonID = NVSSDK.NetClient_Logon_V4(_iLogonType, pvPara, iBufLen); if (g_iLogonID < 0) { Console.WriteLine("[NetClient_Logon_V4] fail! " + g_iLogonID + "\n"); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { Marshal.FreeHGlobal(pvPara); } }