Exemplo n.º 1
0
        List <Guid> noLoginStreamMediaList = null;//尚未登录成功的流媒体设备
        private void Login()
        {
            //登录设备
            StreamMediaListRepository repo            = new StreamMediaListRepository();
            List <StreamMediaList>    streamMediaList = repo.GetList();

            if (noLoginStreamMediaList == null)
            {
                noLoginStreamMediaList = streamMediaList.Select(_ => _.DeviceID).ToList();
            }
            streamMediaList.FindAll(f => noLoginStreamMediaList.Contains(f.DeviceID)).ForEach(_ =>
            {
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                int m_lUserID = CHCNetSDK.NET_DVR_Login_V30(_.VideoIP, _.Port, _.UserName, _.PassWord, ref deviceInfo);
                if (m_lUserID >= 0)
                {
                    //登录成功
                    UserID_m_lAlarmHandle temp_UserID_m_lAlarmHandle = new UserID_m_lAlarmHandle(m_lUserID, -1, deviceInfo);
                    if (!Device_UserID_Alarm.Keys.Contains(_.VideoIP))
                    {
                        Device_UserID_Alarm.Add(_.VideoIP, temp_UserID_m_lAlarmHandle);
                    }
                    noLoginStreamMediaList.Remove(_.DeviceID);
                }
            });
        }
Exemplo n.º 2
0
        private void LoginAllbutton(ref DevInfo dev, ref Int32 userID, ToolStripMenuItem toolStripMenuItem, ToolStripMenuItem ifActivateLive)
        {
            string DVRIPAddress  = dev.getIP();                //设备IP地址或者域名
            Int16  DVRPortNumber = Int16.Parse(dev.getPort()); //设备服务端口号
            string DVRUserName   = dev.getUserID();            //设备登录用户名
            string DVRPassword   = dev.getPassword();          //设备登录密码

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            userID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
            if (userID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号
                MessageBox.Show(str);

                return;
            }
            else
            {
                //登录成功
                string tmp = dev.getIP() + "login success!";
                toolStripMenuItem.Text = "Logout";
                if (!IsActivatedLiveAll)
                {
                    IsActivatedLiveAll = IfactivateLiveAll(IsActivatedLiveAll);
                }

                ArgsEvent(tmp);
                ifActivateLive.Enabled = true;
                return;
            }
        }
Exemplo n.º 3
0
        private bool LoginDevice()
        {
            string DVRIPAddress  = "192.168.0.68";
            Int16  DVRPortNumber = 8000;
            string DVRUserName   = "******";
            string DVRPassword   = "******";

            try
            {
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                m_userId = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref m_struDeviceInfo);
                if (-1 == m_userId)
                {
                    m_iErrorCode = CHCNetSDK.NET_DVR_GetLastError();
                    Log.GetLogger().ErrorFormat("NET_DVR_Login_V30 failed, error code = {0}", m_iErrorCode);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().InfoFormat("LoginDevice catch an error : {0}", e.Message);
                return(false);
            }

            Log.GetLogger().InfoFormat("LoginDevice return {0}", m_userId.ToString());
            return(true);
        }
Exemplo n.º 4
0
        int deviceLogin(string DVRIPAddress, string DVRPortNumber, string DVRUserName, string DVRPassword)
        {
            if (iDeviceNumber >= 20)
            {
                //MessageBox.Show("本程序限制最多添加20台设备!");
                //return;
            }
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, int.Parse(DVRPortNumber), DVRUserName, DVRPassword, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
                DebugInfo(strErr);
                return(m_lUserID);
            }
            else
            {
                DebugInfo("NET_DVR_Login_V30 succ!");
                //登录成功
                iDeviceNumber++;
                string str1 = "" + m_lUserID;
                //将已注册设备添加进列表
                //DebugInfo("NET_DVR_Login_V30 succ!");
                //btnLogin.Text = "Logout";

                return(m_lUserID);
            }
        }
