Esempio n. 1
0
        /// <summary>
        /// Prisijungimas prie įeigos kontrolės įrenginio.
        /// </summary>
        /// <returns>Įeigos kontrolės įrenginio naudotojo ID. -1 jeigu nepavyko prisijungti prie įrenginio.</returns>
        public static int AccessControllerLogin()
        {
            Settings _settings = SettingsController.GetSettings();

            if (CHCNetSDK.NET_DVR_Init() == false)
            {
                return(-1);
            }
            CHCNetSDK.NET_DVR_SetLogToFile(3, "./", false);

            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            struLoginInfo.sDeviceAddress = _settings.AccessControllerIP;
            struLoginInfo.sUserName      = _settings.AccessControllerUsername;
            struLoginInfo.sPassword      = _settings.AccessControllerPassword;
            ushort.TryParse(_settings.AccessControllerPort.ToString(), out struLoginInfo.wPort);

            int lUserID = -1;

            lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
            if (lUserID >= 0)
            {
                return(lUserID);
            }
            return(-1);
        }
Esempio n. 2
0
        public uint Login()
        {
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            struLoginInfo.bUseAsynLogin  = false;
            struLoginInfo.sDeviceAddress = DeviceIP;
            struLoginInfo.sUserName      = LoginUsername;
            struLoginInfo.sPassword      = LoginPassword;
            struLoginInfo.wPort          = Port;

            UserID_ = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);

            uint errorCode = 0;

            if (UserID_ >= 0)
            {
                errorCode = 0;
                Console.WriteLine("Login Successul");
            }
            else
            {
                errorCode = CHCNetSDK.NET_DVR_GetLastError();
                Console.WriteLine("Login failed. Error: " + errorCode);
            }

            return(errorCode);
        }
Esempio n. 3
0
        public string AddPerson(string IpAddress, string UserName, string Password, ushort Port, dynamic userInfo)
        {
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO nET_DVR_USER_LOGIN_INFO = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();

            nET_DVR_USER_LOGIN_INFO.sDeviceAddress = IpAddress;
            nET_DVR_USER_LOGIN_INFO.wPort          = Port;
            nET_DVR_USER_LOGIN_INFO.sUserName      = UserName;
            nET_DVR_USER_LOGIN_INFO.sPassword      = Password;
            nET_DVR_USER_LOGIN_INFO.bUseAsynLogin  = false;

            CHCNetSDK.NET_DVR_DEVICEINFO_V40 nET_DVR_DEVICEINFO_V40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            nET_DVR_DEVICEINFO_V40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            int userID = CHCNetSDK.NET_DVR_Login_V40(ref nET_DVR_USER_LOGIN_INFO, ref nET_DVR_DEVICEINFO_V40);

            string url = "PUT /ISAPI/AccessControl/UserInfo/SetUp?format=json";

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT nET_DVR_XML_CONFIG_INPUT = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();
            Int32 nInSize = Marshal.SizeOf(nET_DVR_XML_CONFIG_INPUT);

            nET_DVR_XML_CONFIG_INPUT.dwSize          = (uint)Marshal.SizeOf(nET_DVR_XML_CONFIG_INPUT);
            nET_DVR_XML_CONFIG_INPUT.lpRequestUrl    = Marshal.StringToHGlobalAnsi(url);
            nET_DVR_XML_CONFIG_INPUT.dwRequestUrlLen = (uint)url.Length;

            var json    = new { UserInfo = userInfo };
            var strJson = JsonConvert.SerializeObject(json);

            nET_DVR_XML_CONFIG_INPUT.lpInBuffer     = Marshal.StringToHGlobalAnsi(strJson);
            nET_DVR_XML_CONFIG_INPUT.dwInBufferSize = (uint)strJson.Length;

            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT nET_DVR_XML_CONFIG_OUTPUT = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
            nET_DVR_XML_CONFIG_OUTPUT.dwSize          = (uint)Marshal.SizeOf(nET_DVR_XML_CONFIG_INPUT);
            nET_DVR_XML_CONFIG_OUTPUT.lpOutBuffer     = Marshal.AllocHGlobal(3 * 1024 * 1024);
            nET_DVR_XML_CONFIG_OUTPUT.dwOutBufferSize = 3 * 1024 * 1024;
            nET_DVR_XML_CONFIG_OUTPUT.lpStatusBuffer  = Marshal.AllocHGlobal(4096 * 4);
            nET_DVR_XML_CONFIG_OUTPUT.dwStatusSize    = 4096 * 4;

            if (!NET_DVR_STDXMLConfig(userID, ref nET_DVR_XML_CONFIG_INPUT, ref nET_DVR_XML_CONFIG_OUTPUT))
            {
                uint   getLastError = CHCNetSDK.NET_DVR_GetLastError();
                string errorStr     = "NET_DVR_STDXMLConfig failed :" + getLastError;
                Console.WriteLine(errorStr);
            }


            string result = Marshal.PtrToStringAnsi(nET_DVR_XML_CONFIG_OUTPUT.lpOutBuffer);
            string outXML = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(result));

            Console.WriteLine(outXML);
            string outStatus = Marshal.PtrToStringAnsi(nET_DVR_XML_CONFIG_OUTPUT.lpStatusBuffer);

            Console.WriteLine("Status Output:\n" + outStatus);


            Marshal.FreeHGlobal(nET_DVR_XML_CONFIG_INPUT.lpRequestUrl);
            Marshal.FreeHGlobal(nET_DVR_XML_CONFIG_OUTPUT.lpOutBuffer);
            Marshal.FreeHGlobal(nET_DVR_XML_CONFIG_OUTPUT.lpStatusBuffer);
            return("ok");
        }
Esempio n. 4
0
        public string SearchPerson(string IpAddress, string UserName, string Password, ushort Port)
        {
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO nET_DVR_USER_LOGIN_INFO = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();

            nET_DVR_USER_LOGIN_INFO.sDeviceAddress = IpAddress;
            nET_DVR_USER_LOGIN_INFO.wPort          = Port;
            nET_DVR_USER_LOGIN_INFO.sUserName      = UserName;
            nET_DVR_USER_LOGIN_INFO.sPassword      = Password;
            nET_DVR_USER_LOGIN_INFO.bUseAsynLogin  = false;

            CHCNetSDK.NET_DVR_DEVICEINFO_V40 nET_DVR_DEVICEINFO_V40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            nET_DVR_DEVICEINFO_V40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            int userID = CHCNetSDK.NET_DVR_Login_V40(ref nET_DVR_USER_LOGIN_INFO, ref nET_DVR_DEVICEINFO_V40);

            string url = "POST /ISAPI/AccessControl/UserInfo/Search?format=json";

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT nET_DVR_XML_CONFIG_INPUT = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();

            Int32 nInSize = Marshal.SizeOf(nET_DVR_XML_CONFIG_INPUT);

            nET_DVR_XML_CONFIG_INPUT.dwSize          = (uint)nInSize;
            nET_DVR_XML_CONFIG_INPUT.lpRequestUrl    = Marshal.StringToHGlobalAnsi(url);
            nET_DVR_XML_CONFIG_INPUT.dwRequestUrlLen = (uint)url.Length;

            var userInfoSearchCond = new { searchID = "0", searchResultPosition = 0, maxResults = 50 };
            var json    = new { UserInfoSearchCond = userInfoSearchCond };
            var strJson = JsonConvert.SerializeObject(json);

            nET_DVR_XML_CONFIG_INPUT.lpInBuffer     = Marshal.StringToHGlobalAnsi(strJson);
            nET_DVR_XML_CONFIG_INPUT.dwInBufferSize = (uint)strJson.Length;

            // reserve space for return data
            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT nET_DVR_XML_CONFIG_OUTPUT = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
            nET_DVR_XML_CONFIG_OUTPUT.dwSize          = (uint)Marshal.SizeOf(nET_DVR_XML_CONFIG_INPUT);
            nET_DVR_XML_CONFIG_OUTPUT.lpOutBuffer     = Marshal.AllocHGlobal(3 * 1024 * 1024);
            nET_DVR_XML_CONFIG_OUTPUT.dwOutBufferSize = 3 * 1024 * 1024;
            nET_DVR_XML_CONFIG_OUTPUT.lpStatusBuffer  = Marshal.AllocHGlobal(4096 * 4);
            nET_DVR_XML_CONFIG_OUTPUT.dwStatusSize    = 4096 * 4;

            if (!NET_DVR_STDXMLConfig(userID, ref nET_DVR_XML_CONFIG_INPUT, ref nET_DVR_XML_CONFIG_OUTPUT))
            {
                uint   getLastError = CHCNetSDK.NET_DVR_GetLastError();
                string errorStr     = "NET_DVR_STDXMLConfig failed :" + getLastError;
                Console.WriteLine(errorStr);
            }

            string result = Marshal.PtrToStringAnsi(nET_DVR_XML_CONFIG_OUTPUT.lpOutBuffer);

            Console.WriteLine(result);


            Marshal.FreeHGlobal(nET_DVR_XML_CONFIG_INPUT.lpRequestUrl);
            Marshal.FreeHGlobal(nET_DVR_XML_CONFIG_OUTPUT.lpOutBuffer);
            Marshal.FreeHGlobal(nET_DVR_XML_CONFIG_OUTPUT.lpStatusBuffer);

            return(result);
        }
