コード例 #1
0
ファイル: ucVideo.cs プロジェクト: Jinyuancheng/ReplayAx
 /// <summary>
 /// 海康主机登录
 /// </summary>
 public void HikHostLogin()
 {
     if (m_lstLoginInfo.Count > 0)
     {
         for (int i = 0; i < m_lstLoginInfo.Count; i++)
         {
             if (m_lstLoginInfo[i].iHandle == -1)
             {
                 NET_DVR_USER_LOGIN_INFO struLoginInfo = new NET_DVR_USER_LOGIN_INFO();
                 NET_DVR_DEVICEINFO_V40  devInfor      = new NET_DVR_DEVICEINFO_V40();
                 devInfor.byRes2 = new byte[246];
                 devInfor.struDeviceV30.sSerialNumber = new byte[48];
                 devInfor.byRes2 = new byte[246];
                 devInfor.struDeviceV30.sSerialNumber = new byte[48];
                 struLoginInfo.sDeviceAddress         = m_lstLoginInfo[i].sStreamIp;
                 struLoginInfo.wPort         = Convert.ToUInt16(m_lstLoginInfo[i].sPort); //设备服务端口
                 struLoginInfo.sUserName     = m_lstLoginInfo[i].sUser;                   //设备登录用户名
                 struLoginInfo.sPassword     = m_lstLoginInfo[i].sPass;                   //设备登录密码
                 struLoginInfo.bUseAsynLogin = false;                                     //同步登录方式(异步现在设备不在线时会报错,不知道啥原因)
                 struLoginInfo.byLoginMode   = 0;
                 struLoginInfo.byHttps       = 2;
                 //m_lstLoginInfo[i].iHandle = HikVideoAPI.NET_HIK_Login_V40(ref struLoginInfo, ref devInfor);
                 m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref devInfor);
                 //失败
                 if (m_lstLoginInfo[i].iHandle < 0)
                 {
                     CHCNetSDK.NET_DVR_Logout(m_lstLoginInfo[i].iHandle);
                     CHCNetSDK.NET_DVR_Cleanup();
                     return;
                 }
                 else
                 {
                     //存储数据用来计算通道号
                     NET_DVR_IPPARACFG_V40 oIpParaCfgV40 = new NET_DVR_IPPARACFG_V40();
                     uint   dwSize          = (uint)Marshal.SizeOf(oIpParaCfgV40);
                     IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);
                     Marshal.StructureToPtr(oIpParaCfgV40, ptrIpParaCfgV40, false);
                     uint dwReturn = 0;
                     //int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取
                     for (int iGroupNo = 0; iGroupNo < 4; iGroupNo++)
                     {
                         if (CHCNetSDK.NET_DVR_GetDVRConfig(m_lstLoginInfo[i].iHandle, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
                         {
                             oIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                             m_lstStruIpParaCfgV40.Add(oIpParaCfgV40);
                         }
                     }
                 }
                 //第二种登录
                 //CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                 //m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V30(m_lstLoginInfo[i].sIp, Convert.ToInt32(m_lstLoginInfo[i].sPort),
                 //    m_lstLoginInfo[i].sUser, m_lstLoginInfo[i].sPass, ref DeviceInfo);
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// 使用线程登录
 /// </summary>
 public void ThreadLogin()
 {
     //string file = "G:\\天津白泽技术有限公司项目\\天津白泽技术项目源文件等\\CentralEcoCity\\bin\\HCNetSDK.dll";
     //InitHikVideoSDK(m_iHCNetDllPath);
     Thread.Sleep(2000);
     while (true)
     {
         lock (m_oSingleLock)
         {
             if (m_lstLoginInfo.Count > 0)
             {
                 for (int i = 0; i < m_lstLoginInfo.Count; i++)
                 {
                     if (m_lstLoginInfo[i].iHandle == -1)
                     {
                         NET_DVR_USER_LOGIN_INFO struLoginInfo = new NET_DVR_USER_LOGIN_INFO();
                         NET_DVR_DEVICEINFO_V40  devInfor      = new NET_DVR_DEVICEINFO_V40();
                         devInfor.byRes2 = new byte[246];
                         devInfor.struDeviceV30.sSerialNumber = new byte[48];
                         devInfor.byRes2 = new byte[246];
                         devInfor.struDeviceV30.sSerialNumber = new byte[48];
                         struLoginInfo.sDeviceAddress         = m_lstLoginInfo[i].sIp;
                         struLoginInfo.wPort         = Convert.ToUInt16(m_lstLoginInfo[i].sPort); //设备服务端口
                         struLoginInfo.sUserName     = m_lstLoginInfo[i].sUser;                   //设备登录用户名
                         struLoginInfo.sPassword     = m_lstLoginInfo[i].sPass;                   //设备登录密码
                         struLoginInfo.bUseAsynLogin = false;                                     //同步登录方式(异步现在设备不在线时会报错,不知道啥原因)
                         struLoginInfo.byLoginMode   = 0;
                         //struLoginInfo.byHttps = 2;
                         //m_lstLoginInfo[i].iHandle = HikVideoAPI.NET_HIK_Login_V40(ref struLoginInfo, ref devInfor);
                         m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref devInfor);
                         //将通道信息和对应的ip存储到list集合中
                         if (m_lstLoginInfo[i].iHandle >= 0)
                         {
                             NET_DVR_IPPARACFG_V40 oIpParaCfgV40 = new NET_DVR_IPPARACFG_V40();
                             uint   dwSize          = (uint)Marshal.SizeOf(oIpParaCfgV40);
                             IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);
                             Marshal.StructureToPtr(oIpParaCfgV40, ptrIpParaCfgV40, false);
                             uint dwReturn = 0;
                             //int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取
                             for (int iGroupNo = 0; iGroupNo < 4; iGroupNo++)
                             {
                                 if (CHCNetSDK.NET_DVR_GetDVRConfig(m_lstLoginInfo[i].iHandle, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
                                 {
                                     oIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                                     m_lstStruIpParaCfgV40.Add(oIpParaCfgV40);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
        public void HikDVR_VideoPlay2()
        {
            fLoginResultCallBack    f          = new fLoginResultCallBack(LoginResultCallBack);
            NET_DVR_USER_LOGIN_INFO pLoginInfo = new NET_DVR_USER_LOGIN_INFO();

            pLoginInfo.sDeviceAddress = "192.168.5.162";
            pLoginInfo.byRes1         = 0x00;
            pLoginInfo.wPort          = 8000;
            pLoginInfo.sUserName      = "******";
            pLoginInfo.sPassword      = "******";
            pLoginInfo.cbLoginResult  = f;
            pLoginInfo.pUser          = IntPtr.Zero;
            pLoginInfo.bUseAsynLogin  = false;
            pLoginInfo.byRes2         = new byte[128];
            NET_DVR_DEVICEINFO_V40 lpDeviceInfo = new NET_DVR_DEVICEINFO_V40();

            _intDVRHwd = NET_DVR_Login_V40(ref pLoginInfo, ref lpDeviceInfo);
        }
コード例 #4
0
 public static extern int NET_DVR_Login_V40(ref NET_DVR_USER_LOGIN_INFO pLoginInfo, ref NET_DVR_DEVICEINFO_V40 lpDeviceInfo);
コード例 #5
0
        /// <summary>
        /// 使用线程登录(使用)
        /// </summary>
        public void ThreadLogin()
        {
            int iDelay = 0;/*\ 延迟 /*/

            while (!m_bTerminated)
            {
                if (m_lstLoginInfo.Count == 0)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    iDelay = 0;
                    if (m_lstLoginInfo.Count > 0)
                    {
                        for (int i = 0; i < m_lstLoginInfo.Count; i++)
                        {
                            if (m_lstLoginInfo[i].iHandle == -1)
                            {
                                NET_DVR_USER_LOGIN_INFO struLoginInfo = new NET_DVR_USER_LOGIN_INFO();
                                NET_DVR_DEVICEINFO_V40  devInfor      = new NET_DVR_DEVICEINFO_V40();
                                devInfor.byRes2 = new byte[246];
                                devInfor.struDeviceV30.sSerialNumber = new byte[48];
                                devInfor.byRes2 = new byte[246];
                                devInfor.struDeviceV30.sSerialNumber = new byte[48];
                                struLoginInfo.sDeviceAddress         = m_lstLoginInfo[i].sIp;
                                struLoginInfo.wPort         = Convert.ToUInt16(m_lstLoginInfo[i].sPort); //设备服务端口
                                struLoginInfo.sUserName     = m_lstLoginInfo[i].sUser;                   //设备登录用户名
                                struLoginInfo.sPassword     = m_lstLoginInfo[i].sPass;                   //设备登录密码
                                struLoginInfo.bUseAsynLogin = false;                                     //同步登录方式(异步现在设备不在线时会报错,不知道啥原因)
                                struLoginInfo.byLoginMode   = 0;
                                //struLoginInfo.byHttps = 2;
                                //m_lstLoginInfo[i].iHandle = HikVideoAPI.NET_HIK_Login_V40(ref struLoginInfo, ref devInfor);
                                m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref devInfor);
                                //将通道信息和对应的ip存储到list集合中
                                if (m_lstLoginInfo[i].iHandle >= 0)
                                {
                                    CSaveHikChannelInfo oSaveHikChannelInfo = new CSaveHikChannelInfo();
                                    oSaveHikChannelInfo.m_lstHikChannelInfo = new List <NET_DVR_IPPARACFG_V40>();
                                    oSaveHikChannelInfo.m_sStreamIp         = m_lstLoginInfo[i].sIp;
                                    NET_DVR_IPPARACFG_V40 oIpParaCfgV40 = new NET_DVR_IPPARACFG_V40();
                                    uint   dwSize          = (uint)Marshal.SizeOf(oIpParaCfgV40);
                                    IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);
                                    Marshal.StructureToPtr(oIpParaCfgV40, ptrIpParaCfgV40, false);
                                    uint dwReturn = 0;
                                    //int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取
                                    /*\ 共16组每组64个 /*/
                                    for (int iGroupNo = 0; iGroupNo < 15; iGroupNo++)
                                    {
                                        if (CHCNetSDK.NET_DVR_GetDVRConfig(m_lstLoginInfo[i].iHandle, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
                                        {
                                            lock (m_oSingleLock)
                                            {
                                                oIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                                                oSaveHikChannelInfo.m_lstHikChannelInfo.Add(oIpParaCfgV40);
                                                m_lstSaveHikChannelInfo.Add(oSaveHikChannelInfo);
                                            }
                                        }
                                    }
                                    Marshal.FreeHGlobal(ptrIpParaCfgV40);
                                }
                            }
                        }
                        while (!m_bTerminated)
                        {
                            iDelay++;
                            Thread.Sleep(1000);
                            if (iDelay > 10)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: HikOperate.cs プロジェクト: radtek/HikDeviceApi
 /// <summary>
 /// 登录设备
 /// </summary>
 /// <param name="deviceIp">设备IP</param>
 /// <param name="userName">用户名</param>
 /// <param name="userPwd">用户密码</param>
 /// <param name="deviceInfo">设备参数结构体(输出)</param>
 /// <param name="userId">用户ID(输出)</param>
 /// <param name="port">通讯端口</param>
 /// <returns>成功返回true,否则失败</returns>
 public static bool LoginBySynLogin_V40(string deviceIp, string userName, string userPwd, ref NET_DVR_DEVICEINFO_V40 deviceInfo, ref int userId, uint port = 8000)
 {
     try
     {
         NET_DVR_USER_LOGIN_INFO loginInfo = new NET_DVR_USER_LOGIN_INFO();
         loginInfo.bUseAsynLogin  = false;
         loginInfo.sUserName      = userName;
         loginInfo.sPassword      = userPwd;
         loginInfo.wPort          = port;
         loginInfo.pUser          = IntPtr.Zero;
         loginInfo.sDeviceAddress = deviceIp;
         int x = HikApi.NET_DVR_Login_V40(loginInfo, ref deviceInfo);
         if (x == -1)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception) { return(false); }
 }