Exemple #1
0
        private void btnSlow_Click(object sender, EventArgs e)
        {
            uint iOutValue = 0;

            if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(m_lPlayHandle, CHCNetSDK.NET_DVR_PLAYSLOW, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_PLAYSLOW failed, error code= " + iLastErr; //回放控制失败,输出错误号
                MessageBox.Show(str);
                return;
            }
        }
Exemple #2
0
        private void PreSetGet_Click(object sender, EventArgs e)
        {
            while (comboBox1.Text != "")
            {
                PreSetNo = comboBox1.Items.IndexOf(comboBox1.Text);
                UInt32 dwReturn     = 0;
                Int32  nSize        = Marshal.SizeOf(m_struPreSetCfg[PreSetNo]);
                Int32  nOutBufSize  = nSize * 300;
                IntPtr ptrPreSetCfg = Marshal.AllocHGlobal(nOutBufSize);
                int    i;
                for (i = 0; i < 300; i++)
                {
                    //m_struPreSetCfg[i] = new CHCNetSDK.NET_DVR_PRESET_NAME();

                    /* if (i == PreSetNo)
                     * {
                     *   textBoxPanPos1.Text = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wPanPos);
                     *   textBoxTiltPos1.Text = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wTiltPos);
                     *   textBoxZoomPos1.Text = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wZoomPos);
                     * }*/
                    Marshal.StructureToPtr(m_struPreSetCfg[i], (IntPtr)((Int32)(ptrPreSetCfg) + i * nSize), false);
                }
                //获取参数失败
                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PRESET_NAME, 1, ptrPreSetCfg, (UInt32)nOutBufSize, ref dwReturn))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_GetDVRConfig failed, error code= " + iLastErr;
                    MessageBox.Show(str);
                    return;
                }
                else
                {
                    for (i = 0; i < 300; i++)
                    {
                        m_struPreSetCfg[i] = (CHCNetSDK.NET_DVR_PRESET_NAME)Marshal.PtrToStructure((IntPtr)((Int32)(ptrPreSetCfg) + i * nSize), typeof(CHCNetSDK.NET_DVR_PRESET_NAME));
                    }
                    textBoxPanPos1.Text  = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wPanPos);
                    textBoxTiltPos1.Text = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wTiltPos);
                    textBoxZoomPos1.Text = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wZoomPos);
                    if (m_struPreSetCfg[PreSetNo].byName != null)
                    {
                        str = System.Text.Encoding.Default.GetString(m_struPreSetCfg[PreSetNo].byName);
                    }

                    PreSetName.Text = str;
                    MessageBox.Show("获取成功");
                }
                Marshal.FreeHGlobal(ptrPreSetCfg);
                return;
            }
            MessageBox.Show("please input the PtrPreSetNo");
        }
Exemple #3
0
        /// 视频录像
        private void recordbtn_Click(object sender, EventArgs e)
        {
            DateTime time = DateTime.Now;
            folder   data = new folder();

            data.Read();

            if (data.data[0] == "" || data.data[1] == "")
            {
                Information.Text += "请先指定录像存放目录!" + System.Environment.NewLine;
                return;
            }
            string src = data.data[1] + "/" + time.ToString("yyyy-MM-dd-hh-mm-ss") + ".mp4";

            if (recordbtn.Text == "视频录像")
            {
                bool result = CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, src);
                if (result == true)
                {
                    recordbtn.Text    = "停止录像";
                    Information.Text += "录像开始!" + System.Environment.NewLine;
                }
                else
                {
                    Information.Text += "录像失败!" + System.Environment.NewLine;
                    uint nError = CHCNetSDK.NET_DVR_GetLastError();
                    Information.Text += "发生错误,错误代码:" + nError + System.Environment.NewLine;
                    if (nError == 12)
                    {
                        Information.Text += "请先开启预览!" + System.Environment.NewLine;
                    }
                    else if (nError == 34)
                    {
                        Information.Text += "请检查录像存放目录!" + System.Environment.NewLine;
                    }
                }
            }
            else
            {
                if (CHCNetSDK.NET_DVR_StopSaveRealData(m_lRealHandle) == true)
                {
                    recordbtn.Text    = "视频录像";
                    Information.Text += "录像已保存到:" + src + System.Environment.NewLine;
                }
                else
                {
                    Information.Text += "结束录像失败!" + System.Environment.NewLine;
                    uint nError = CHCNetSDK.NET_DVR_GetLastError();
                    Information.Text += "发生错误,错误代码:" + nError + System.Environment.NewLine;
                }
            }
        }
