示例#1
0
        /// <summary>
        /// 获取设备能力集
        /// </summary>
        /// <param name="userId">登录id</param>
        /// <param name="struDecAbility">设备能力集</param>
        /// <returns></returns>
        public static bool GetDeviceAbility(int userId, ref CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41 struDecAbility)
        {
            uint errorCode = 0;

            try
            {
                //获取设备能力集
                int    nSize         = Marshal.SizeOf(struDecAbility);
                IntPtr ptrDecAbility = Marshal.AllocHGlobal(nSize);
                Marshal.StructureToPtr(struDecAbility, ptrDecAbility, false);
                if (!CHCNetSDK.NET_DVR_GetDeviceAbility(userId, CHCNetSDK.MATRIXDECODER_ABILITY_V41, IntPtr.Zero, 0, ptrDecAbility, (uint)nSize))
                {
                    errorCode = CHCNetSDK.NET_DVR_GetLastError();
                    Log.GetLogger().ErrorFormat("Get MATRIXDECODER_ABILITY_V41 failed, error code = {0}", errorCode);
                    return(false);
                }

                struDecAbility = (CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41)Marshal.PtrToStructure(ptrDecAbility,
                                                                                              typeof(CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41));
            }
            catch (Exception e)
            {
                Log.GetLogger().InfoFormat("catch an error : {0}", e.Message);
                return(false);
            }

            return(true);
        }
示例#2
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            IntPtr pInBuf;
            Int32  nSize;

            if (xmlInput == null)
            {
                pInBuf = IntPtr.Zero;
                nSize  = 0;
            }
            else
            {
                nSize  = xmlInput.Length;
                pInBuf = Marshal.AllocHGlobal(nSize);
                pInBuf = Marshal.StringToHGlobalAnsi(xmlInput);
            }

            int    XML_ABILITY_OUT_LEN = 3 * 1024 * 1024;
            IntPtr pOutBuf             = Marshal.AllocHGlobal(XML_ABILITY_OUT_LEN);

            if (!CHCNetSDK.NET_DVR_GetDeviceAbility(m_lUserID, m_dwAbilityType, pInBuf, (uint)nSize, pOutBuf, (uint)XML_ABILITY_OUT_LEN))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GetDeviceAbility failed, error code= " + iLastErr + "\r\n" + GetErrorDescription(iLastErr);
                //获取设备能力集失败,输出错误号 Failed to get the capability set and output the error code
                textBoxCapability.Text = strErr;
            }
            else
            {
                string strOutBuf = Marshal.PtrToStringAnsi(pOutBuf, XML_ABILITY_OUT_LEN);
                strOutBuf = strOutBuf.Replace(">\n<", ">\r\n<");
                textBoxCapability.Text = strOutBuf;
            }
            Marshal.FreeHGlobal(pInBuf);
            Marshal.FreeHGlobal(pOutBuf);
        }
        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
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                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";
                    Int32  nSize         = Marshal.SizeOf(m_struDecAbility);
                    IntPtr ptrDecAbility = Marshal.AllocHGlobal(nSize);
                    Marshal.StructureToPtr(m_struDecAbility, ptrDecAbility, false);
                    if (!CHCNetSDK.NET_DVR_GetDeviceAbility(m_lUserID, CHCNetSDK.MATRIXDECODER_ABILITY_V41, IntPtr.Zero, 0, ptrDecAbility, (uint)nSize))
                    {
                        iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                        strErr   = "Get MATRIXDECODER_ABILITY_V41 failed, error code= " + iLastErr;
                        //获取解码器能力集失败,输出错误号 Failed to get the capability set of decoder and output the error code
                        MessageBox.Show(strErr);
                    }
                    else
                    {
                        m_struDecAbility = (CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41)Marshal.PtrToStructure(ptrDecAbility, typeof(CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41));
                        int    i = 0;
                        string str;

                        //解码通道信息 Decoding channel information
                        for (i = 0; i < m_struDecAbility.byDecChanNums; i++)
                        {
                            str = String.Format("通道{0}", i + 1);
                            comboBoxDecChan.Items.Add(str);
                        }

                        //显示通道信息 Display channel information
                        for (i = 0; i < m_struDecAbility.struVgaInfo.byChanNums; i++)
                        {
                            str = String.Format("VGA{0}", i + 1);
                            comboBoxDispChan.Items.Add(str);
                            iDispChanNo[iTotalDispChanNum] = m_struDecAbility.struVgaInfo.byStartChan + i;
                            iTotalDispChanNum++;
                        }
                        for (i = 0; i < m_struDecAbility.struBncInfo.byChanNums; i++)
                        {
                            str = String.Format("BNC{0}", i + 1);
                            comboBoxDispChan.Items.Add(str);
                            iDispChanNo[iTotalDispChanNum] = m_struDecAbility.struBncInfo.byStartChan + i;
                            iTotalDispChanNum++;
                        }
                        for (i = 0; i < m_struDecAbility.struHdmiInfo.byChanNums; i++)
                        {
                            str = String.Format("HDMI{0}", i + 1);
                            comboBoxDispChan.Items.Add(str);
                            iDispChanNo[iTotalDispChanNum] = m_struDecAbility.struHdmiInfo.byStartChan + i;
                            iTotalDispChanNum++;
                        }
                        for (i = 0; i < m_struDecAbility.struDviInfo.byChanNums; i++)
                        {
                            str = String.Format("DVI{0}", i + 1);
                            comboBoxDispChan.Items.Add(str);
                            iDispChanNo[iTotalDispChanNum] = m_struDecAbility.struDviInfo.byStartChan + i;
                            iTotalDispChanNum++;
                        }
                        comboBoxDecChan.SelectedIndex  = 0;
                        comboBoxDispChan.SelectedIndex = 0;
                    }
                    Marshal.FreeHGlobal(ptrDecAbility);
                }
            }
            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;
                }
            }
        }