Esempio n. 5
0
        private void DVR_Login()
        {
            if (textBoxport.Text == "" ||
                textBoxUserName.Text == "" || textBoxPassword.Text == "")
            {
                MessageBox.Show("Please input IP, User name and Password!");
                return;
            }
            struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();


            //设备用户名
            byte[] byUserName = System.Text.Encoding.Default.GetBytes(textBoxUserName.Text);
            struLogInfo.sUserName = new byte[64];
            byUserName.CopyTo(struLogInfo.sUserName, 0);

            //设备密码
            byte[] byPassword = System.Text.Encoding.Default.GetBytes(textBoxPassword.Text);
            struLogInfo.sPassword = new byte[64];
            byPassword.CopyTo(struLogInfo.sPassword, 0);

            struLogInfo.wPort = ushort.Parse(textBoxport.Text);//设备服务端口号

            if (LoginCallBack == null)
            {
                LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
            }
            struLogInfo.cbLoginResult = LoginCallBack;
            struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是

            byte[] byIP = System.Text.Encoding.Default.GetBytes(textBoxIP.Text);

            struLogInfo.sDeviceAddress = new byte[129];
            byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

            DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            if (m_lUserID < 0)
            {
                m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);
                if (m_lUserID < 0)
                {
                    str         = "连接失败 : " + "Login_err_" + CHCNetSDK.NET_DVR_GetLastError(); //登录失败,输出错误号
                    label2.Text = str;
                }
                else
                {
                    label2.Text = "设备连接成功";
                }
            }
        }
Esempio n. 6
0
        public void Login()
        {
            if (EventByDeploy.m_UserID >= 0)
            {
                CHCNetSDK.NET_DVR_Logout_V30(EventByDeploy.m_UserID);
                EventByDeploy.m_UserID = -1;
            }
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            struLoginInfo.sDeviceAddress = textBoxDeviceAddress.Text;
            struLoginInfo.sUserName      = textBoxUserName.Text;
            struLoginInfo.sPassword      = textBoxPassword.Text;
            ushort.TryParse(textBoxPort.Text, out struLoginInfo.wPort);

            int lUserID = -1;

            lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
            if (lUserID >= 0)
            {
                EventByDeploy.m_UserID = lUserID;
                MessageBox.Show("Login Successful");
                this.Close();
            }
            else
            {
                uint nErr = CHCNetSDK.NET_DVR_GetLastError();
                if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
                {
                    MessageBox.Show("user name or password error!");
                    if (1 == struDeviceInfoV40.bySupportLock)
                    {
                        string strTemp1 = string.Format("Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
                        MessageBox.Show(strTemp1);
                    }
                }
                else if (nErr == CHCNetSDK.NET_DVR_USER_LOCKED)
                {
                    if (1 == struDeviceInfoV40.bySupportLock)
                    {
                        string strTemp1 = string.Format("user is locked, the remaining lock time is {0}", struDeviceInfoV40.dwSurplusLockTime);
                        MessageBox.Show(strTemp1);
                    }
                }
                else
                {
                    MessageBox.Show("Login fail error: " + nErr);
                }
            }
        }
Esempio n. 7
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (textBoxport.Text == "" ||
                textBoxUserName.Text == "" || textBoxPassword.Text == "")
            {
                MessageBox.Show("Please input IP, User name and Password!");
                return;
            }
            struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();



            //设备用户名
            byte[] byUserName = System.Text.Encoding.Default.GetBytes(textBoxUserName.Text);
            struLogInfo.sUserName = new byte[64];
            byUserName.CopyTo(struLogInfo.sUserName, 0);

            //设备密码
            byte[] byPassword = System.Text.Encoding.Default.GetBytes(textBoxPassword.Text);
            struLogInfo.sPassword = new byte[64];
            byPassword.CopyTo(struLogInfo.sPassword, 0);

            struLogInfo.wPort = ushort.Parse(textBoxport.Text);//设备服务端口号

            if (LoginCallBack == null)
            {
                LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
            }
            struLogInfo.cbLoginResult = LoginCallBack;
            struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是

            DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();


            DVR_Login_out(0, textBox1.Text, labels1);
            DVR_Login_out(1, textBox2.Text, labels2);
            DVR_Login_out(2, textBox3.Text, labels3);
            DVR_Login_out(3, textBox4.Text, labels4);
            DVR_Login_out(4, textBox5.Text, labels5);
            DVR_Login_out(5, textBox6.Text, labels6);
            DVR_Login_out(6, textBox7.Text, labels7);
            DVR_Login_out(7, textBox8.Text, labels8);
            DVR_Login_out(8, textBox9.Text, labels9);

            return;
        }
Esempio n. 8
0
        public OResult <Boolean> Login(CameraLoginRequest request)
        {
            try
            {
                var struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();

                //设备IP地址或者域名
                Byte[] byIP = Encoding.Default.GetBytes(request.IP);
                struLogInfo.sDeviceAddress = new Byte[129];
                byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

                //设备服务端口号
                struLogInfo.wPort = (UInt16)request.LoginPort;

                //设备用户名
                Byte[] byUserName = Encoding.Default.GetBytes(request.UserName);
                struLogInfo.sUserName = new Byte[64];
                byUserName.CopyTo(struLogInfo.sUserName, 0);

                //设备密码
                Byte[] byPassword = Encoding.Default.GetBytes(request.Password);
                struLogInfo.sPassword = new Byte[64];
                byPassword.CopyTo(struLogInfo.sPassword, 0);

                struLogInfo.cbLoginResult = new CHCNetSDK.LOGINRESULTCALLBACK(LoginCallBack);
                struLogInfo.bUseAsynLogin = false;

                _deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
                _userId     = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref _deviceInfo);

                if (_userId < 0)
                {
                    return(new OResult <Boolean>(false, HkvsErrorCode.GetLastErrorCode(), $"登录失败:{HkvsErrorCode.GetLastErrorMessage()}"));
                }

                _loginRequest = request;
                return(new OResult <Boolean>(true));
            }
            catch (Exception ex)
            {
                return(new OResult <Boolean>(false, ex));
            }
        }
        public bool InitializeComponent(Control parent, int width, int stride, int height)
        {
            if (m_lUserID >= 0)
            {
                return(false);
            }

            var struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();

            // 设备IP地址或者域名
            byte[] byIP = Encoding.Default.GetBytes("192.168.1.64");
            struLogInfo.sDeviceAddress = new byte[129];
            byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

            // 设备用户名
            byte[] byUserName = Encoding.Default.GetBytes("admin");
            struLogInfo.sUserName = new byte[64];
            byUserName.CopyTo(struLogInfo.sUserName, 0);

            // 设备密码
            byte[] byPassword = Encoding.Default.GetBytes("abcd1234");
            struLogInfo.sPassword = new byte[64];
            byPassword.CopyTo(struLogInfo.sPassword, 0);

            struLogInfo.wPort         = ushort.Parse("8000"); //设备服务端口号
            struLogInfo.bUseAsynLogin = false;                //是否异步登录:0- 否,1- 是

            var DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                return(false);
            }

            return(StartRealPlay(channel, parent.Handle));
        }