Exemple #4
0
        private void previewBtn(Int32 userID, ref Int32 realHandler, PictureBox Wnd, ToolStripMenuItem contextMenuStrip, ToolStripMenuItem recordButton, string streamType)
        {
            if (realHandler >= 0)
            {
                if (!CHCNetSDK.NET_DVR_StopRealPlay(realHandler))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_StopRealPlay failed, error code= " + iLastErr;
                    MessageBox.Show(str);
                    return;
                }
                realHandler           = -1;
                contextMenuStrip.Text = "Live this";
                recordButton.Enabled  = false;
                Wnd.Refresh();
            }

            else
            {
                if (userID < 0)
                {
                    MessageBox.Show("Please login first");
                    return;
                }
                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                lpPreviewInfo.hPlayWnd = Wnd.Handle;                    //预览窗口
                //lpPreviewInfo.hPlayWnd = imageBoxShow.Handle;
                lpPreviewInfo.lChannel        = Int16.Parse(ichannel);  //预te览的设备通道
                lpPreviewInfo.dwStreamType    = uint.Parse(streamType); //码流类型: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();//用户数据

                //打开预览 Start live view
                realHandler = CHCNetSDK.NET_DVR_RealPlay_V40(userID, ref lpPreviewInfo,
                                                             null, pUser);
                ArgsEvent("Live view succeed.");
                contextMenuStrip.Text = "Stop living this";
                recordButton.Enabled  = true;
                if (realHandler < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; //预览失败,输出错误号
                    MessageBox.Show(str);
                    return;
                }
            }
        }
Exemple #5
0
        private void StartPreview()
        {
            if (m_lUserID < 0)
            {
                Console.WriteLine("[CCTV] - Access Error.");
                return;
            }

            if (m_lRealHandle < 0)
            {
                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                if (Pb_CCTV.InvokeRequired)
                {
                    Pb_CCTV.Invoke(new MethodInvoker(delegate {
                        lpPreviewInfo.hPlayWnd = Pb_CCTV.Handle;
                    }));
                }
                else
                {
                    lpPreviewInfo.hPlayWnd = Pb_CCTV.Handle;
                }

                lpPreviewInfo.lChannel        = 1;
                lpPreviewInfo.dwStreamType    = 0;
                lpPreviewInfo.dwLinkMode      = 1;
                lpPreviewInfo.bBlocked        = true;
                lpPreviewInfo.dwDisplayBufNum = 1;
                lpPreviewInfo.byProtoType     = 0;
                lpPreviewInfo.byPreviewMode   = 0;

                if (RealData == null)
                {
                    RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);
                }

                m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null, IntPtr.Zero);
                if (m_lRealHandle < 0)
                {
                    Console.WriteLine("[CCTV] - NET_DVR_RealPlay_V40 Failed : {0}", CHCNetSDK.NET_DVR_GetLastError());
                }
                else
                {
                    Console.WriteLine("[CCTV] - Start Preview.");
                    // Event Trigger
                    if (ModeListener != null)
                    {
                        ModeListener(MODE_PREVIEW);
                    }
                }
            }
            //SystemEnv.ShowLogMessage("[CCTV] - RealHandle : {0}", m_lRealHandle);
        }
Exemple #6
0
        /// <summary>
        /// 连接海康摄像机视频直播
        /// </summary>
        /// <param name="_iHikLoginHandle">海康摄像机登录句柄</param>
        public void ConnectVideoHik(int _iHikLoginHandle, int iChannel, string strName)
        {
            IntPtr pUser = new IntPtr();

            CHCNetSDK.NET_DVR_PREVIEWINFO struPlayInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
            struPlayInfo.hPlayWnd     = this.Handle; //需要SDK解码时句柄设为有效值,仅取流不解码时可设为空
            struPlayInfo.lChannel     = iChannel;    //预览通道号
            struPlayInfo.dwStreamType = 0;           //0-主码流,1-子码流,2-码流3,3-码流4,以此类推
            struPlayInfo.dwLinkMode   = 0;           //0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
            struPlayInfo.bBlocked     = true;        //0- 非阻塞取流,1- 阻塞取流
            m_iPlayHandle             = CHCNetSDK.NET_DVR_RealPlay_V40(_iHikLoginHandle, ref struPlayInfo, null, pUser);
            uint a = CHCNetSDK.NET_DVR_GetLastError();
        }
