Exemplo n.º 1
0
        public int SignOutCamera()
        {
            if (m_lReadHandle >= 0)
            {
                LoggerService.logger.Info($"摄像IP:{ip} 请先停止预览!");
                return(-2);
            }

            if (!HKNetSDKS.NET_DVR_Logout(m_lUserId))
            {
                LoggerService.logger.Error($"摄像IP:{ip} 注销失败[{HKNetSDKS.NET_DVR_GetLastError()}]!");
                return(-3);
            }

            LoggerService.logger.Info($"摄像IP:{ip} 注销 成功!");

            m_lUserId = -1;

            if ((taskStartRealPlay != null) && (taskStartRealPlay.IsCompleted))
            {
                taskStartRealPlay = null;
            }

            Statue = CameraStatue.SignOut;

            return(0);
        }
Exemplo n.º 2
0
        public Camera(string ip, ushort port, string user, string pwd)
            : this()
        {
            this.Ip   = ip;
            this.port = port;
            this.user = user;
            this.pwd  = pwd;

            Statue = CameraStatue.SignOut;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据保存的ip地址,用户名,密码等信息
        /// </summary>
        public int SignCamera()
        {
            if (!this.checkSignParam())
            {
                //检测出用于登录的参数有问题
                return(-1);
            }

            //该摄像机未登录
            if (Statue == CameraStatue.SignOut)
            {
                //初始化登录信息结构体
                struLogInfo = new HKNetSDKS.NET_DVR_USER_LOGIN_INFO();

                //复制IP地址到结构体中
                byte[] byIp = System.Text.Encoding.Default.GetBytes(Ip);
                struLogInfo.sDeviceAddress = new byte[129];
                byIp.CopyTo(struLogInfo.sDeviceAddress, 0);

                //复制用户名到登录结构体中
                byte[] byUser = System.Text.Encoding.Default.GetBytes(user);
                struLogInfo.sUserName = new byte[64];
                byUser.CopyTo(struLogInfo.sUserName, 0);

                //复制登录密码到登录结构体中
                byte[] byPwd = System.Text.Encoding.Default.GetBytes(pwd);
                struLogInfo.sPassword = new byte[64];
                byPwd.CopyTo(struLogInfo.sPassword, 0);

                //复制端口号到登录结构体中
                struLogInfo.wPort = port;

                DeviceInfo = new HKNetSDKS.NET_DVR_DEVICEINFO_V40();

                //尝试登录设备,如果登录成功,则返回值会大于等于0,在这里使用的是同步登陆方式,会所在线程进进入阻塞状态
                m_lUserId = HKNetSDKS.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);

                //登录设备,并获取设备信息,当登录失败,该
                if (m_lUserId < 0)
                {
                    //获取错误代码,并返回改错误代码
                    LoggerService.logger.Error($"摄像IP:{ip} 登录失败[{HKNetSDKS.NET_DVR_GetLastError()}]!");
                    return((int)HKNetSDKS.NET_DVR_GetLastError());
                }
                //登录成功
                else
                {
                    Statue = CameraStatue.SignIn;

                    LoggerService.logger.Info($"摄像IP:{ip} 登录成功!");
                }
            }
            return(0);
        }
Exemplo n.º 4
0
        public async Task <int> StopRealPreview()
        {
            if (m_lReadHandle < 0)
            {
                LoggerService.logger.Error($"摄像头{ip},未启动过预览。");
                return(-1);
            }

            if (!HKNetSDKS.NET_DVR_StopRealPlay(m_lReadHandle))
            {
                LoggerService.logger.Error($"摄像头{ip},播放器无法停止预览。错误代码:{HKNetSDKS.NET_DVR_GetLastError()}");
            }

            if (m_lPort >= 0)
            {
                if (!HKPlayCtrlSDK.PlayM4_Stop(m_lPort))
                {
                    LoggerService.logger.Error($"摄像头{ip},播放器无法停止工作。错误代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                }

                if (!HKPlayCtrlSDK.PlayM4_CloseStream(m_lPort))
                {
                    LoggerService.logger.Error($"摄像头{ip},播放器无法关闭数据流。错误代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                }
                if (!HKPlayCtrlSDK.PlayM4_FreePort(m_lPort))
                {
                    LoggerService.logger.Error($"摄像头{ip},播放器无法释放播放端口。错误代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                }

                m_lPort = -1;
            }


            LoggerService.logger.Info($"摄像头{ip},已停止预览。");

            m_lReadHandle = -1;
            Statue        = CameraStatue.StopReadPlay;
            if (PictrueBoxId != null)
            {
                PictrueBoxId.Invalidate();
                PictrueBoxId = null;
            }
            return(0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 执行进行监控预览
        /// </summary>
        /// <returns>-2:启动预览错误;-1:设备未登录,0:执行正常</returns>
        public int RealPreview()
        {
            //如果设备未登录
            if (m_lUserId < 0)
            {
                LoggerService.logger.Info("请先登录该网络视频设备后再预览!");
                return(-1);
            }

            //如果没有创建过预览句柄
            //则进行预览设置
            if (m_lReadHandle < 0)
            {
                HKNetSDKS.NET_DVR_PREVIEWINFO lpPreviewInfo = new HKNetSDKS.NET_DVR_PREVIEWINFO();

                lpPreviewInfo.hPlayWnd        = IntPtr.Zero;
                lpPreviewInfo.lChannel        = ChannelNum;
                lpPreviewInfo.dwStreamType    = 0;    //主码流
                lpPreviewInfo.dwLinkMode      = 0;    //TCP方式
                lpPreviewInfo.bBlocked        = true; //阻塞式
                lpPreviewInfo.dwDisplayBufNum = 1;    //播放库显示缓存区最大的帧数

                IntPtr pUser = IntPtr.Zero;

                //RealDataCallBack回调函数,摄像头有每一帧的信息传过来后,当前的线程都会调用该函数,告诉解码器将视频流解码
                ReadData = new HKNetSDKS.REALDATACALLBACK(RealDataCallBack);

                //把海康预览的结构体放在函数里,根据结构体的信息,比如通信方式等等,跟摄像头通信,创建成功,则返回一个专门用来预览的资源句柄,相当于一个线程
                m_lReadHandle = HKNetSDKS.NET_DVR_RealPlay_V40(m_lUserId, ref lpPreviewInfo, ReadData, pUser);

                if (m_lReadHandle < 0)
                {
                    LoggerService.logger.Error($"摄像头{ip},启动预览失败,错误代码:{HKNetSDKS.NET_DVR_GetLastError()}");
                    return(-2);
                }
                else
                {
                    LoggerService.logger.Info($"摄像头{ip},启动预览成功!");
                    Statue = CameraStatue.OnReadPlay;
                }
            }

            return(0);
        }