Esempio n. 10
0
        public bool Login(bool bStatus)//true said add node login, false for the existing node to log in
        {
            LoginCallBackFlag = false;
            m_struDeviceInfo  = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            struDeviceInfo.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            CHCNetSDK.NET_DVR_NETCFG_V50 struNetCfg = new CHCNetSDK.NET_DVR_NETCFG_V50();
            struNetCfg.Init();
            CHCNetSDK.NET_DVR_DEVICECFG_V40 struDevCfg = new CHCNetSDK.NET_DVR_DEVICECFG_V40();
            struDevCfg.sDVRName      = new byte[CHCNetSDK.NAME_LEN];
            struDevCfg.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];
            struDevCfg.byDevTypeName = new byte[CHCNetSDK.DEV_TYPE_NAME_LEN];
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];
            uint dwReturned = 0;
            int  lUserID    = -1;

            struLoginInfo.bUseAsynLogin = AysnLoginFlag;
            struLoginInfo.cbLoginResult = new CHCNetSDK.LoginResultCallBack(AsynLoginMsgCallback);

            if (bStatus)
            {
                struLoginInfo.sDeviceAddress = textBoxDeviceAddress.Text;
                struLoginInfo.sUserName      = textBoxUserName.Text;
                struLoginInfo.sPassword      = textBoxPassword.Text;
                ushort.TryParse(textBoxPort.Text, out struLoginInfo.wPort);
            }
            else
            {
                struLoginInfo.sDeviceAddress = g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chDeviceIP;
                struLoginInfo.sUserName      = g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chLoginUserName;
                struLoginInfo.sPassword      = g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chLoginPwd;
                struLoginInfo.wPort          = (ushort)g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].lDevicePort;
            }

            lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
            if (struLoginInfo.bUseAsynLogin)
            {
                for (int i = 0; i < 1000; i++)
                {
                    if (!LoginCallBackFlag)
                    {
                        Thread.Sleep(5);
                    }
                    else
                    {
                        break;
                    }
                }
                if (!LoginCallBackFlag)
                {
                    MessageBox.Show(Properties.Resources.asynloginTips, Properties.Resources.messageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                if (m_AysnLoginResult == 1)
                {
                    lUserID = m_iUserID;
                    struDeviceInfoV40.struDeviceV30 = m_struDeviceInfo;
                }
                else
                {
                    MessageBox.Show(Properties.Resources.asynloginFailedTips, Properties.Resources.messageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }
            }

            if (lUserID < 0)
            {
                uint   nErr    = CHCNetSDK.NET_DVR_GetLastError();
                string strTemp = string.Format("NET_DVR_Login_V40 [{0}]", textBoxDeviceAddress.Text);
                g_formList.AddLog(-1, AcsDemoPublic.OPERATION_FAIL_T, strTemp);
                if (nErr == CHCNetSDK.NET_DVR_PASSWORD_ERROR)
                {
                    MessageBox.Show("user name or password error!");
                    if (1 == struDeviceInfoV40.bySupportLock)
                    {
                        string strTemp1 = string.Format("Left {0} try opportunity", struDeviceInfoV40.byRetryLoginTime);
                        MessageBox.Show(strTemp1);
                    }
                }
                else if (nErr == CHCNetSDK.NET_DVR_USER_LOCKED)
                {
                    if (1 == struDeviceInfoV40.bySupportLock)
                    {
                        string strTemp1 = string.Format("user is locked, the remaining lock time is {0}", struDeviceInfoV40.dwSurplusLockTime);
                        MessageBox.Show(strTemp1);
                    }
                }
                else
                {
                    MessageBox.Show("net error or dvr is busy!");
                }
                return(false);
            }
            else
            {
                if (1 == struDeviceInfoV40.byPasswordLevel)
                {
                    MessageBox.Show("default password, please change the password");
                }
                else if (3 == struDeviceInfoV40.byPasswordLevel)
                {
                    MessageBox.Show("risk password, please change the password");
                }
                struDeviceInfo = struDeviceInfoV40.struDeviceV30;
            }

            if (bStatus)
            {
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chLocalNodeName = textBoxLocalNode.Text;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chLoginPwd      = textBoxPassword.Text;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chDeviceIP      = textBoxDeviceAddress.Text;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chLoginUserName = textBoxUserName.Text;
                int.TryParse(textBoxPort.Text, out g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].lDevicePort);
            }

            g_formList.AddLog(m_iDeviceIndex, AcsDemoPublic.OPERATION_SUCC_T, "NET_DVR_Login_V40");

            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byCharaterEncodeType    = struDeviceInfoV40.byCharEncodeType;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].lLoginID                = lUserID;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chSerialNumber          = System.Text.Encoding.UTF8.GetString(struDeviceInfo.sSerialNumber).TrimEnd('\0');
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDeviceIndex            = m_iDeviceIndex;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDeviceType             = (int)struDeviceInfo.wDevType;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDeviceChanNum          = (int)(struDeviceInfo.byChanNum + struDeviceInfo.byIPChanNum + struDeviceInfo.byHighDChanNum * 256);
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iStartChan              = (int)struDeviceInfo.byStartChan;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDiskNum                = (int)struDeviceInfo.byDiskNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iAlarmInNum             = (int)struDeviceInfo.byAlarmInPortNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iAlarmOutNum            = (int)struDeviceInfo.byAlarmOutPortNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iAudioNum               = (int)struDeviceInfo.byAlarmOutPortNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iAnalogChanNum          = (int)struDeviceInfo.byChanNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iIPChanNum              = (int)(struDeviceInfo.byIPChanNum + struDeviceInfo.byHighDChanNum * 256);
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byZeroChanNum           = struDeviceInfo.byZeroChanNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byStartDTalkChan        = struDeviceInfo.byStartDTalkChan;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byLanguageType          = struDeviceInfo.byLanguageType;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byMirrorChanNum         = struDeviceInfo.byMirrorChanNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].wStartMirrorChanNo      = struDeviceInfo.wStartMirrorChanNo;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byAudioInputChanNum     = struDeviceInfo.byVoiceInChanNum;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byStartAudioInputChanNo = struDeviceInfo.byStartVoiceInChanNo;

            if (1 == (struDeviceInfo.bySupport & 0x80))
            {
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byMainProto = (byte)(struDeviceInfo.byMainProto + 2);
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].bySubProto  = (byte)(struDeviceInfo.bySubProto + 2);
            }
            else
            {
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byMainProto = struDeviceInfo.byMainProto;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].bySubProto  = struDeviceInfo.bySubProto;
            }

            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].bySupport1     = struDeviceInfo.bySupport1;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].bySupport2     = struDeviceInfo.bySupport2;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].bySupport7     = struDeviceInfo.bySupport7;
            g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byLanguageType = struDeviceInfo.byLanguageType;

            uint   dwSize    = (uint)Marshal.SizeOf(struNetCfg);
            IntPtr ptrNetCfg = Marshal.AllocHGlobal((int)dwSize);

            Marshal.StructureToPtr(struNetCfg, ptrNetCfg, false);

            if (!CHCNetSDK.NET_DVR_GetDVRConfig(lUserID, CHCNetSDK.NET_DVR_GET_NETCFG_V50, 0, ptrNetCfg, dwSize, ref dwReturned))
            {
                g_formList.AddLog(m_iDeviceIndex, AcsDemoPublic.OPERATION_FAIL_T, "NET_DVR_GET_NETCFG_V50");
            }
            else
            {
                //IPv6 temporary unrealized
                struNetCfg = (CHCNetSDK.NET_DVR_NETCFG_V50)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_NETCFG_V50));
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chDeviceMultiIP = struNetCfg.struMulticastIpAddr.sIpV4;
                string strTemp = string.Format("multi-cast ipv4 {0}", struNetCfg.struMulticastIpAddr.sIpV4);
                g_formList.AddLog(m_iDeviceIndex, AcsDemoPublic.OPERATION_SUCC_T, strTemp);
            }
            Marshal.FreeHGlobal(ptrNetCfg);

            dwReturned = 0;
            uint   dwSize2   = (uint)Marshal.SizeOf(struDevCfg);
            IntPtr ptrDevCfg = Marshal.AllocHGlobal((int)dwSize2);

            Marshal.StructureToPtr(struDevCfg, ptrDevCfg, false);

            if (!CHCNetSDK.NET_DVR_GetDVRConfig(lUserID, CHCNetSDK.NET_DVR_GET_DEVICECFG_V40, 0, ptrDevCfg, dwSize2, ref dwReturned))
            {
                g_formList.AddLog(lUserID, AcsDemoPublic.OPERATION_FAIL_T, "NET_DVR_GET_DEVICECFG_V40");
            }
            else
            {
                struDevCfg = (CHCNetSDK.NET_DVR_DEVICECFG_V40)Marshal.PtrToStructure(ptrDevCfg, typeof(CHCNetSDK.NET_DVR_DEVICECFG_V40));
                if (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDeviceType != (int)struDevCfg.wDevType)
                {
                    // string strTemp = null;
                    string strShow = null;
                    // g_formList.g_StringLanType(ref strTemp, "登陆返回设备类型值与获取设备参数返回设备类型值不同", "returned device type is different between login and get device config");
                    strShow = "returned device type is different between login and get device config" + g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDeviceType.ToString() + " " + struDevCfg.wDevType.ToString();
                    MessageBox.Show(strShow);
                }
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].chDeviceName = System.Text.Encoding.UTF8.GetString(struDevCfg.byDevTypeName).Trim('\0');
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].dwDevSoftVer = struDevCfg.dwSoftwareVersion;
            }
            Marshal.FreeHGlobal(ptrDevCfg);

            if (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iIPChanNum >= 0)
            {
                if (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iIPChanNum == 0)
                {
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruIPParaCfgV40 = new CHCNetSDK.NET_DVR_IPPARACFG_V40[1];
                }
                else
                {
                    if (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iIPChanNum % CHCNetSDK.MAX_CHANNUM_V30 == 0)
                    {
                        g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruIPParaCfgV40 =
                            new CHCNetSDK.NET_DVR_IPPARACFG_V40[g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iIPChanNum / CHCNetSDK.MAX_CHANNUM_V30];
                    }
                    else
                    {
                        g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruIPParaCfgV40 =
                            new CHCNetSDK.NET_DVR_IPPARACFG_V40[g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iIPChanNum / CHCNetSDK.MAX_CHANNUM_V30 + 1];
                    }
                }
            }

            //if (DoGetDeviceResoureCfg(m_iDeviceIndex))
            //{

            //}

            return(true);
        }
        /// <summary>
        /// 下发卡数据
        /// </summary>
        /// <param name="message"></param>
        /// <param name="deviceIPAddr"></param>
        /// <param name="devicePort"></param>
        /// <param name="userInfo"></param>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="cbSetRemoteConfig"></param>
        /// <returns></returns>
        public bool CardInsert(
            out string message,
            string deviceIPAddr,
            int devicePort,
            Core.Domain.EntranceControl.UserInfo userInfo,
            string user     = "******",
            string password = "",
            CHCNetSDK.RemoteConfigCallback cbSetRemoteConfig = null)
        {
            bool ret = false;

            message = string.Empty;
            uint errCode = 0;
            int  iUserId = -1;
            //用户数据指针
            IntPtr ptrUserData = IntPtr.Zero;
            //长连接句柄
            int hndRemoteConfig = -1;
            //长连接数据发送是否成功
            bool retSendRemoteConfig  = false;
            bool retCloseRemoteConfig = false;

            #region init

            //初始化
            coreInfrastructure.NetDvrInit();

            //设置连接超时时间与重连功能
            //CHCNetSDK.NET_DVR_SetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);
            coreInfrastructure.NetDvrSetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);

            //CHCNetSDK.NET_DVR_SetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);
            coreInfrastructure.NetDvrSetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);

            #endregion

            #region login

            CHCNetSDK.NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            //登录设备 Login the device
            iUserId = coreInfrastructure.NetDvrLoginV40(deviceIPAddr, devicePort, user, password, ref struDeviceInfoV40);

            if (iUserId < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_Login_V40 failed, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            #region start remote config 启动长连接配置

            if (null == cbSetRemoteConfig)
            {
                SetRemoteConfigDelegate = new CHCNetSDK.RemoteConfigCallback(ProcessCardInsertCallback);
            }
            else
            {
                SetRemoteConfigDelegate = cbSetRemoteConfig;
            }

            hndRemoteConfig = logicCardManage.StartRemoteConfigForCardInsert(iUserId, GetRemoteConfigDelegate, ptrUserData, userInfo);

            if (hndRemoteConfig < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_StartRemoteConfig, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            #region send remote config 发送长连接数据

            retSendRemoteConfig = logicCardManage.SendRemoteConfigForCardInsert(hndRemoteConfig, userInfo);

            if (!retSendRemoteConfig)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_SendRemoteConfig, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            System.Threading.Thread.Sleep(PreSettings.durationCallback);

            #region 获取数据

            ret = retSendRemoteConfig && errCode == 0;

            message = errCode + "";

            #endregion

            #region 关闭长连接配置接口所创建的句柄,释放资源

            if (bSetCardCfgFinish)
            {
                retCloseRemoteConfig = coreInfrastructure.NetDvrStopRemoteConfig(hndRemoteConfig);
            }

            bSetCardCfgFinish = false;

            #endregion


            //注销用户
            //CHCNetSDK.NET_DVR_Logout(iUserId);
            coreInfrastructure.NetDvrLogout(iUserId);
            //释放 SDK 资源
            //CHCNetSDK.NET_DVR_Cleanup();
            coreInfrastructure.NetDvrCleanUp();

            return(errCode == 0);
        }
        /// <summary>
        /// 查询卡数据
        /// </summary>
        /// <param name="message"></param>
        /// <param name="employeeNo"></param>
        /// <param name="deviceIPAddr"></param>
        /// <param name="devicePort"></param>
        /// <param name="cardNo"></param>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="cbGetRemoteConfig"></param>
        /// <returns></returns>
        public bool CardQuery(
            out string message,
            out uint employeeNo,
            string deviceIPAddr,
            int devicePort,
            string cardNo,
            string user     = "******",
            string password = "",
            CHCNetSDK.RemoteConfigCallback cbGetRemoteConfig = null)
        {
            bool ret = false;

            message    = string.Empty;
            employeeNo = 0;
            uint   errCode   = 0;
            int    iUserId   = -1;
            IntPtr pUserData = IntPtr.Zero;
            //长连接句柄
            int hndRemoteConfig = -1;
            //长连接数据发送是否成功
            bool retSendRemoteConfig  = false;
            bool retCloseRemoteConfig = false;

            #region init

            //初始化
            coreInfrastructure.NetDvrInit();

            //设置连接超时时间与重连功能
            //CHCNetSDK.NET_DVR_SetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);
            coreInfrastructure.NetDvrSetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);

            //CHCNetSDK.NET_DVR_SetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);
            coreInfrastructure.NetDvrSetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);

            #endregion

            #region login

            CHCNetSDK.NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            //登录设备 Login the device
            iUserId = coreInfrastructure.NetDvrLoginV40(deviceIPAddr, devicePort, user, password, ref struDeviceInfoV40);

            if (iUserId < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_Login_V40 failed, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            #region start remote config 启动长连接配置

            if (null == cbGetRemoteConfig)
            {
                GetRemoteConfigDelegate = new CHCNetSDK.RemoteConfigCallback(ProcessCardQueryCallback);
            }
            else
            {
                GetRemoteConfigDelegate = cbGetRemoteConfig;
            }

            hndRemoteConfig = logicCardManage.StartRemoteConfigForCardQuery(iUserId, GetRemoteConfigDelegate, pUserData, cardNo);

            if (hndRemoteConfig < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_StartRemoteConfig, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            #region send remote config 发送长连接数据

            retSendRemoteConfig = logicCardManage.SendRemoteConfigForCardQuery(hndRemoteConfig, cardNo);

            if (!retSendRemoteConfig)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_SendRemoteConfig, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            System.Threading.Thread.Sleep(PreSettings.durationCallback);

            #region 获取数据

            ret = retSendRemoteConfig;

            employeeNo = struCardInfo.dwEmployeeNo;

            //struCardInfo = (CHCNetSDK.NET_DVR_CARD_CFG_V50)Marshal.PtrToStructure(buffer, typeof(CHCNetSDK.NET_DVR_CARD_CFG_V50));

            message = "error:" + errCode;

            #endregion

            #region 关闭长连接配置接口所创建的句柄,释放资源

            if (bGetCardCfgFinish)
            {
                retCloseRemoteConfig = coreInfrastructure.NetDvrStopRemoteConfig(hndRemoteConfig);
            }

            bGetCardCfgFinish = false;
            #endregion

            //System.Threading.Thread.Sleep(PreSettings.durationCallback);
            //注销用户
            //CHCNetSDK.NET_DVR_Logout(iUserId);
            coreInfrastructure.NetDvrLogout(iUserId);
            //释放 SDK 资源
            //CHCNetSDK.NET_DVR_Cleanup();
            coreInfrastructure.NetDvrCleanUp();

            return(ret);
        }
Esempio n. 13
0
    private void Login()
    {
        CHCNetSDK.NET_DVR_Init();
        if (m_lUserID < 0)
        {
            struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();

            //设备IP地址或者域名
            byte[] byIP = System.Text.Encoding.Default.GetBytes("192.168.1.64");
            struLogInfo.sDeviceAddress = new byte[129];
            byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

            //设备用户名
            byte[] byUserName = System.Text.Encoding.Default.GetBytes("admin");
            struLogInfo.sUserName = new byte[64];
            byUserName.CopyTo(struLogInfo.sUserName, 0);

            //设备密码
            byte[] byPassword = System.Text.Encoding.Default.GetBytes("daqing123");
            struLogInfo.sPassword = new byte[64];
            byPassword.CopyTo(struLogInfo.sPassword, 0);

            struLogInfo.wPort = ushort.Parse("8000");//设备服务端口号

            if (LoginCallBack == null)
            {
                //LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
            }
            struLogInfo.cbLoginResult = LoginCallBack;
            struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是

            DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_Login_V40 failed, error code= " + iLastErr; //登录失败,输出错误号
                Debug.Log(str);
                return;
            }
            else
            {
                //登录成功
                Debug.Log("Login Success!");
            }
        }
        //else
        //{
        //    //注销登录 Logout the device
        //    if (m_lRealHandle >= 0)
        //    {
        //        MessageBox.Show("Please stop live view firstly");
        //        return;
        //    }

        //    if (!CHCNetSDK.NET_DVR_Logout(m_lUserID))
        //    {
        //        iLastErr = CHCNetSDK.NET_DVR_GetLastError();
        //        str = "NET_DVR_Logout failed, error code= " + iLastErr;
        //        MessageBox.Show(str);
        //        return;
        //    }
        //    m_lUserID = -1;
        //    btnLogin.Text = "Login";
        //}
        return;
    }