Exemple #7
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="ip">IP地址</param>
        /// <param name="port">端口</param>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        private Boolean Login(String ip, Int16 port, String userName, String password)
        {
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

            mUserId = CHCNetSDK.NET_DVR_Login_V30(ip, port, userName, password, ref deviceInfo);
            if (mUserId < 0)
            {
                Tracker.LogE("NET_DVR_Login_V30 failed, error code= " + CHCNetSDK.NET_DVR_GetLastError());
                return(false);
            }

            return(true);
        }
Exemple #8
0
 /// <summary>
 /// 停止播放
 /// </summary>
 /// <param name="boxHandle">图像显示控件</param>
 public uint StopPlay()
 {
     if (realHandle < -1)
     {
         return(1);
     }
     if (CHCNetSDK.NET_DVR_StopRealPlay(this.realHandle))
     {
         this.realHandle = -1; return(1000);
     }
     this.lastError = CHCNetSDK.NET_DVR_GetLastError();
     return(this.lastError);
 }
Exemple #9
0
        public string SearchCard(string IpAddress, string UserName, string Password, ushort Port)
        {
            Auth(IpAddress, UserName, Password, Port);

            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/CardInfo/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 cardInfoSearchCond = new { searchID = "0", searchResultPosition = 0, maxResults = 50 };
            var json    = new { CardInfoSearchCond = cardInfoSearchCond };
            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);
        }
        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);
                }
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (m_lUserID < 0)
            {
                string DVRIPAddress  = textBoxIP.Text;
                Int16  DVRPortNumber = Int16.Parse(textBoxPort.Text);
                string DVRUserName   = textBoxUserName.Text;
                string DVRPassword   = textBoxPassword.Text;

                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;
                    DebugInfo(str);
                    return;
                }
                else
                {
                    UserSave();


                    DebugInfo("NET_DVR_Login_V30 succ!");
                    btnLogin.Text = "Logout";

                    dwAChanTotalNum = (uint)DeviceInfo.byChanNum;
                    dwDChanTotalNum = (uint)DeviceInfo.byIPChanNum + 256 * (uint)DeviceInfo.byHighDChanNum;
                }
            }
            else
            {
                if (m_lRealHandle >= 0)
                {
                    DebugInfo("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;
                    DebugInfo(str);
                    return;
                }
                DebugInfo("NET_DVR_Logout succ!");

                m_lUserID     = -1;
                btnLogin.Text = "Login";
            }
            return;
        }
Exemple #12
0
        private void btnPreview_Click(object sender, System.EventArgs e)
        {
            if (m_lUserID < 0)
            {
                MessageBox.Show("Please login the device firstly");
                return;
            }

            if (m_lRealHandle < 0)
            {
                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 = 15;                                                     //播放库播放缓冲区最大缓冲帧数

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

                //打开预览 Start live view
                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;
                }
                else
                {
                    //预览成功
                    btnPreview.Text = "停止预览";
                }
            }
            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;
                btnPreview.Text = "开始预览";
            }
            return;
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (m_lUserID < 0)
            {
                if (textBoxIP.Text == "" || textBoxPort.Text == "" ||
                    textBoxUserName.Text == "" || textBoxPassword.Text == "")
                {
                    MessageBox.Show("Please input prarameters: ");
                    return;
                }
                string DVRIPAddress  = textBoxIP.Text;
                Int16  DVRPortNumber = Int16.Parse(textBoxPort.Text);
                string DVRUserName   = textBoxUserName.Text;
                string DVRPassword   = textBoxPassword.Text;

                //登录设备 Login the device
                m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref m_struDeviceInfo);
                if (m_lUserID == -1)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    strErr   = "NET_DVR_Login_V30 failed, error code= " + iLastErr;
                    //登录失败,输出错误号 Failed to login and output the error code
                    MessageBox.Show(strErr);
                    return;
                }
                else
                {
                    btnLogin.Text = "注销登录 Logout";
                    btnDevCfgGet_Click(sender, e);
                    btnNetCfgGet_Click(sender, e);
                    btnTimeGet_Click(sender, e);
                    GetDevChanList();
                }
            }
            else
            {
                //注销登录 Logout the device
                if (!CHCNetSDK.NET_DVR_Logout(m_lUserID))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    strErr   = "NET_DVR_Logout failed, error code= " + iLastErr; //注销登录失败,输出错误号 Failed to logout and output the error code
                    MessageBox.Show(strErr);
                }
                else
                {
                    btnLogin.Text = "登录设备 Login";
                    m_lUserID     = -1;
                    ParameterClear();
                }
            }
        }