示例#4
0
        //登录设备
        private bool InitHMQ(string ip, string user, string pwd, string port)
        {
            try
            {
                //登录设备
                int nPort = string.IsNullOrEmpty(port) ? 8000 : int.Parse(port);
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                m_userId = CHCNetSDK.NET_DVR_Login_V30(ip, nPort, user, pwd, 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);
                }

                //获取设备能力集
                int    nSize         = Marshal.SizeOf(m_struDecAbility);
                IntPtr ptrDecAbility = Marshal.AllocHGlobal(nSize);
                Marshal.StructureToPtr(m_struDecAbility, ptrDecAbility, false);
                if (!CHCNetSDK.NET_DVR_GetDeviceAbility(m_userId, CHCNetSDK.MATRIXDECODER_ABILITY_V41, IntPtr.Zero, 0, ptrDecAbility, (uint)nSize))
                {
                    m_iErrorCode = CHCNetSDK.NET_DVR_GetLastError();
                    Log.GetLogger().ErrorFormat("Get MATRIXDECODER_ABILITY_V41 failed, error code = {0}", m_iErrorCode);
                    return(false);
                }
                m_struDecAbility = (CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41)Marshal.PtrToStructure(ptrDecAbility,
                                                                                                typeof(CHCNetSDK.NET_DVR_MATRIX_ABILITY_V41));
                Log.GetLogger().InfoFormat("合码器ip={0}, DecN={1}, BncN={2}", ip, m_struDecAbility.byDecChanNums,
                                           m_struDecAbility.struBncInfo.byChanNums);

                //设置设备自动重启
                CHCNetSDK.NET_DVR_AUTO_REBOOT_CFG struRebootCfg = new CHCNetSDK.NET_DVR_AUTO_REBOOT_CFG();
                nSize = Marshal.SizeOf(struRebootCfg);
                IntPtr ptrRebootCfg = Marshal.AllocHGlobal(nSize);
                Marshal.StructureToPtr(struRebootCfg, ptrRebootCfg, false);
                uint lpBytesReturned = 0;
                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_userId, CHCNetSDK.NET_DVR_GET_AUTO_REBOOT_CFG,
                                                    0, ptrRebootCfg, (uint)nSize, ref lpBytesReturned))
                {
                    m_iErrorCode = CHCNetSDK.NET_DVR_GetLastError();
                    Log.GetLogger().ErrorFormat("NET_DVR_GetDVRConfig 获取重启参数失败, error code = {0}", m_iErrorCode);
                    return(false);
                }
                struRebootCfg = (CHCNetSDK.NET_DVR_AUTO_REBOOT_CFG)Marshal.PtrToStructure(ptrRebootCfg,
                                                                                          typeof(CHCNetSDK.NET_DVR_AUTO_REBOOT_CFG));
                if (7 != struRebootCfg.struRebootTime.byDate)
                {
                    struRebootCfg.dwSize = (uint)nSize;
                    struRebootCfg.struRebootTime.byDate   = 7;
                    struRebootCfg.struRebootTime.byHour   = 5;
                    struRebootCfg.struRebootTime.byMinute = 9;
                    IntPtr ptrRebootCfgNew = Marshal.AllocHGlobal(nSize);
                    Marshal.StructureToPtr(struRebootCfg, ptrRebootCfgNew, false);
                    if (!CHCNetSDK.NET_DVR_SetDVRConfig(m_userId, CHCNetSDK.NET_DVR_SET_AUTO_REBOOT_CFG, 0,
                                                        ptrRebootCfgNew, (uint)nSize))
                    {
                        m_iErrorCode = CHCNetSDK.NET_DVR_GetLastError();
                        Log.GetLogger().ErrorFormat("NET_DVR_SetDVRConfig 设置自动重启失败, errorCode = {0}", m_iErrorCode);
                        return(false);
                    }
                    Log.GetLogger().InfoFormat("NET_DVR_SetDVRConfig 设置自动重启成功");
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().InfoFormat("InitHMQ catch an error : {0}", e.Message);
                return(false);
            }

            return(true);
        }