Esempio n. 14
0
        /// <summary>
        /// 登录NVR
        /// </summary>
        private void LoginNVR()
        {
            try
            {
                uint dwReturned = 0;
                InitDeviceInfo();
                CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
                CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
                //string DVRIPAddress = cameraParm.DEVICEIP;
                //Int16 DVRPortNumber = (short)cameraParm.PORT;
                //string DVRUserName = cameraParm.VIDEOUSERNAME;
                //string DVRPassword = cameraParm.PASSWORD;
                struLoginInfo.sDeviceAddress = Configurations.VideoIP;
                struLoginInfo.sUserName      = Configurations.VideoUserName;
                struLoginInfo.sPassword      = Configurations.VideoPSW;
                struLoginInfo.wPort          = (ushort)Configurations.VideoPort;
                CHCNetSDK.NET_DVR_SetConnectTime(5000, 1);//设置超时时间
                CHCNetSDK.NET_DVR_NETCFG_V30 struNetCfg = new CHCNetSDK.NET_DVR_NETCFG_V30();
                struNetCfg.init();
                CHCNetSDK.NET_DVR_DEVICECFG_V40 struDevCfg = new CHCNetSDK.NET_DVR_DEVICECFG_V40();
                struDevCfg.sDVRName      = new byte[CHCNetSDK.NAME_LEN];
                struDevCfg.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];
                struDevCfg.byDevTypeName = new byte[CHCNetSDK.DEV_TYPE_NAME_LEN];
                m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);
                //m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref dev);
                //dicChanInfo = nvrConfig.GetChanParm(m_lUserID, dev);  //获取视频通道参数
                if (m_lUserID == -1)
                {
                    MessageBox.Show("视频登录失败!");
                }
                else
                {//登录成功
                    IsLoginOk      = true;
                    struDeviceInfo = struDeviceInfoV40.struDeviceV30;
                }
                g_struDeviceInfo[m_iDeviceIndex].byCharaterEncodeType    = struDeviceInfoV40.byCharEncodeType;
                g_struDeviceInfo[m_iDeviceIndex].lLoginID                = m_lUserID;
                g_struDeviceInfo[m_iDeviceIndex].chSerialNumber          = System.Text.Encoding.UTF8.GetString(struDeviceInfo.sSerialNumber).TrimEnd('\0');
                g_struDeviceInfo[m_iDeviceIndex].iDeviceIndex            = m_iDeviceIndex;
                g_struDeviceInfo[m_iDeviceIndex].iDeviceType             = (int)struDeviceInfo.wDevType;
                g_struDeviceInfo[m_iDeviceIndex].iDeviceChanNum          = (int)(struDeviceInfo.byChanNum + struDeviceInfo.byIPChanNum + struDeviceInfo.byHighDChanNum * 256);
                g_struDeviceInfo[m_iDeviceIndex].iStartChan              = (int)struDeviceInfo.byStartChan;
                g_struDeviceInfo[m_iDeviceIndex].iDiskNum                = (int)struDeviceInfo.byDiskNum;
                g_struDeviceInfo[m_iDeviceIndex].iAlarmInNum             = (int)struDeviceInfo.byAlarmInPortNum;
                g_struDeviceInfo[m_iDeviceIndex].iAlarmOutNum            = (int)struDeviceInfo.byAlarmOutPortNum;
                g_struDeviceInfo[m_iDeviceIndex].iAudioNum               = (int)struDeviceInfo.byAlarmOutPortNum;
                g_struDeviceInfo[m_iDeviceIndex].iAnalogChanNum          = (int)struDeviceInfo.byChanNum;
                g_struDeviceInfo[m_iDeviceIndex].iIPChanNum              = (int)(struDeviceInfo.byIPChanNum + struDeviceInfo.byHighDChanNum * 256);
                g_struDeviceInfo[m_iDeviceIndex].byZeroChanNum           = struDeviceInfo.byZeroChanNum;
                g_struDeviceInfo[m_iDeviceIndex].byStartDTalkChan        = struDeviceInfo.byStartDTalkChan;
                g_struDeviceInfo[m_iDeviceIndex].byLanguageType          = struDeviceInfo.byLanguageType;
                g_struDeviceInfo[m_iDeviceIndex].byMirrorChanNum         = struDeviceInfo.byMirrorChanNum;
                g_struDeviceInfo[m_iDeviceIndex].wStartMirrorChanNo      = struDeviceInfo.wStartMirrorChanNo;
                g_struDeviceInfo[m_iDeviceIndex].byAudioInputChanNum     = struDeviceInfo.byVoiceInChanNum;
                g_struDeviceInfo[m_iDeviceIndex].byStartAudioInputChanNo = struDeviceInfo.byStartVoiceInChanNo;
                if (1 == (struDeviceInfo.bySupport & 0x80))
                {
                    g_struDeviceInfo[m_iDeviceIndex].byMainProto = (byte)(struDeviceInfo.byMainProto + 2);
                    g_struDeviceInfo[m_iDeviceIndex].bySubProto  = (byte)(struDeviceInfo.bySubProto + 2);
                }
                else
                {
                    g_struDeviceInfo[m_iDeviceIndex].byMainProto = struDeviceInfo.byMainProto;
                    g_struDeviceInfo[m_iDeviceIndex].bySubProto  = struDeviceInfo.bySubProto;
                }
                g_struDeviceInfo[m_iDeviceIndex].bySupport1     = struDeviceInfo.bySupport1;
                g_struDeviceInfo[m_iDeviceIndex].bySupport2     = struDeviceInfo.bySupport2;
                g_struDeviceInfo[m_iDeviceIndex].bySupport7     = struDeviceInfo.bySupport7;
                g_struDeviceInfo[m_iDeviceIndex].byLanguageType = struDeviceInfo.byLanguageType;
                uint   dwSize    = (uint)Marshal.SizeOf(struNetCfg);
                IntPtr ptrNetCfg = Marshal.AllocHGlobal((int)dwSize);
                Marshal.StructureToPtr(struNetCfg, ptrNetCfg, false);
                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_NETCFG_V30, 0, ptrNetCfg, dwSize, ref dwReturned))
                {
                }
                else
                {
                    //IPv6 temporary unrealized
                    struNetCfg = (CHCNetSDK.NET_DVR_NETCFG_V30)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_NETCFG_V30));
                    g_struDeviceInfo[m_iDeviceIndex].chDeviceMultiIP = struNetCfg.struMulticastIpAddr.sIpV4;
                    string strTemp = string.Format("multi-cast ipv4{0}", struNetCfg.struMulticastIpAddr.sIpV4);
                }
                Marshal.FreeHGlobal(ptrNetCfg);

                dwReturned = 0;
                uint   dwSize2   = (uint)Marshal.SizeOf(struDevCfg);
                IntPtr ptrDevCfg = Marshal.AllocHGlobal((int)dwSize2);
                Marshal.StructureToPtr(struDevCfg, ptrDevCfg, false);

                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_DEVICECFG_V40, 0, ptrDevCfg, dwSize2, ref dwReturned))
                {
                }
                else
                {
                    struDevCfg = (CHCNetSDK.NET_DVR_DEVICECFG_V40)Marshal.PtrToStructure(ptrDevCfg, typeof(CHCNetSDK.NET_DVR_DEVICECFG_V40));
                    if (g_struDeviceInfo[m_iDeviceIndex].iDeviceType != (int)struDevCfg.wDevType)
                    {
                        string strTemp = null;
                        string strShow = null;
                        strShow = strTemp + g_struDeviceInfo[m_iDeviceIndex].iDeviceType.ToString() + struDevCfg.wDevType.ToString();
                        MessageBox.Show(strShow);
                    }
                    g_struDeviceInfo[m_iDeviceIndex].chDeviceName = System.Text.Encoding.UTF8.GetString(struDevCfg.byDevTypeName).Trim('\0');
                    g_struDeviceInfo[m_iDeviceIndex].dwDevSoftVer = struDevCfg.dwSoftwareVersion;
                }
                Marshal.FreeHGlobal(ptrDevCfg);

                if (g_struDeviceInfo[m_iDeviceIndex].iIPChanNum >= 0)
                {
                    if (g_struDeviceInfo[m_iDeviceIndex].iIPChanNum == 0)
                    {
                        g_struDeviceInfo[m_iDeviceIndex].pStruIPParaCfgV40 = new CHCNetSDK.NET_DVR_IPPARACFG_V40[1];
                    }
                    else
                    {
                        if (g_struDeviceInfo[m_iDeviceIndex].iIPChanNum % CHCNetSDK.MAX_CHANNUM_V30 == 0)
                        {
                            g_struDeviceInfo[m_iDeviceIndex].pStruIPParaCfgV40 =
                                new CHCNetSDK.NET_DVR_IPPARACFG_V40[g_struDeviceInfo[m_iDeviceIndex].iIPChanNum / CHCNetSDK.MAX_CHANNUM_V30];
                        }
                        else
                        {
                            g_struDeviceInfo[m_iDeviceIndex].pStruIPParaCfgV40 =
                                new CHCNetSDK.NET_DVR_IPPARACFG_V40[g_struDeviceInfo[m_iDeviceIndex].iIPChanNum / CHCNetSDK.MAX_CHANNUM_V30 + 1];
                        }
                    }
                }

                if (DoGetDeviceResoureCfg(m_iDeviceIndex))
                {
                }
            }
            catch (Exception ex)
            { }
        }