Exemple #14
0
        private void buttonSet_Click(object sender, EventArgs e)
        {
            //init
            m_struEventCardLinkageCfgV51 = new CHCNetSDK.NET_DVR_EVENT_CARD_LINKAGE_CFG_V51();
            m_struEventCardLinkageCfgV51.Init();
            m_struEventCardLinkageCond       = new CHCNetSDK.NET_DVR_EVENT_CARD_LINKAGE_COND();
            m_struEventCardLinkageCond.byRes = new byte[106];

            //update
            UpdateUserData();
            m_struEventCardLinkageCfgV51.byCapturePic  = (byte)(checkBoxSnapshortLinkage.Checked ? 1 : 0);
            m_struEventCardLinkageCfgV51.byRecordVideo = (byte)(checkBoxRecordLinkage.Checked ? 1 : 0);
            uint.TryParse(textBoxEventNo.Text, out m_struEventCardLinkageCond.dwEventID);
            ushort.TryParse(textBoxLocalConID.Text, out m_struEventCardLinkageCond.wLocalControllerID);

            //allocate unmanaged resources
            uint dwSize = (uint)Marshal.SizeOf(m_struEventCardLinkageCond);

            m_struEventCardLinkageCond.dwSize = dwSize;

            IntPtr ptrStruCond = Marshal.AllocHGlobal((int)dwSize);

            Marshal.StructureToPtr(m_struEventCardLinkageCond, ptrStruCond, false);
            IntPtr ptrDwReturned = Marshal.AllocHGlobal(4);

            uint dwSizeCfg = (uint)Marshal.SizeOf(m_struEventCardLinkageCfgV51);

            m_struEventCardLinkageCfgV51.dwSize = dwSizeCfg;
            IntPtr ptrStruCfg = Marshal.AllocHGlobal((int)m_struEventCardLinkageCfgV51.dwSize);

            Marshal.StructureToPtr(m_struEventCardLinkageCfgV51, ptrStruCfg, false);

            //connect to device
            if (!CHCNetSDK.NET_DVR_SetDeviceConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_EVENT_CARD_LINKAGE_CFG_V51, 1,
                                                   ptrStruCond, dwSize, ptrDwReturned, ptrStruCfg, dwSizeCfg))
            {
                g_formList.AddLog(m_iDeviceIndex, AcsDemoPublic.OPERATION_FAIL_T, "NET_DVR_SET_EVENT_CARD_LINKAGE_CFG_V51 Failed");
                uint error = CHCNetSDK.NET_DVR_GetLastError();
                MessageBox.Show("Set event card linkage cfg Failed" + ":" + error);
            }
            else
            {
                g_formList.AddLog(m_iDeviceIndex, AcsDemoPublic.OPERATION_SUCC_T, "NET_DVR_SET_EVENT_CARD_LINKAGE_CFG_V51 SUCC");
            }
            m_byProMode    = false;
            m_byMacAddr    = false;
            m_byEmployeeNo = false;
            Marshal.FreeHGlobal(ptrStruCond);
            Marshal.FreeHGlobal(ptrStruCfg);
            Marshal.FreeHGlobal(ptrDwReturned);
        }
Exemple #15
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 = "设备连接成功";
                }
            }
        }