Exemplo n.º 5
0
        //正在录像的文件

        /// <summary>
        /// 设备登录
        /// </summary>
        public static void LogIn()
        {
            CHCNetSDK.NET_DVR_Init();
            //登录设备
            for (int i = 0; i < Class1.streamMediaList.Count; i++)
            {
                string IPAddress  = Class1.streamMediaList[i].VideoIP;  //设备IP地址或者域名
                int    PortNumber = Class1.streamMediaList[i].Port;     //设备服务端口号
                string UserName   = Class1.streamMediaList[i].UserName; //设备登录用户名
                string Password   = Class1.streamMediaList[i].PassWord; //设备登录密码

                CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

                //登录设备 Login the device
                int m_lUserID = CHCNetSDK.NET_DVR_Login_V30(IPAddress, PortNumber, UserName, Password, ref DeviceInfo);
                if (m_lUserID < 0)
                {
                }
                else
                {
                    //登录成功
                    Console.WriteLine("Login Success!");
                    if (!userIDList.Keys.Contains(IPAddress))
                    {
                        userIDList.Add(IPAddress, m_lUserID);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// 1.初始化SDK
        /// 2.设置回调函数
        /// 3.用户注册
        /// 4.配置报警条件
        /// 5.报警布防
        /// 6.报警函数里面接收和处理数据
        /// 7.报警撤防
        /// 8.注销用户
        /// 9.释放SDK资源
        ///
        ///
        ///

        //设备注册-用户登录

        ///

        /// <summary>
        /// 设备注册-用户登录
        /// </summary>
        /// <param name="sDVRIP">登录IP</param>
        /// <param name="wDVRPort">端口</param>
        /// <param name="sUserName">用户名</param>
        /// <param name="sPassword">密码</param>
        /// <returns>返回值小于0登录注册失败</returns>
        public int RegisterDevice(string sDVRIP, Int32 wDVRPort, string sUserName, string sPassword)
        {
            //设备信息输出参数
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();



            int m_lUserID = CHCNetSDK.NET_DVR_Login_V30(sDVRIP, wDVRPort, sUserName, sPassword, ref DeviceInfo);

            if (m_lUserID < 0)
            {
                MessageBox.Show("登陆失败");
                return(-1);
            }



            //4.5.启用布防设置布防条件
            CHCNetSDK.NET_DVR_SETUPALARM_PARAM structSetUpParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
            structSetUpParam.dwSize          = (uint)Marshal.SizeOf(structSetUpParam);
            structSetUpParam.byLevel         = 1; //布防优先级:0-一级(高) ,1- 二等级(中)
            structSetUpParam.byAlarmInfoType = 1; //上传报警信息类型 1- 新报警信息(NET_ITS_PLATE_RESULT)

            int lhandle = CHCNetSDK.NET_DVR_SetupAlarmChan_V41(m_lUserID, ref structSetUpParam);

            if (lhandle < 0)
            {
                MessageBox.Show("布防失败");
                return(-1);
            }
            return(m_lUserID);//返回用户登陆成功句柄
        }
Exemplo n.º 7
0
        public bool Login(string ip, int port, string userName, string pwd)
        {
            string DVRIPAddress  = ip;       //设备IP地址或者域名
            int    DVRPortNumber = port;     //设备服务端口号
            string DVRUserName   = userName; //设备登录用户名
            string DVRPassword   = pwd;      //设备登录密码

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string str = "摄像头打开失败,错误号= " + iLastErr; //登录失败,输出错误号

                //MessageBox.Show(str);
            }
            else
            {
                Status = 1;
                InitShowStr();
                InitError();
                //登录成功  //MessageBox.Show("Login Success!");
                return(true);
            }
            Status = 0;
            return(false);
        }
Exemplo n.º 8
0
        // Sending preset to camera
        private void Preset(Camera Camera, UInt32 PreSetNo)
        {
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(Camera.DVRIPAddress, Camera.DVRPortNumber, Camera.DVRUserName, Camera.DVRPassword, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                label1.Text += "login err ";
                Log(Camera.DVRIPAddress + "\tlogin err");
            }
            else
            {
                if (!CHCNetSDK.NET_DVR_PTZPreset_Other(m_lUserID, 1, CHCNetSDK.GOTO_PRESET, (UInt32)(PreSetNo)))
                {
                    label1.Text += "set err ";
                    Log(Camera.DVRIPAddress + "\tset err");
                }
                else
                {
                    label1.Text += "ok ";
                    Log(Camera.DVRIPAddress + "\t" + PreSetNo.ToString());
                }
                if (!CHCNetSDK.NET_DVR_Logout(m_lUserID))
                {
                    label1.Text += "logout err ";
                    Log(Camera.DVRIPAddress + "\tlogout err");
                    m_lUserID = -1;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="DVRIPAddress">设备ip</param>
        /// <param name="DVRPortNumber">设备ip</param>
        /// <param name="DVRUserName">用户名</param>
        /// <param name="DVRPassword">用户密码</param>
        /// <returns>-1表示失败,其他值表示返回的用户ID值。该用户ID具有唯一性,后续对设备的操作都需要通过此ID实现。</returns>
        public static int LoginV30(string DVRIPAddress, ushort DVRPortNumber, string DVRUserName, string DVRPassword)
        {
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            int m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref m_struDeviceInfo);

            return(m_lUserID);
        }
Exemplo n.º 10
0
        public int LoginCamera(CameraInfo cameraInfo)
        {
            string DVRIPAddress  = cameraInfo.CameraIp;    //设备IP地址或者域名 Device IP
            Int16  DVRPortNumber = (Int16)cameraInfo.Port; //设备服务端口号 Device Port
            string DVRUserName   = cameraInfo.User;        //设备登录用户名 User name to login
            string DVRPassword   = cameraInfo.Password;    //设备登录密码 Password to login

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            Int32 lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);

            if (lUserID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
                return(-1);
            }
            else
            {
                //登录成功
                cameraInfo.UserNum = lUserID;
                m_cameraInfos.Add(cameraInfo);
                return(1);
            }
        }
Exemplo n.º 11
0
        public ORespuesta LoginHikvision()
        {
            ORespuesta _Respuesta = new ORespuesta();

            CHCNetSDK.NET_DVR_Init();
            CHCNetSDK.NET_DVR_SetConnectTime(2000, 1);
            CHCNetSDK.NET_DVR_SetReconnect(10000, 1);
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            string ip       = this.IP;
            ushort port     = this.Puerto;
            string user     = this.Usuario;
            string password = this.Password;

            this.HUserID = CHCNetSDK.NET_DVR_Login_V30(ip, port, user, password, ref struDeviceInfo);
            if (this.HUserID < 0)
            {
                _Respuesta.Mensaje = string.Format("Error en Login");
                _Respuesta.Error   = CHCNetSDK.NET_DVR_GetLastError();
                CHCNetSDK.NET_DVR_Cleanup();
                this.HUserID = 0;
                return(_Respuesta);
            }
            for (int i = 1; i <= Convert.ToInt32(struDeviceInfo.byChanNum); i++)
            {
                this.Canales.Add(i);
            }                                                                                             //Se extraen los canales del dispositivo
            _Respuesta.Exitoso = true;
            return(_Respuesta);
        }
Exemplo n.º 12
0
        public bool LoginDVR()
        {
            bool statue = true;

            if (DVRIPAddress.Equals("") || DVRUserName.Equals("") || DVRPassword.Equals(""))
            {
                MessageBox.Show("配置不正确,请设置IP、端口号、用户名和密码!");
                statue = false;
            }

            if (m_lUserID < 0)
            {
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

                //登录设备 Login the device
                m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
                if (m_lUserID < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    msgErr   = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号
                    MessageBox.Show(msgErr);
                    statue = false;
                }
            }

            return(statue);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 登录海康设备
        /// </summary>
        /// <param name="ip">设备IP</param>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="port">端口</param>
        /// <param name="userId">输出参数,登录id</param>
        /// <returns></returns>
        public static bool LoginHikDevice(string ip, string username, string password, int port, out int userId)
        {
            userId = -1;
            uint errorCode = 0;

            if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || port <= 0)
            {
                Log.GetLogger().ErrorFormat("LoginHikDevice fail,传入参数为空值");
                return(false);
            }

            try
            {
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                userId = CHCNetSDK.NET_DVR_Login_V30(ip, port, username, password, ref m_struDeviceInfo);
                if (-1 == userId)
                {
                    errorCode = CHCNetSDK.NET_DVR_GetLastError();
                    Log.GetLogger().ErrorFormat("NET_DVR_Login_V30 failed, error code = {0}", errorCode);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().ErrorFormat("catch an error : {0}", e.Message);
                return(false);
            }

            return(true);
        }
Exemplo n.º 14
0
        public void setAlarm(string ip, string port, string name, string password)
        {
            if (ip == "" || port == "" || name == "" || password == "")
            {
                return;
            }
            string DVRIPAddress  = ip;                //设备IP地址或者域名 Device IP
            Int16  DVRPortNumber = Int16.Parse(port); //设备服务端口号 Device Port
            string DVRUserName   = name;              //设备登录用户名 User name to login
            string DVRPassword   = password;          //设备登录密码 Password to login

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
            if (m_lUserID >= 0)
            {
                //登录成功

                CHCNetSDK.NET_DVR_SETUPALARM_PARAM struAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
                struAlarmParam.dwSize          = (uint)Marshal.SizeOf(struAlarmParam);
                struAlarmParam.byLevel         = 1;                                                                   //0- 一级布防,1- 二级布防
                struAlarmParam.byAlarmInfoType = 1;                                                                   //智能交通设备有效,新报警信息类型
                m_lAlarmHandle[m_lUserID]      = CHCNetSDK.NET_DVR_SetupAlarmChan_V41(m_lUserID, ref struAlarmParam); //布防
                if (m_lAlarmHandle[m_lUserID] >= 0)
                {
                    //布防成功
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 登录摄像机
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="port"></param>
        /// <param name="userAccount"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool Login(string ipAddress, int port, string userAccount, string password)
        {
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(ipAddress, port, userAccount, password, ref DeviceInfo);
            return(m_lUserID >= 0);
        }
Exemplo n.º 16
0
        public bool ConnectCamera(string deviceIP, int port, string userName, string password)
        {
            initSDK = CHCNetSDK.NET_DVR_Init();
            if (initSDK == false)
            {
                lastErr      = CHCNetSDK.NET_DVR_GetLastError();
                debugMessage = "初始化过程失败, 错误码: " + lastErr;

                err = true;
                return(false);
            }
            else
            {
                CHCNetSDK.NET_DVR_SetLogToFile(3, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SdkLog\\"), true);
            }

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();


            userID = CHCNetSDK.NET_DVR_Login_V30(deviceIP, port, userName, password, ref DeviceInfo);
            if (userID < 0)
            {
                lastErr      = CHCNetSDK.NET_DVR_GetLastError();
                debugMessage = "注册失败, 错误码:" + lastErr;
                err          = true;

                return(false);
            }


            Isconnected = true;
            return(true);
        }
Exemplo n.º 17
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            if (txtDeIP.Text == "" || txtDePortNum.Text == "" ||
                txtUser.Text == "" || txtPwd.Text == "")
            {
                MessageBox.Show("Please input IP, Port, User name and Password!");
                return;
            }
            string DVRIPAddress  = txtDeIP.Text;                   //设备IP地址或者域名 Device IP
            Int16  DVRPortNumber = Int16.Parse(txtDePortNum.Text); //设备服务端口号 Device Port
            string DVRUserName   = txtUser.Text;                   //设备登录用户名 User name to login
            string DVRPassword   = txtPwd.Text;                    //设备登录密码 Password to login

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                string strErr = "NET_DVR_Login_V30 failed, error code= " + CHCNetSDK.NET_DVR_GetLastError(); //登录失败,输出错误号 Failed to login and output the error code
                MessageBox.Show(strErr);
                return;
            }
            else
            {
                MessageBox.Show("登录成功!");
                btnLogin.Enabled  = false;
                btnCancel.Enabled = true;
            }
        }
Exemplo n.º 18
0
        public int camera_Login(string HKCameraip, string HKCameraUsername, string HKCameraPassword)
        {
            string DVRIPAddress  = HKCameraip;          //设备IP地址或者域名 Device IP
            Int16  DVRPortNumber = Int16.Parse("8000"); //设备服务端口号 Device Port
            string DVRUserName   = HKCameraUsername;    //设备登录用户名 User name to login
            string DVRPassword   = HKCameraPassword;    //设备登录密码 Password to login

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
                Log.WriteLog(DateTime.Now + " 摄像机登录失败\r\n" + iLastErr + "\r\n");
                return(-3);
            }
            else
            {
                //登录成功
                iDeviceNumber++;
                string str1 = "" + m_lUserID;
                return(0);
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// preview camera
 /// 1.inint sdk
 /// 2.login cameera
 /// 3.preview
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lookBtn_Click(object sender, RoutedEventArgs e)
 {
     isInitSDK = CameraHelper.InitSDK();
     if (isInitSDK)
     {
         CHCNetSDK.NET_DVR_DEVICEINFO_V30 info = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
         currCameraId = CameraHelper.loginCamera(this.IpTB.Text.Trim(), this.portTB.Text.Trim(), this.userNameTB.Text.Trim(), this.pwdTB.Text.Trim(), ref info);
         if (currCameraId >= 0)
         {
             System.Windows.Forms.PictureBox pb = this.previewFormsHost.Child as System.Windows.Forms.PictureBox;
             int chanlnum = (int)info.byChanNum;
             isPreviewSuccess = CameraHelper.Preview(ref pb, chanlnum, currCameraId);
             if (isPreviewSuccess)
             {
                 MessageBox.Show("预览成功!");
             }
             else
             {
                 MessageBox.Show("预览失败!");
             }
         }
     }
     else
     {
         MessageBox.Show("init failure");
     }
     switchBtnVisbility();
 }
Exemplo n.º 20
0
 /// <summary>
 /// 注册用户到设备的扩展接口,支持一个用户指定设备支持的能力
 /// </summary>
 /// <param name="pchDVRIP">设备IP</param>
 /// <param name="wDVRPort">设备端口</param>
 /// <param name="pchUserName">用户名</param>
 /// <param name="pchPassword">用户密码</param>
 /// <param name="nSpecCap">设备支持的能力,值为2表示主动侦听模式下的用户登录。[车载dvr登录]</param>
 /// <param name="pCapParam">对nSpecCap 的补充参数, nSpecCap = 2时,pCapParam填充设备序列号字串。[车载dvr登录]</param>
 /// <param name="lpDeviceInfo">设备信息,属于输出参数</param>
 /// <param name="error">返回登录错误码</param>
 /// <returns>返回0,成功返回,</returns>
 public int Login(string pchDVRIP, ushort wDVRPort, string pchUserName, string pchPassword, int nSpecCap, string pCapParam)
 {
     CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
     //NET_DVR_DEVICEINFO nET = new NET_DVR_DEVICEINFO() { };
     m_lLogin = CHCNetSDK.NET_DVR_Login_V30(pchDVRIP, wDVRPort, pchUserName, pchPassword, ref deviceInfo);
     //m_lLogin = SDK_Login(pchDVRIP, wDVRPort, pchUserName, pchPassword, out m_lpDeviceInfo, out error, nSpecCap, pCapParam);
     return(m_lLogin);
 }
Exemplo n.º 21
0
        public void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;

            #region
            if (m_lUserID < 0)
            {
                string DVRIPAddress  = "192.168.1.64";      //设备IP地址或者域名
                Int16  DVRPortNumber = Int16.Parse("8000"); //设备服务端口号
                string DVRUserName   = "******";             //设备登录用户名
                string DVRPassword   = "******";          //设备登录密码
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                //登录设备 Login the device
                m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
                if (m_lUserID < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号
                    MessageBox.Show(str);
                    return;
                }
                else
                {
                    btn.Content = "注销";
                    ShowVideo();
                }
            }
            else
            {
                //停止预览 Stop live view
                if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_StopRealPlay failed, error code= " + iLastErr;
                    MessageBox.Show(str);
                    return;
                }
                m_lRealHandle = -1;

                //注销登录 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;

                btn.Content = "登录";
            }
            #endregion
        }
Exemplo n.º 22
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            if (textBoxIP.Text == "" || textBoxPort.Text == "" ||
                textBoxUserName.Text == "" || textBoxPassword.Text == "")
            {
                MessageBox.Show("请输入IP, 端口,用户名,密码!");
                return;
            }//查看是否补全
            if (m_lUserID < 0)//未进行登录
            {
                string DVRIPAddress  = textBoxIP.Text;                                                //设备IP地址或者域名
                Int16  DVRPortNumber = Int16.Parse(textBoxPort.Text);                                 //设备服务端口号
                string DVRUserName   = textBoxUserName.Text;                                          //设备登录用户名
                string DVRPassword   = textBoxPassword.Text;                                          //设备登录密码

                CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30(); //设备

                //登录设备 Login the device
                m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
                if (m_lUserID < 0)//尝试登陆失败
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号
                    MessageBox.Show(str);
                    return;
                }
                else
                {
                    //登录成功
                    MessageBox.Show("Login Success!");
                    btnLogin.Text = "Logout";
                }
            }
            if (m_lRealHandle < 0)
            {
                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                lpPreviewInfo.hPlayWnd        = RealPlayWnd.Handle; //预览窗口
                lpPreviewInfo.lChannel        = Int16.Parse("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 = 15;                 //播放库播放缓冲区最大缓冲帧数

                //CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);//预览实时流回调函数
                IntPtr pUser = new IntPtr();//用户数据

                //打开预览
                m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser);
                if (m_lRealHandle < 0)//不能打开预览
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; //预览失败,输出错误号
                    MessageBox.Show(str);
                    return;
                }
            }
        }
Exemplo n.º 23
0
        private bool fff(string ip, int port, string username, string password, int channel, DateTime startTime, DateTime endTime)
        {
            var initFlag = CHCNetSDK.NET_DVR_Init();

            //返回值为布尔值 fasle初始化失败
            if (!initFlag)
            {
                //log.warn("hksdk(视频)-海康sdk初始化失败!");
                return(false);
            }

            var deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            var userId     = CHCNetSDK.NET_DVR_Login_V30(ip, (short)port, username, password, ref deviceInfo);

            //log.info("hksdk(视频)-登录海康录像机信息,状态值:" + hCNetSDK.NET_DVR_GetLastError());
            if (userId == -1)
            {
                //log.warn("hksdk(视频)-海康sdk登录失败!");
                return(false);
            }

            var st = DateTimeToNETDVRTIME(startTime);
            var et = DateTimeToNETDVRTIME(endTime);

            var playHandle = CHCNetSDK.NET_DVR_PlayBackByTime(userId, channel, ref st, ref et, IntPtr.Zero);//new WindowInteropHelper(this).Handle

            if (playHandle < 0)
            {
                var d = CHCNetSDK.NET_DVR_GetLastError();

                CHCNetSDK.NET_DVR_Logout(userId);
                CHCNetSDK.NET_DVR_Cleanup();
                return(false);
            }

            if (!CHCNetSDK.NET_DVR_SetPlayDataCallBack(playHandle, PlayDataCallback, 0))
            {
                CHCNetSDK.NET_DVR_Logout(userId);
                CHCNetSDK.NET_DVR_Cleanup();
                return(false);
            }

            uint pos = 0;

            if (!CHCNetSDK.NET_DVR_PlayBackControl(playHandle, CHCNetSDK.NET_DVR_PLAYSTART, 0, ref pos))
            {
                //printf("play back control failed [%d]\n", NET_DVR_GetLastError());
                CHCNetSDK.NET_DVR_Logout(userId);
                CHCNetSDK.NET_DVR_Cleanup();
                return(false);
            }



            return(true);
        }
Exemplo n.º 24
0
        /// <summary>
        /// 注册设备
        /// </summary>
        /// <returns>-1注册失败,否则注册成功</returns>
        public override void Login(DeviceInfo device)
        {
            string deviceIp      = device.deviceIp;
            int    devicePort    = device.devicePort;
            string loginName     = device.userName;
            string loginPassword = device.userPwd;

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            device.loginId = CHCNetSDK.NET_DVR_Login_V30(deviceIp, devicePort, loginName, loginPassword, ref deviceInfo);
        }
Exemplo n.º 25
0
        private void btnLogin_Click(object sender, System.EventArgs e)
        {
            if (textBoxIP.Text == "" || textBoxPort.Text == "" ||
                textBoxUserName.Text == "" || textBoxPassword.Text == "")
            {
                MessageBox.Show("请输入正确的IP地址,端口号,用户名和密码。");
                return;
            }
            if (m_lUserID < 0)
            {
                string DVRIPAddress  = textBoxIP.Text;                //设备IP地址或者域名
                Int16  DVRPortNumber = Int16.Parse(textBoxPort.Text); //设备服务端口号
                string DVRUserName   = textBoxUserName.Text;          //设备登录用户名
                string DVRPassword   = textBoxPassword.Text;          //设备登录密码

                CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

                //登录设备 Login the device
                m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
                if (m_lUserID < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //登录失败,输出错误号
                    MessageBox.Show(str);

                    return;
                }
                else
                {
                    //登录成功
                    MessageBox.Show("登录成功!");
                    btnLogin.Text = "注销";
                }
            }
            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 = "登录";
            }
            return;
        }
Exemplo n.º 26
0
        // Asynchronous callback function
        public void AsynLoginMsgCallback(Int32 lUserID, UInt32 dwResult, ref CHCNetSDK.NET_DVR_DEVICEINFO_V30 lpDeviceInfo, IntPtr pUser)
        {
            if (dwResult == 1)
            {
                m_struDeviceInfo = lpDeviceInfo;
            }

            m_AysnLoginResult = dwResult;
            m_iUserID         = lUserID;
            LoginCallBackFlag = true;
        }
Exemplo n.º 27
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[m_lUserID_flag] < 0)
            {
                string DVRIPAddress  = textBoxIP.Text;                //É豸IPµØÖ·»òÕßÓòÃû
                Int16  DVRPortNumber = Int16.Parse(textBoxPort.Text); //É豸·þÎñ¶Ë¿ÚºÅ
                string DVRUserName   = textBoxUserName.Text;          //É豸µÇ¼Óû§Ãû
                string DVRPassword   = textBoxPassword.Text;          //É豸µÇ¼ÃÜÂë

                CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

                //µÇ¼É豸 Login the device
                m_lUserID[m_lUserID_flag] = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
                if (m_lUserID[m_lUserID_flag] < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Login_V30 failed, error code= " + iLastErr; //µÇ¼ʧ°Ü£¬Êä³ö´íÎóºÅ
                    MessageBox.Show(str);
                    return;
                }
                else
                {
                    //µÇ¼³É¹¦
                    MessageBox.Show("Login Success!");
                    btnLogin.Text = "Í˳ö";
                }
            }
            else
            {
                //×¢ÏúµÇ¼ Logout the device
                if (m_lRealHandle[m_lRealHandle_flag] >= 0)
                {
                    MessageBox.Show("Please stop live view firstly");
                    return;
                }

                if (!CHCNetSDK.NET_DVR_Logout(m_lUserID[m_lUserID_flag]))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_Logout failed, error code= " + iLastErr;
                    MessageBox.Show(str);
                    return;
                }
                m_lUserID[m_lUserID_flag] = -1;
                btnLogin.Text             = "怬";
            }
            return;
        }