Esempio n. 15
0
        //static Task task = null;
        public int Play(string device_ip, string device_username, string device_password, string device_port, string key)
        {
            try
            {
                //if (ps_data_callback == null)
                //{
                //    return "未设置数据回调的实体";
                //}
                CHCNetSDK.NET_DVR_SetLogToFile(0, "", true);
                CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
                //设备IP地址或者域名
                byte[] byIP = System.Text.Encoding.Default.GetBytes(device_ip);
                struLogInfo.sDeviceAddress = new byte[129];
                byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

                //设备用户名
                byte[] byUserName = System.Text.Encoding.Default.GetBytes(device_username);
                struLogInfo.sUserName = new byte[64];
                byUserName.CopyTo(struLogInfo.sUserName, 0);

                //设备密码
                byte[] byPassword = System.Text.Encoding.Default.GetBytes(device_password);
                struLogInfo.sPassword = new byte[64];
                byPassword.CopyTo(struLogInfo.sPassword, 0);

                struLogInfo.wPort = ushort.Parse(device_port);//设备服务端口号
                CHCNetSDK.NET_DVR_DEVICEINFO_V40 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
                int m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);

                if (m_lUserID == -1)
                {
                    uint err = CHCNetSDK.NET_DVR_GetLastError();
                }

                if (RealData == null)
                {
                    RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);//预览实时流回调函数
                }
                IntPtr pUser = Marshal.StringToBSTR(key);
                //if (task == null)
                //{
                //    task = Task.Factory.StartNew(HIKDataInput);
                //}
                //Task task = Task.Factory.StartNew(HIKDataInput);

                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                lpPreviewInfo.lChannel        = 1;    //预te览的设备通道
                lpPreviewInfo.dwStreamType    = 0;    //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                lpPreviewInfo.dwLinkMode      = 0;    //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                lpPreviewInfo.bBlocked        = true; //0- 非阻塞取流,1- 阻塞取流
                lpPreviewInfo.dwDisplayBufNum = 1;    //播放库播放缓冲区最大缓冲帧数
                lpPreviewInfo.byProtoType     = 0;
                lpPreviewInfo.byPreviewMode   = 0;
                if (!dic_cache.ContainsKey(key))
                {
                    dic_cache.Add(key, new List <byte>());
                }
                int m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, /*null*/ RealData, pUser);
                if (m_lRealHandle < 0)//播放失败
                {
                    LogHelper.Print("播放失败:" + m_lRealHandle);
                }
                else
                {
                }
                return(m_lRealHandle);
            }
            catch (Exception ex)
            {
                return(-2);
            }
        }
        /// <summary>
        /// 查询人脸数据
        /// </summary>
        /// <param name="message"></param>
        /// <param name="deviceIPAddr"></param>
        /// <param name="devicePort"></param>
        /// <param name="cardNo"></param>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="cbGetFacePara"></param>
        /// <returns></returns>
        public bool FaceQuery(
            out string message,
            string deviceIPAddr,
            int devicePort,
            string cardNo,
            string user     = "******",
            string password = "******",
            CHCNetSDK.RemoteConfigCallback cbGetFacePara = null)
        {
            bool ret = false;

            message = string.Empty;
            uint errCode = 0;
            int  iUserId = -1;
            //用户数据指针
            IntPtr ptrUserData = IntPtr.Zero;
            //长连接句柄
            int hndRemoteConfig = -1;

            #region init

            //初始化
            coreInfrastructure.NetDvrInit();

            //设置连接超时时间与重连功能
            //CHCNetSDK.NET_DVR_SetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);
            coreInfrastructure.NetDvrSetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);

            //CHCNetSDK.NET_DVR_SetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);
            coreInfrastructure.NetDvrSetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);

            #endregion

            #region login

            CHCNetSDK.NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            //登录设备 Login the device
            iUserId = coreInfrastructure.NetDvrLoginV40(deviceIPAddr, devicePort, user, password, ref struDeviceInfoV40);

            if (iUserId < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_Login_V40 failed, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            #region start remote config 启动长连接配置

            if (null == cbGetFacePara)
            {
                GetFaceParaDelegate = new CHCNetSDK.RemoteConfigCallback(ProcessFaceQueryCallback);
            }
            else
            {
                GetFaceParaDelegate = cbGetFacePara;
            }

            hndRemoteConfig = logicFaceManage.StartRemoteConfigForFaceQuery(iUserId, GetFaceParaDelegate, ptrUserData, cardNo);

            if (hndRemoteConfig < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();
                message = "NET_DVR_StartRemoteConfig, error code= " + errCode; //登录失败,输出错误号
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            #endregion

            System.Threading.Thread.Sleep(PreSettings.durationCallback);

            #region 获取数据

            ret = bGetFaceParamCfgFinish;

            #endregion

            #region 关闭长连接配置接口所创建的句柄,释放资源

            if (bGetFaceParamCfgFinish)
            {
                coreInfrastructure.NetDvrStopRemoteConfig(hndRemoteConfig);
            }

            bGetFaceParamCfgFinish = false;

            #endregion

            //System.Threading.Thread.Sleep(PreSettings.durationCallback);
            //注销用户
            //CHCNetSDK.NET_DVR_Logout(iUserId);
            coreInfrastructure.NetDvrLogout(iUserId);
            //释放 SDK 资源
            //CHCNetSDK.NET_DVR_Cleanup();
            coreInfrastructure.NetDvrCleanUp();


            return(ret);
        }
Esempio n. 17
0
        private void btnLogin_Click(object sender, System.EventArgs e)
        {
            if (textBoxIP.Text == "" || textBoxPort.Text == "" ||
                textBoxUserName.Text == "" || textBoxPassword.Text == "")
            {
                MessageBox.Show("Please input IP, Port, User name and Password!");
                return;
            }
            if (m_lUserID < 0)
            {
                struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();

                //设备IP地址或者域名
                byte[] byIP = System.Text.Encoding.Default.GetBytes(textBoxIP.Text);
                struLogInfo.sDeviceAddress = new byte[129];
                byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

                //设备用户名
                byte[] byUserName = System.Text.Encoding.Default.GetBytes(textBoxUserName.Text);
                struLogInfo.sUserName = new byte[64];
                byUserName.CopyTo(struLogInfo.sUserName, 0);

                //设备密码
                byte[] byPassword = System.Text.Encoding.Default.GetBytes(textBoxPassword.Text);
                struLogInfo.sPassword = new byte[64];
                byPassword.CopyTo(struLogInfo.sPassword, 0);

                struLogInfo.wPort = ushort.Parse(textBoxPort.Text);//设备服务端口号

                if (LoginCallBack == null)
                {
                    LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
                }
                struLogInfo.cbLoginResult = LoginCallBack;
                struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是

                DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

                //登录设备 Login the device
                m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);
                if (m_lUserID < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Login_V40 failed, error code= " + iLastErr; //登录失败,输出错误号
                    MessageBox.Show(str);
                    return;
                }
                else
                {
                    //登录成功
                    MessageBox.Show("Login Success!");
                    btnLogin.Text = "Logout";
                }
            }
            else
            {
                //注销登录 Logout the device
                if (m_lRealHandle >= 0)
                {
                    MessageBox.Show("Please stop live view firstly");
                    return;
                }

                if (!CHCNetSDK.NET_DVR_Logout(m_lUserID))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Logout failed, error code= " + iLastErr;
                    MessageBox.Show(str);
                    return;
                }
                m_lUserID     = -1;
                btnLogin.Text = "Login";
            }
            return;
        }