Exemple #16
0
        private void menuRecord_Click(object sender, EventArgs e)
        {
            //录像保存路径和文件名 the path and file name to save
            string sVideoFileName;

            sVideoFileName = UserDir + "录像" + DateTime.Now.ToUniversalTime().ToString().Replace("/", "-").Replace(":", "-") + ".mp4";

            if (m_bRecord == false)
            {
                //强制I帧 Make one key frame
                int lChannel = 1; //通道号 Channel number
                CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);

                //开始录像 Start recording
                if (!CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, sVideoFileName))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_SaveRealData failed, error code= " + iLastErr;
                    return;
                }
                else
                {
                    menuRecord.Text = "停止录像";
                    m_bRecord       = true;
                    label1.Visible  = true;
                    t.Enabled       = true;
                }
            }
            else
            {
                //停止录像 Stop recording
                if (!CHCNetSDK.NET_DVR_StopSaveRealData(m_lRealHandle))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_StopSaveRealData failed, error code= " + iLastErr;
                    return;
                }
                else
                {
                    str             = "NET_DVR_StopSaveRealData succ and the saved file is " + sVideoFileName;
                    menuRecord.Text = "录像";
                    label1.Visible  = false;
                    m_bRecord       = false;
                    Record record = new Record();
                    record.Show();
                    t.Enabled      = false;
                    label1.Visible = false;
                }
            }
            return;
        }
Exemple #17
0
        private void startvideo(String filename)
        {
            CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
            lpPreviewInfo.hPlayWnd        = RealPlayWnd.Handle;               //预览窗口
            lpPreviewInfo.lChannel        = Int16.Parse(textBoxChannel.Text); //预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 (RealData == null)
            {
                RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数
            }
            IntPtr pUser = new IntPtr();                                     //用户数据

            //打开预览 Start live view
            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;
            }
            else
            {
            }
            //录像保存路径和文件名 the path and file name to save
            string sVideoFileName;

            /* sVideoFileName = "Record_test.mp4";*/
            sVideoFileName = filename;
            //强制I帧 Make a I frame
            int lChannel = Int16.Parse(textBoxChannel.Text); //通道号 Channel number

            CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);
            //开始录像 Start recording
            if (!CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, sVideoFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_SaveRealData failed, error code= " + iLastErr;
                return;
            }
            else
            {
                /*MessageBox.Show("开始录像");*/
            }
            return;
        }
Exemple #18
0
        public void logout(int m_lUserID, string num, string zhakou)
        {
            bool re       = CHCNetSDK.NET_DVR_Logout(m_lUserID);
            uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();

            if (iLastErr != 0)
            {
                loginfo.Error(zhakou + "第" + num.ToString() + "道摄像头登出错误信息:" + iLastErr.ToString());
            }
            if (iLastErr == 0)
            {
                loginfo.Info(zhakou + "第" + num.ToString() + "道摄像头登出成功");
            }
        }
 private void btnStopDecode_Click(object sender, EventArgs e)
 {
     if (!CHCNetSDK.NET_DVR_MatrixStopDynamic(m_lUserID, dwDecChanNum))
     {
         iLastErr = CHCNetSDK.NET_DVR_GetLastError();
         strErr   = "NET_DVR_MatrixStopDynamic failed, error code= " + iLastErr;
         //停止动态解码失败,输出错误号 Failed to stop dynamic decoding and output the error code
         MessageBox.Show(strErr);
     }
     else
     {
         MessageBox.Show("Successful to stop dynamic decoding!");
     }
 }
Exemple #20
0
 private void btnAlarmChanEnd_Click(object sender, EventArgs e)
 {
     //停止布防结构体
     if (!CHCNetSDK.NET_DVR_CloseAlarmChan_V30(alarmChan))
     {
         MessageBox.Show(CHCNetSDK.NET_DVR_GetLastError().ToString());//报错参数
     }
     else
     {
         MessageBox.Show("撤防成功!");
         btnAlarmChanB.Enabled   = true;
         btnAlarmChanEnd.Enabled = false;
     }
 }
Exemple #21
0
 private void btnListenEnd_Click(object sender, EventArgs e)
 {
     //停止监听
     if (!CHCNetSDK.NET_DVR_StopListen_V30(iListenHandle))
     {
         MessageBox.Show(CHCNetSDK.NET_DVR_GetLastError().ToString());
     }
     else
     {
         MessageBox.Show("停止监听操作成功!");
         btnListenBegin.Enabled = true;
         btnListenEnd.Enabled   = false;
     }
 }