Exemplo n.º 28
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <returns>操作结果</returns>
        public OperatedResult Login()
        {
            if (LoginStatus)
            {
                return(OperatedResult.Fail("已经处于登陆状态,不能进行登陆操作."));
            }

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 _deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            UserId = CHCNetSDK.NET_DVR_Login_V30(VideoIPEndPoint.Address.ToString(), VideoIPEndPoint.Port, UserName, PassWord, ref _deviceInfo);
            return(LoginStatus == true?OperatedResult.Success() : OperatedResult.Fail(LastErrorMessage));
        }
Exemplo n.º 29
0
        /// <summary>
        /// 设备登陆
        /// </summary>
        /// <param name="devIp"></param>
        /// <param name="devPort"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private DevLoginModel DeviceLogin(string devIp, int devPort, string userName, string password)
        {
            string loginUserKey = GetDeviceLoginUserDictKey(devIp, devPort, userName, password);

            //设备已经登陆,择直接返回登陆id,并增加1此登陆的订阅数
            if (_loginedDeviceDict.ContainsKey(loginUserKey))
            {
                _loginedDeviceDict[loginUserKey].SubscriberCount++;
                return(_loginedDeviceDict[loginUserKey]);
            }

            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            int loginId = CHCNetSDK.NET_DVR_Login_V30(devIp, devPort, userName, password, ref DeviceInfo);

            if (loginId < 0)
            {
                uint lastErr = CHCNetSDK.NET_DVR_GetLastError();
                LogHelper.Default.Debug(string.Format("设备{0}-{1}登陆失败,错误代码[{2}]", devIp, devPort, lastErr));
                return(null);
            }

            //设置报警回调函数
            if (_msgCallback_V31 == null)
            {
                _msgCallback_V31 = new CHCNetSDK.MSGCallBack_V31(MsgCallback_V31);
            }

            RuntimeTypeHandle handle = GetType().TypeHandle;
            IntPtr            ptr    = handle.Value;

            if (!CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(_msgCallback_V31, ptr))
            {
                uint lastErr = CHCNetSDK.NET_DVR_GetLastError();
                LogHelper.Default.Debug(string.Format("设备{0}-{1}设置报警回调失败,错误代码[{2}]", devIp, devPort, lastErr));
            }

            CHCNetSDK.NET_DVR_SETUPALARM_PARAM setAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
            setAlarmParam.byAlarmInfoType = 1;
            setAlarmParam.byLevel         = 1;
            //布防
            long setAlarmHandle = CHCNetSDK.NET_DVR_SetupAlarmChan(loginId);

            DevLoginModel devLoginModel = new DevLoginModel();

            devLoginModel.Key             = loginUserKey;
            devLoginModel.LoginId         = loginId;
            devLoginModel.SubscriberCount = 1;

            _loginedDeviceDict.TryAdd(loginUserKey, devLoginModel);
            return(devLoginModel);
        }
Exemplo n.º 30
0
        public void Login(LoginInfo logininfo)
        {
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            loginUserId = CHCNetSDK.NET_DVR_Login_V30(logininfo.Ip, logininfo.Port, logininfo.UserName, logininfo.Password, ref DeviceInfo);

            if (loginUserId < 0)
            {
                //uint errNo = CHCNetSDK.NET_DVR_GetLastError();
                throw new Exception("[海康]登录失败" + GetErrorMessage());
            }
        }
Exemplo n.º 31
0
        public bool login()
        {
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            //登录设备 Login the device
            device.userID = CHCNetSDK.NET_DVR_Login_V30(device.IP, device.port, device.username, device.password, ref DeviceInfo);
            if (device.userID < 0)
            {
                uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string str = "NET_DVR_Login_V30 failed, error code= " + iLastErr + "!登录失败,请检查配置参数,并重新启动!"; //登录失败,输出错误号
                MessageBox.Show(str);
                return false;
            }
            return true;
        }