Esempio n. 18
0
        static void SDKTest()
        {
            string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");

            MediaServer.Config config = new MediaServer.Config();
            config.ini_is_path = 1;
            config.ini         = configPath;
            MediaServer.mk_env_init(ref config);
            uint ret;

            ret = MediaServer.mk_http_server_start(8500, 0);
            ret = MediaServer.mk_rtsp_server_start(554, 0);
            ret = MediaServer.mk_rtmp_server_start(1935, 0);


            ctx = MediaServer.mk_media_create("__defaultVhost__", "fh", "sdklive", 0, 1, 1, 1, 0);
            MediaServer.mk_media_init_video(ctx, 0, 1280, 720, 25);
            MediaServer.mk_media_init_complete(ctx);


            bool m_bInitSDK = CHCNetSDK.NET_DVR_Init();

            CHCNetSDK.NET_DVR_SetLogToFile(0, "", true);
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            //设备IP地址或者域名
            byte[] byIP = System.Text.Encoding.Default.GetBytes("10.128.24.57");
            struLogInfo.sDeviceAddress = new byte[129];
            byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

            //设备用户名
            byte[] byUserName = System.Text.Encoding.Default.GetBytes("admin");
            struLogInfo.sUserName = new byte[64];
            byUserName.CopyTo(struLogInfo.sUserName, 0);

            //设备密码
            byte[] byPassword = System.Text.Encoding.Default.GetBytes("123456a?");
            struLogInfo.sPassword = new byte[64];
            byPassword.CopyTo(struLogInfo.sPassword, 0);

            struLogInfo.wPort = 8000;//设备服务端口号
            CHCNetSDK.NET_DVR_DEVICEINFO_V40 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            int m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);



            if (RealData == null)
            {
                RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);//预览实时流回调函数
            }

            CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
            //lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle;//预览窗口
            lpPreviewInfo.lChannel        = 1;    //预te览的设备通道
            lpPreviewInfo.dwStreamType    = 0;    //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
            lpPreviewInfo.dwLinkMode      = 0;    //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
            lpPreviewInfo.bBlocked        = true; //0- 非阻塞取流,1- 阻塞取流
            lpPreviewInfo.dwDisplayBufNum = 1;    //播放库播放缓冲区最大缓冲帧数
            lpPreviewInfo.byProtoType     = 0;
            lpPreviewInfo.byPreviewMode   = 0;
            IntPtr pUser         = new IntPtr();//用户数据
            int    m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, /*null*/ RealData, pUser);

            if (m_lRealHandle >= 0)//播放成功
            {
                //eSCallBack = new CHCNetSDK.PlayESCallBack(ESCallBack);
                //bool ret = CHCNetSDK.NET_DVR_SetESRealPlayCallBack(m_lRealHandle, eSCallBack, IntPtr.Zero);
                Task task = Task.Factory.StartNew(HIKDataInput);
            }
            Console.Read();
        }
        /// <summary>
        /// 远程开门
        /// </summary>
        /// <param name="message">返回信息</param>
        /// <param name="dwStatic">开/关门</param>
        /// <param name="deviceIPAddr">设备 IP 地址</param>
        /// <param name="devicePort">设备服务端口</param>
        /// <param name="gatewayIdx">门禁序号</param>
        /// <param name="user">登录用户名</param>
        /// <param name="password">登录密码</param>
        /// <returns></returns>
        private bool RemoteControlGateway(
            out string message,
            DwStatic dwStatic,
            string deviceIPAddr,
            int devicePort,
            int gatewayIdx,
            string user     = "******",
            string password = "******")
        {
            bool retFlag = false;
            uint errCode = 0;
            int  iUserId = -1;

            message = string.Empty;

            //初始化
            coreInfrastructure.NetDvrInit();

            //设置连接超时时间与重连功能
            //CHCNetSDK.NET_DVR_SetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);
            coreInfrastructure.NetDvrSetConnectTime(PreSettings.dwWaitTime, PreSettings.dwTryTimes);

            //CHCNetSDK.NET_DVR_SetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);
            coreInfrastructure.NetDvrSetReconnect(PreSettings.dwInterval, PreSettings.enableRecon);

            //CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            ////登录设备 Login the device
            //iUserId = coreInfrastructure.NetDvrLoginV30(deviceIPAddr, devicePort, user, password, ref deviceInfo);

            CHCNetSDK.NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();

            //登录设备 Login the device
            iUserId = coreInfrastructure.NetDvrLoginV40(deviceIPAddr, devicePort, user, password, ref struDeviceInfoV40);

            if (iUserId < 0)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();            //CHCNetSDK.NET_DVR_GetLastError();
                message = "NET_DVR_Login_V30 failed, error code= " + errCode; //登录失败,输出错误号
                //CHCNetSDK.NET_DVR_Cleanup();
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            retFlag = logicControlGateway.ControlGateway(iUserId, gatewayIdx, Convert.ToUInt32(dwStatic));

            if (!retFlag)
            {
                errCode = coreInfrastructure.NetDvrGetLastError();                                               //CHCNetSDK.NET_DVR_GetLastError();
                message = "NET_DVR_ControlGateway failed (" + dwStatic.ToString() + "), error code= " + errCode; //开启失败,输出错误号
                //注销用户
                //CHCNetSDK.NET_DVR_Logout(iUserId);
                coreInfrastructure.NetDvrLogoutV30(iUserId);
                //释放 SDK 资源
                //CHCNetSDK.NET_DVR_Cleanup();
                coreInfrastructure.NetDvrCleanUp();
                return(false);
            }

            System.Threading.Thread.Sleep(PreSettings.durationCallback);
            //注销用户
            //CHCNetSDK.NET_DVR_Logout(iUserId);
            coreInfrastructure.NetDvrLogout(iUserId);
            //释放 SDK 资源
            //CHCNetSDK.NET_DVR_Cleanup();
            coreInfrastructure.NetDvrCleanUp();

            return(retFlag);
        }