Exemple #22
0
 private void btnResume_Click(object sender, EventArgs e)
 {
     if (!CHCNetSDK.NET_DVR_MatrixDiaplayControl(m_lUserID, (uint)iDisplayNo, 2, (uint)comboBoxEnlarge.SelectedIndex + 1))
     {
         iLastErr = CHCNetSDK.NET_DVR_GetLastError();
         strErr   = "NET_DVR_MatrixDiaplayControl failed, error code= " + iLastErr;
         //显示通道控制窗口放大恢复失败,输出错误号 Failed to resume the window and output the error code
         MessageBox.Show(strErr);
     }
     else
     {
         checkBoxEnlarge.Checked = false;
     }
 }
Exemple #23
0
        public override void Stop()
        {
            if (RealHandle == -1)
            {
                return;
            }
            if (!CHCNetSDK.NET_DVR_StopRealPlay(RealHandle))
            {
                var code = CHCNetSDK.NET_DVR_GetLastError();

                Logger.Default.Error($"关闭摄像机实时预览失败,摄像机:[{DVR.IP}],错误码:{code}");
            }
            RealHandle = -1;
        }
Exemple #24
0
 private void StopLivePreView()
 {
     //Í£Ö¹Ô¤ÀÀ 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;
     //LogoutUser();
     //FailCamera();
 }
Exemple #25
0
        private void timer_near_Tick(object sender, EventArgs e)
        {
            bool result = CHCNetSDK.NET_DVR_PTZControl(m_lRealHandle, 13, 0);

            if (result == false)
            {
                uint nError = CHCNetSDK.NET_DVR_GetLastError();
                if (nError == 12)
                {
                    Information.Text += "请先启动预览!" + System.Environment.NewLine;
                }
            }
            bool result1 = CHCNetSDK.NET_DVR_PTZControl(m_lRealHandle, 13, 1);
        }
 /// <summary>
 ///  释放设备资源
 /// </summary>
 public uint CleanUp()
 {
     this.initSDK = false;
     foreach (CameraServer server in servers)
     {
         server.CleanUp();
     }
     if (CHCNetSDK.NET_DVR_Cleanup())
     {
         return(1000);
     }
     this.lastError = CHCNetSDK.NET_DVR_GetLastError();
     return(this.lastError);
 }
Exemple #27
0
        private void SaveVideo(DevInfo dev, ref bool ifRecord, string path, ref Int32 userID, ref Int32 realHandler, ToolStripMenuItem recordToolStripMenuItem)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string VideoName = path + "\\" + dev.getIP() + "_" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" +
                               DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".mp4";

            if (!ifRecord)
            {
                int iChannel_1 = Int16.Parse(ichannel);

                CHCNetSDK.NET_DVR_MakeKeyFrame(userID, iChannel_1);
                bool ret = CHCNetSDK.NET_DVR_SaveRealData(userID, VideoName);
                if (!ret)
                {
                    uint ilastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str = "NET_DVR_SaveRealData failed, error code= " + ilastErr;
                    MessageBox.Show(str);

                    return;
                }
                else
                {
                    recordToolStripMenuItem.Text = "Stop recording";

                    ifRecord = true;
                }
            }
            else
            {
                bool ret = CHCNetSDK.NET_DVR_StopSaveRealData(realHandler);
                if (!ret)
                {
                    uint ilastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str = "NET_DVR_StopSaveRealData failed, error code= " + ilastErr;
                    MessageBox.Show(str);

                    return;
                }
                else
                {
                    str = "Successful to stop recording and the saved file is " + VideoName;
                    recordToolStripMenuItem.Text = "Record this";
                    MessageBox.Show(str);
                    ifRecord = false;
                }
            }
        }