Esempio n. 20
0
        public string XMLTransparent(string IpAddress, string UserName, string Password, ushort Port)
        {
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLoginInfo     = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            CHCNetSDK.NET_DVR_DEVICEINFO_V40  struDeviceInfoV40 = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            struDeviceInfoV40.struDeviceV30.sSerialNumber = new byte[CHCNetSDK.SERIALNO_LEN];

            struLoginInfo.bUseAsynLogin  = false;
            struLoginInfo.sDeviceAddress = IpAddress;
            struLoginInfo.sUserName      = UserName;
            struLoginInfo.sPassword      = Password;
            struLoginInfo.wPort          = Port;

            //string url = "GET /ISAPI/System/time";
            string url    = "POST /ISAPI/AccessControl/UserInfo/Search?format=json";
            int    userID = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref struDeviceInfoV40);

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT pInputXml = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();
            Int32 nInSize = Marshal.SizeOf(pInputXml);

            pInputXml.dwSize = (uint)nInSize;

            // add request url
            string strRequestUrl   = url;
            uint   dwRequestUrlLen = (uint)strRequestUrl.Length;

            pInputXml.lpRequestUrl    = Marshal.StringToHGlobalAnsi(strRequestUrl);
            pInputXml.dwRequestUrlLen = dwRequestUrlLen;
            //

            var userInfoSearchCond = new { searchID = "1", searchResultPosition = 0, maxResults = 100 };

            //string userInfo1 = JsonConvert.SerializeObject(userInfoSearchCond);
            var    json    = new { UserInfoSearchCond = userInfoSearchCond };
            string jsonStr = JsonConvert.SerializeObject(json); //convert object -> string

            Console.WriteLine(jsonStr);

            // add input parameters
            string strInputParam = jsonStr;

            pInputXml.lpInBuffer     = Marshal.StringToHGlobalAnsi(strInputParam);
            pInputXml.dwInBufferSize = (uint)strInputParam.Length;
            //

            // reserve space for return data
            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT pOutputXml = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
            pOutputXml.dwSize          = (uint)Marshal.SizeOf(pInputXml);
            pOutputXml.lpOutBuffer     = Marshal.AllocHGlobal(3 * 1024 * 1024);
            pOutputXml.dwOutBufferSize = 3 * 1024 * 1024;
            pOutputXml.lpStatusBuffer  = Marshal.AllocHGlobal(4096 * 4);
            //pOutputXml.dwStatusSize = 4096 * 4;
            //

            if (!NET_DVR_STDXMLConfig(userID, ref pInputXml, ref pOutputXml))
            {
                uint   iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string strErr   = "NET_DVR_STDXMLConfig failed, error code= " + iLastErr;
                // Failed to send XML data and output the error code
                Console.WriteLine(strErr);
            }

            string strOutputParam = Marshal.PtrToStringAnsi(pOutputXml.lpOutBuffer);
            //Console.WriteLine("Output param: {0}", strOutputParam); // display in json format in console
            string outXML = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(strOutputParam));
            //Console.WriteLine("XML Output:\n" + outXML);
            string outStatus = Marshal.PtrToStringAnsi(pOutputXml.lpStatusBuffer);
            //Console.WriteLine("Status Output:\n" + outStatus);

            dynamic json2 = JsonConvert.DeserializeObject(outXML);//conver string -> object
            //Console.WriteLine("response status str: {0}", json2.UserInfoSearch.responseStatusStrg);
            JArray UserInfoList = json2.UserInfoSearch.UserInfo;



            foreach (dynamic userInfo in UserInfoList)
            {
                //Console.WriteLine(userInfo);
                dynamic param = userInfo;
                Console.WriteLine("employeeNo: {0}", param.employeeNo);
                Console.WriteLine("employeeName: {0}", param.name);
                Console.WriteLine("employeeType: {0}", param.userType);
                dynamic param2 = param.Valid;
                Console.WriteLine("begiTime: {0}", param2.beginTime);


                Console.WriteLine("password: {0}", param.password);
            }

            Marshal.FreeHGlobal(pInputXml.lpRequestUrl);
            Marshal.FreeHGlobal(pOutputXml.lpOutBuffer);
            Marshal.FreeHGlobal(pOutputXml.lpStatusBuffer);

            return(strOutputParam);
        }