Exemple #28
0
        private void CaptureJpeg()
        {
            int lChannel = Int32.Parse(dvrControl.dvrObject.Channel);

            CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();


            lpJpegPara.wPicQuality = captureController.captureSettingModel.PictureQuality;
            lpJpegPara.wPicSize    = captureController.captureSettingModel.PictureSize;

            //Capture a JPEG picture
            string sJpegPicFileName;

            sJpegPicFileName = "reza.jpeg";

            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;
                //DebugInfo(str);
                MessageControl messageControl = new MessageControl("Capture error", str);
                messageControl.ShowDialog();
                return;
            }
            else
            {
                str = "NET_DVR_CaptureJPEGPicture succ and the saved file is " + sJpegPicFileName;
                //DebugInfo(str);
            }

            byJpegPicBuffer = new byte[iBuffSize];


            if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(m_lUserID, lChannel, ref lpJpegPara, byJpegPicBuffer, iBuffSize, ref dwSizeReturned))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_CaptureJPEGPicture_NEW failed, error code= " + iLastErr;
                //DebugInfo(str);
                MessageControl messageControl = new MessageControl("Capture error", str);
                messageControl.ShowDialog();
                return;
            }
            else
            {
                str = "NET_DVR_CaptureJPEGPicture_NEW succ and save the data in buffer to 'buffertest.jpg'.";
            }

            return;
        }
        /// <summary>
        ///		Stop Preview.
        /// </summary>
        public void StopPreview()
        {
            if (livePlayer_.RealPlayHandle == -1)
            {
                debugInfo("Preview not started!");
                return;
            }

            {
                // Set to null Draw CallBack Function
                CHCNetSDK.NET_DVR_RigisterDrawFun(livePlayer_.RealPlayHandle, null, 0);
            }

            bool isStopRealPlayOk;

            {
                // Stop live view
                isStopRealPlayOk = CHCNetSDK.NET_DVR_StopRealPlay(livePlayer_.RealPlayHandle);

                if (livePlayer_.RealPlayPort >= 0)
                {
                    if (!PlayCtrl.PlayM4_Stop(livePlayer_.RealPlayPort))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_Stop failed");
                    }

                    if (!PlayCtrl.PlayM4_CloseStream(livePlayer_.RealPlayPort))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_CloseStream failed");
                    }

                    if (!PlayCtrl.PlayM4_FreePort(livePlayer_.RealPlayPort))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_FreePort failed");
                    }
                }
            }

            livePlayer_ = LivePlayer.Default();

            if (isStopRealPlayOk)
            {
                debugInfo("NET_DVR_StopRealPlay succ!");
            }
            else
            {
                throw new NvrSdkException(CHCNetSDK.NET_DVR_GetLastError(), "NET_DVR_StopRealPlay failed");
            }
        }
        private void btnMotionSetup_Click(object sender, EventArgs e)
        {
            m_struMotionV30.byMotionSensitive = GetMotionSensitivityCurSel();
            GetAlarmHandleWnd();
            GetAlarmTimeWnd();
            GetRecordChanWnd();
            if (checkBoxEnableMotion.Checked)
            {
                m_struMotionV30.byEnableHandleMotion = 1;
            }
            else
            {
                m_struMotionV30.byEnableHandleMotion = 0;
            }

            // set motion region
            if (checkBoxMotionScope.Checked)
            {
                for (int i = 0; i < 18; i++)
                {
                    for (int j = 0; j < 22; j++)
                    {
                        m_struMotionV30.byMotionScope[i * 96 + j] = 1;
                    }
                }
            }

            m_struPicCfgV30.struMotion = m_struMotionV30;

            uint   dwSize       = (uint)Marshal.SizeOf(m_struPicCfgV30);
            IntPtr ptrPicCfgV30 = Marshal.AllocHGlobal((Int32)dwSize);

            Marshal.StructureToPtr(m_struPicCfgV30, ptrPicCfgV30, false);
            if (!CHCNetSDK.NET_DVR_SetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_PICCFG_V30, m_lChannel, ptrPicCfgV30, dwSize))
            {
                // fail
                // Preview.DebugInfo("NET_DVR_GET_PICCFG_V30 Succ");
                uint dwErrorNo = CHCNetSDK.NET_DVR_GetLastError();
                Debug.Print("NET_DVR_SET_PICCFG_V30 fail");
                MessageBox.Show("NET_DVR_SET_PICCFG_V30 Fail");
            }
            else
            {
                // succ
                Debug.Print("NET_DVR_SET_PICCFG_V30 Succ");
                MessageBox.Show("NET_DVR_SET_PICCFG_V30 Succ");
            }
            Marshal.FreeHGlobal(ptrPicCfgV30);
        }