Esempio n. 1
0
        public static int StringGet(string IP, int m_lChannel)
        {
            UInt32 dwReturn      = 0;
            Int32  nSize         = Marshal.SizeOf(m_struShowStrCfg);
            IntPtr ptrShowStrCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struShowStrCfg, ptrShowStrCfg, false);
            int mUserID = -1;

            if (MediaData.Device_UserID_Alarm.ContainsKey(IP))
            {
                mUserID = MediaData.Device_UserID_Alarm[IP].UserID;
            }
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(mUserID, CHCNetSDK.NET_DVR_GET_SHOWSTRING_V30, m_lChannel, ptrShowStrCfg, (UInt32)nSize, ref dwReturn))
            {
                uint   iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string strErr   = "NET_DVR_GET_SHOWSTRING_V30 failed, error code= " + iLastErr;
                //获取字符叠加参数失败,输出错误号 Failed to get overlay parameters and output the error code
                return(int.Parse(iLastErr.ToString()));
            }
            else
            {
                m_struShowStrCfg = (CHCNetSDK.NET_DVR_SHOWSTRING_V30)Marshal.PtrToStructure(ptrShowStrCfg, typeof(CHCNetSDK.NET_DVR_SHOWSTRING_V30));
                return(1);
            }
            Marshal.FreeHGlobal(ptrShowStrCfg);
        }
Esempio n. 2
0
        private CHCNetSDK.NET_DVR_PICCFG_V30 getOSDConfig(int m_lChannel)
        {
            uint dwReturned = 0;

            CHCNetSDK.NET_DVR_PICCFG_V30 m_struOsdCfg = new CHCNetSDK.NET_DVR_PICCFG_V30();
            uint   dwSize    = (uint)Marshal.SizeOf(m_struOsdCfg);
            IntPtr ptrOsdCfg = Marshal.AllocHGlobal((Int32)dwSize);

            Marshal.StructureToPtr(m_struOsdCfg, ptrOsdCfg, false);
            // configure OSD parameters
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PICCFG_V30, m_lChannel, ptrOsdCfg, dwSize, ref dwReturned))
            {
                uint   iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string str      = "NET_DVR_GET_PICCFG_V30, error code= " + iLastErr;
                Marshal.FreeHGlobal(ptrOsdCfg);
            }
            else
            {
                m_struOsdCfg = (CHCNetSDK.NET_DVR_PICCFG_V30)Marshal.PtrToStructure(ptrOsdCfg, typeof(CHCNetSDK.NET_DVR_PICCFG_V30));
                Marshal.FreeHGlobal(ptrOsdCfg);
                //m_bChkDisplayName = m_struOsdCfg.dwShowChanName;
                //m_bChkDisplayTime = m_struOsdCfg.dwShowOsd;
                //textBoxDisplayName.Text = m_struOsdCfg.sChanName;
                //comboBoxDateFormat.SelectedIndex = (int)m_struOsdCfg.byOSDType;
                //comboBoxTimeFormat.SelectedIndex = (int)m_struOsdCfg.byHourOSDType;
                //comboBoxOSDAttribute.SelectedIndex = (int)(m_struOsdCfg.byOSDAttrib - 1);
            }
            return(m_struOsdCfg);
        }
Esempio n. 3
0
        private void btnTimeGet_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn   = 0;
            Int32  nSize      = Marshal.SizeOf(m_struTimeCfg);
            IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_TIMECFG, -1, ptrTimeCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GET_TIMECFG failed, error code= " + iLastErr;
                //获取设备时间失败,输出错误号 Failed to get time of the device and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                m_struTimeCfg      = (CHCNetSDK.NET_DVR_TIME)Marshal.PtrToStructure(ptrTimeCfg, typeof(CHCNetSDK.NET_DVR_TIME));
                textBoxYear.Text   = Convert.ToString(m_struTimeCfg.dwYear);
                textBoxMonth.Text  = Convert.ToString(m_struTimeCfg.dwMonth);
                textBoxDay.Text    = Convert.ToString(m_struTimeCfg.dwDay);
                textBoxHour.Text   = Convert.ToString(m_struTimeCfg.dwHour);
                textBoxMinute.Text = Convert.ToString(m_struTimeCfg.dwMinute);
                textBoxSecond.Text = Convert.ToString(m_struTimeCfg.dwSecond);
            }
            Marshal.FreeHGlobal(ptrTimeCfg);
        }
Esempio n. 4
0
        private void btnShowStringGet_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn      = 0;
            Int32  nSize         = Marshal.SizeOf(m_struShowStrCfg);
            IntPtr ptrShowStrCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struShowStrCfg, ptrShowStrCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_SHOWSTRING_V30, m_lChannel, ptrShowStrCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GET_SHOWSTRING_V30 failed, error code= " + iLastErr;
                //获取字符叠加参数失败,输出错误号 Failed to get overlay parameters and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                m_struShowStrCfg = (CHCNetSDK.NET_DVR_SHOWSTRING_V30)Marshal.PtrToStructure(ptrShowStrCfg, typeof(CHCNetSDK.NET_DVR_SHOWSTRING_V30));

                checkBoxOSD1.Checked = (m_struShowStrCfg.struStringInfo[0].wShowString == 1);
                textBoxOSD1.Text     = m_struShowStrCfg.struStringInfo[0].sString;
                textBoxOSD1X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[0].wShowStringTopLeftX);
                textBoxOSD1Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[0].wShowStringTopLeftY);

                checkBoxOSD2.Checked = (m_struShowStrCfg.struStringInfo[1].wShowString == 1);
                textBoxOSD2.Text     = m_struShowStrCfg.struStringInfo[1].sString;
                textBoxOSD2X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[1].wShowStringTopLeftX);
                textBoxOSD2Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[1].wShowStringTopLeftY);

                checkBoxOSD3.Checked = (m_struShowStrCfg.struStringInfo[2].wShowString == 1);
                textBoxOSD3.Text     = m_struShowStrCfg.struStringInfo[2].sString;
                textBoxOSD3X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[2].wShowStringTopLeftX);
                textBoxOSD3Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[2].wShowStringTopLeftY);

                checkBoxOSD4.Checked = (m_struShowStrCfg.struStringInfo[3].wShowString == 1);
                textBoxOSD4.Text     = m_struShowStrCfg.struStringInfo[3].sString;
                textBoxOSD4X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[3].wShowStringTopLeftX);
                textBoxOSD4Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[3].wShowStringTopLeftY);

                checkBoxOSD5.Checked = (m_struShowStrCfg.struStringInfo[4].wShowString == 1);
                textBoxOSD5.Text     = m_struShowStrCfg.struStringInfo[4].sString;
                textBoxOSD5X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[4].wShowStringTopLeftX);
                textBoxOSD5Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[4].wShowStringTopLeftY);

                checkBoxOSD6.Checked = (m_struShowStrCfg.struStringInfo[5].wShowString == 1);
                textBoxOSD6.Text     = m_struShowStrCfg.struStringInfo[5].sString;
                textBoxOSD6X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[5].wShowStringTopLeftX);
                textBoxOSD6Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[5].wShowStringTopLeftY);

                checkBoxOSD7.Checked = (m_struShowStrCfg.struStringInfo[6].wShowString == 1);
                textBoxOSD7.Text     = m_struShowStrCfg.struStringInfo[6].sString;
                textBoxOSD7X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[6].wShowStringTopLeftX);
                textBoxOSD7Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[6].wShowStringTopLeftY);

                checkBoxOSD8.Checked = (m_struShowStrCfg.struStringInfo[7].wShowString == 1);
                textBoxOSD8.Text     = m_struShowStrCfg.struStringInfo[7].sString;
                textBoxOSD8X.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[7].wShowStringTopLeftX);
                textBoxOSD8Y.Text    = Convert.ToString(m_struShowStrCfg.struStringInfo[7].wShowStringTopLeftY);
            }
            Marshal.FreeHGlobal(ptrShowStrCfg);
        }
Esempio n. 5
0
        public PTZInfo GetPTZInfo(string devIp, int devPort, string userName, string password)
        {
            PTZInfo ptzInfo = new PTZInfo();

            int           userId        = -1;
            DevLoginModel devLoginModel = DeviceLogin(devIp, devPort, userName, password);

            if (devLoginModel != null)
            {
                userId = devLoginModel.LoginId;
            }

            CHCNetSDK.NET_DVR_PTZPOS ptzPos = new CHCNetSDK.NET_DVR_PTZPOS();
            uint   dwReturn  = 0;
            int    nSize     = Marshal.SizeOf(ptzPos);
            IntPtr ptrPtzCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(ptzPos, ptrPtzCfg, false);

            if (CHCNetSDK.NET_DVR_GetDVRConfig(userId, CHCNetSDK.NET_DVR_GET_PTZPOS, -1, ptrPtzCfg, (UInt32)nSize, ref dwReturn))
            {
                ptzPos = (CHCNetSDK.NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPtzCfg, typeof(CHCNetSDK.NET_DVR_PTZPOS));

                //成功获取显示ptz参数
                ushort wPanPos = Convert.ToUInt16(Convert.ToString(ptzPos.wPanPos, 16));
                ptzInfo.Pan = wPanPos * 0.1f;
                ushort wTiltPos = Convert.ToUInt16(Convert.ToString(ptzPos.wTiltPos, 16));
                ptzInfo.Tilt = wTiltPos * 0.1f;
                ushort wZoomPos = Convert.ToUInt16(Convert.ToString(ptzPos.wZoomPos, 16));
                ptzInfo.Zoom = wZoomPos * 0.1f;
            }

            Marshal.FreeHGlobal(ptrPtzCfg);
            return(ptzInfo);
        }
Esempio n. 6
0
        public void AdjustMirrorPara(byte type)
        {
            dwReturn  = 0;
            nSize     = Marshal.SizeOf(camPara);
            ptrPicCfg = Marshal.AllocHGlobal(nSize);
            Marshal.StructureToPtr(camPara, ptrPicCfg, false);
            if (CHCNetSDK.NET_DVR_GetDVRConfig(userID, 3368, DeviceInfo.byStartChan, ptrPicCfg, (uint)nSize, ref dwReturn))
            {
                camPara = (CHCNetSDK.NET_DVR_CAMERAPARAMCFG_EX)Marshal.PtrToStructure(ptrPicCfg, typeof(CHCNetSDK.NET_DVR_CAMERAPARAMCFG_EX));
                Marshal.FreeHGlobal(ptrPicCfg);
                camPara.byMirror = type;

                ptrPicCfg = Marshal.AllocHGlobal(nSize);
                Marshal.StructureToPtr(camPara, ptrPicCfg, false);


                if (!CHCNetSDK.NET_DVR_SetDVRConfig(userID, 3369, DeviceInfo.byStartChan, ptrPicCfg, (uint)nSize))
                {
                    lastErr      = CHCNetSDK.NET_DVR_GetLastError();
                    debugMessage = "设置镜像关闭失败, 错误码:" + lastErr;
                    err          = true;
                }
            }
            else
            {
                lastErr      = CHCNetSDK.NET_DVR_GetLastError();
                debugMessage = "获取参数失败, 错误码:" + lastErr;
                err          = true;
            }
            Marshal.FreeHGlobal(ptrPicCfg);
        }
Esempio n. 7
0
        public void GetNetCfg(int m_lUserID)
        {
            UInt32 dwReturn  = 0;
            Int32  nSize     = Marshal.SizeOf(m_struNetCfg);
            IntPtr ptrNetCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struNetCfg, ptrNetCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_NETCFG_V30, -1, ptrNetCfg, (UInt32)nSize, ref dwReturn))
            {
                uint   iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string strErr   = "NET_DVR_GET_NETCFG_V30 failed, error code= " + iLastErr;
                //获取网络参数失败,输出错误号 Failed to get the network parameters and output the error code
                MsgBox.ShowWarn(strErr);
            }
            else
            {
                m_struNetCfg = (CHCNetSDK.NET_DVR_NETCFG_V30)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_NETCFG_V30));
                //textBoxIPAddr.Text = m_struNetCfg.struEtherNet[0].struDVRIP.sIpV4;
                //textBoxGateWay.Text = m_struNetCfg.struGatewayIpAddr.sIpV4;
                //textBoxSubMask.Text = m_struNetCfg.struEtherNet[0].struDVRIPMask.sIpV4;
                //textBoxDns.Text = m_struNetCfg.struDnsServer1IpAddr.sIpV4;
                //textBoxHostIP.Text = m_struNetCfg.struAlarmHostIpAddr.sIpV4;
                //textBoxHostPort.Text = Convert.ToString(m_struNetCfg.wAlarmHostIpPort);
                //textBoxHttpCfg.Text = Convert.ToString(m_struNetCfg.wHttpPortNo);
                //textBoxSdkCfg.Text = Convert.ToString(m_struNetCfg.struEtherNet[0].wDVRPort);
                if (m_struNetCfg.byUseDhcp == 0 && m_struNetCfg.struPPPoE.dwPPPOE == 0)
                {
                    //TextEnable(true);
                }
            }
            Marshal.FreeHGlobal(ptrNetCfg);
        }
Esempio n. 8
0
        private bool GetAlarmInConfig()
        {
            Int32  nSize         = Marshal.SizeOf(m_struAlarmInCfg);
            IntPtr ptrAlarmInCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struAlarmInCfg, ptrAlarmInCfg, false);
            UInt32 dwReturn = 0;
            bool   bRet     = false;
            Int32  lAlarmIn = comboBoxAlarmIn.SelectedIndex;

            bRet = CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_ALARMINCFG_V30, lAlarmIn, ptrAlarmInCfg, (UInt32)nSize, ref dwReturn);
            if (bRet)
            {
                Debug.Print("Succ to NET_DVR_GET_ALARAMINCFG_V30");

                m_struAlarmInCfg = (CHCNetSDK.NET_DVR_ALARMINCFG_V30)Marshal.PtrToStructure(ptrAlarmInCfg, typeof(CHCNetSDK.NET_DVR_ALARMINCFG_V30));
            }
            else
            {
                Debug.Print("Fail to NET_DVR_GET_ALARMINCFG_V30");
            }

            Marshal.FreeHGlobal(ptrAlarmInCfg);

            return(bRet);
        }
Esempio n. 9
0
        /// <summary>
        /// 修改DVR系统时间
        /// </summary>
        public bool SyncDateTime()
        {
            bool rtn = false;

            CHCNetSDK.NET_DVR_TIME time = new CHCNetSDK.NET_DVR_TIME();
            UInt32 dwReturn             = 0;
            Int32  nSize      = Marshal.SizeOf(time);
            IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(time, ptrTimeCfg, false);
            if (CHCNetSDK.NET_DVR_GetDVRConfig(_userID, CHCNetSDK.NET_DVR_GET_TIMECFG, int.Parse(_cameraCfg.Channel), ptrTimeCfg, (UInt32)nSize, ref dwReturn))
            {
                time = (CHCNetSDK.NET_DVR_TIME)Marshal.PtrToStructure(ptrTimeCfg, typeof(CHCNetSDK.NET_DVR_TIME));
                Marshal.FreeHGlobal(ptrTimeCfg);
                time.dwYear   = (uint)DateTime.Now.Year;
                time.dwMonth  = (uint)DateTime.Now.Month;
                time.dwDay    = (uint)DateTime.Now.Day;
                time.dwHour   = (uint)DateTime.Now.Hour;
                time.dwMinute = (uint)DateTime.Now.Minute;
                time.dwSecond = (uint)DateTime.Now.Second;

                Int32  nSize1         = Marshal.SizeOf(time);
                IntPtr ptrShowStrCfg1 = Marshal.AllocHGlobal(nSize1);
                Marshal.StructureToPtr(time, ptrShowStrCfg1, false);
                if (CHCNetSDK.NET_DVR_SetDVRConfig(_userID, CHCNetSDK.NET_DVR_SET_TIMECFG, int.Parse(_cameraCfg.Channel), ptrShowStrCfg1, (UInt32)nSize1))
                {
                    rtn = true;
                }
                Marshal.FreeHGlobal(ptrShowStrCfg1);
            }

            return(rtn);
        }
Esempio n. 10
0
        private CHCNetSDK.NET_DVR_COMPRESSIONCFG_V30 getDvrCompressionCfgV30()
        {
            checkUserSessionValid();

            IntPtr ptrCompressionCfgInfoV30 = IntPtr.Zero;

            CHCNetSDK.NET_DVR_COMPRESSIONCFG_V30 compressionCfgInfoV30 = new CHCNetSDK.NET_DVR_COMPRESSIONCFG_V30();

            try {
                int compressionCfgInfoV30Size = Marshal.SizeOf(compressionCfgInfoV30);
                ptrCompressionCfgInfoV30 = Marshal.AllocHGlobal(compressionCfgInfoV30Size);
                Marshal.StructureToPtr(compressionCfgInfoV30, ptrCompressionCfgInfoV30, false);

                uint dwReturn = 0;
                if (!CHCNetSDK.NET_DVR_GetDVRConfig(NvrUserSession.UserSessionState.UserId,
                                                    CHCNetSDK.NET_DVR_GET_COMPRESSCFG_V30,
                                                    NvrUserSession.UserSessionState.SelectedChannelNum,
                                                    ptrCompressionCfgInfoV30,
                                                    (uint)compressionCfgInfoV30Size,
                                                    ref dwReturn))
                {
                    throw new NvrSdkException(CHCNetSDK.NET_DVR_GetLastError(), "NET_DVR_GetDVRConfig: NET_DVR_GET_COMPRESSCFG_V30 failed");
                }

                compressionCfgInfoV30 = (CHCNetSDK.NET_DVR_COMPRESSIONCFG_V30)Marshal.PtrToStructure(ptrCompressionCfgInfoV30, typeof(CHCNetSDK.NET_DVR_COMPRESSIONCFG_V30));
                debugInfo($"NET_DVR_GetDVRConfig: NET_DVR_GET_COMPRESSCFG_V30 succ! return={dwReturn}");
            } finally {
                if (ptrCompressionCfgInfoV30 != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(ptrCompressionCfgInfoV30);
                }
            }

            return(compressionCfgInfoV30);
        }
Esempio n. 11
0
        private void btnNetCfgGet_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn  = 0;
            Int32  nSize     = Marshal.SizeOf(m_struNetCfg);
            IntPtr ptrNetCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struNetCfg, ptrNetCfg, false);

            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_NETCFG_V30, -1, ptrNetCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GET_NETCFG_V30 failed, error code= " + iLastErr;
                //获取网络参数失败,输出错误号 Failed to get the network parameters and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                m_struNetCfg         = (CHCNetSDK.NET_DVR_NETCFG_V30)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_NETCFG_V30));
                textBoxIPAddr.Text   = m_struNetCfg.struEtherNet[0].struDVRIP.sIpV4;
                textBoxGateWay.Text  = m_struNetCfg.struGatewayIpAddr.sIpV4;
                textBoxSubMask.Text  = m_struNetCfg.struEtherNet[0].struDVRIPMask.sIpV4;
                textBoxDns.Text      = m_struNetCfg.struDnsServer1IpAddr.sIpV4;
                textBoxHostIP.Text   = m_struNetCfg.struAlarmHostIpAddr.sIpV4;
                textBoxHostPort.Text = Convert.ToString(m_struNetCfg.wAlarmHostIpPort);
                textBoxHttpCfg.Text  = Convert.ToString(m_struNetCfg.wHttpPortNo);
                textBoxSdkCfg.Text   = Convert.ToString(m_struNetCfg.struEtherNet[0].wDVRPort);

                if (m_struNetCfg.byUseDhcp == 1)
                {
                    checkBoxDhcp.Checked = true;
                    TextEnable(false);
                }
                else
                {
                    checkBoxDhcp.Checked = false;
                }

                if (m_struNetCfg.struPPPoE.dwPPPOE == 1)
                {
                    checkBoxPPPoe.Checked = true;
                    textBoxPPPoeName.Text = System.Text.Encoding.UTF8.GetString(m_struNetCfg.struPPPoE.sPPPoEUser);
                    textBoxPPPoEPsw.Text  = m_struNetCfg.struPPPoE.sPPPoEPassword;
                    TextEnable(false);
                }

                else
                {
                    textBoxPPPoeName.Text = "";
                    textBoxPPPoEPsw.Text  = "";
                    checkBoxPPPoe.Checked = false;
                }

                if (m_struNetCfg.byUseDhcp == 0 && m_struNetCfg.struPPPoE.dwPPPOE == 0)
                {
                    TextEnable(true);
                }
            }
            Marshal.FreeHGlobal(ptrNetCfg);
        }
Esempio n. 12
0
 /// <summary>
 /// 海康主机登录
 /// </summary>
 public void HikHostLogin()
 {
     if (m_lstLoginInfo.Count > 0)
     {
         for (int i = 0; i < m_lstLoginInfo.Count; i++)
         {
             if (m_lstLoginInfo[i].iHandle == -1)
             {
                 NET_DVR_USER_LOGIN_INFO struLoginInfo = new NET_DVR_USER_LOGIN_INFO();
                 NET_DVR_DEVICEINFO_V40  devInfor      = new NET_DVR_DEVICEINFO_V40();
                 devInfor.byRes2 = new byte[246];
                 devInfor.struDeviceV30.sSerialNumber = new byte[48];
                 devInfor.byRes2 = new byte[246];
                 devInfor.struDeviceV30.sSerialNumber = new byte[48];
                 struLoginInfo.sDeviceAddress         = m_lstLoginInfo[i].sStreamIp;
                 struLoginInfo.wPort         = Convert.ToUInt16(m_lstLoginInfo[i].sPort); //设备服务端口
                 struLoginInfo.sUserName     = m_lstLoginInfo[i].sUser;                   //设备登录用户名
                 struLoginInfo.sPassword     = m_lstLoginInfo[i].sPass;                   //设备登录密码
                 struLoginInfo.bUseAsynLogin = false;                                     //同步登录方式(异步现在设备不在线时会报错,不知道啥原因)
                 struLoginInfo.byLoginMode   = 0;
                 struLoginInfo.byHttps       = 2;
                 //m_lstLoginInfo[i].iHandle = HikVideoAPI.NET_HIK_Login_V40(ref struLoginInfo, ref devInfor);
                 m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref devInfor);
                 //失败
                 if (m_lstLoginInfo[i].iHandle < 0)
                 {
                     CHCNetSDK.NET_DVR_Logout(m_lstLoginInfo[i].iHandle);
                     CHCNetSDK.NET_DVR_Cleanup();
                     return;
                 }
                 else
                 {
                     //存储数据用来计算通道号
                     NET_DVR_IPPARACFG_V40 oIpParaCfgV40 = new NET_DVR_IPPARACFG_V40();
                     uint   dwSize          = (uint)Marshal.SizeOf(oIpParaCfgV40);
                     IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);
                     Marshal.StructureToPtr(oIpParaCfgV40, ptrIpParaCfgV40, false);
                     uint dwReturn = 0;
                     //int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取
                     for (int iGroupNo = 0; iGroupNo < 4; iGroupNo++)
                     {
                         if (CHCNetSDK.NET_DVR_GetDVRConfig(m_lstLoginInfo[i].iHandle, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
                         {
                             oIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                             m_lstStruIpParaCfgV40.Add(oIpParaCfgV40);
                         }
                     }
                 }
                 //第二种登录
                 //CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                 //m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V30(m_lstLoginInfo[i].sIp, Convert.ToInt32(m_lstLoginInfo[i].sPort),
                 //    m_lstLoginInfo[i].sUser, m_lstLoginInfo[i].sPass, ref DeviceInfo);
             }
         }
     }
 }
Esempio n. 13
0
 /// <summary>
 /// 使用线程登录
 /// </summary>
 public void ThreadLogin()
 {
     //string file = "G:\\天津白泽技术有限公司项目\\天津白泽技术项目源文件等\\CentralEcoCity\\bin\\HCNetSDK.dll";
     //InitHikVideoSDK(m_iHCNetDllPath);
     Thread.Sleep(2000);
     while (true)
     {
         lock (m_oSingleLock)
         {
             if (m_lstLoginInfo.Count > 0)
             {
                 for (int i = 0; i < m_lstLoginInfo.Count; i++)
                 {
                     if (m_lstLoginInfo[i].iHandle == -1)
                     {
                         NET_DVR_USER_LOGIN_INFO struLoginInfo = new NET_DVR_USER_LOGIN_INFO();
                         NET_DVR_DEVICEINFO_V40  devInfor      = new NET_DVR_DEVICEINFO_V40();
                         devInfor.byRes2 = new byte[246];
                         devInfor.struDeviceV30.sSerialNumber = new byte[48];
                         devInfor.byRes2 = new byte[246];
                         devInfor.struDeviceV30.sSerialNumber = new byte[48];
                         struLoginInfo.sDeviceAddress         = m_lstLoginInfo[i].sIp;
                         struLoginInfo.wPort         = Convert.ToUInt16(m_lstLoginInfo[i].sPort); //设备服务端口
                         struLoginInfo.sUserName     = m_lstLoginInfo[i].sUser;                   //设备登录用户名
                         struLoginInfo.sPassword     = m_lstLoginInfo[i].sPass;                   //设备登录密码
                         struLoginInfo.bUseAsynLogin = false;                                     //同步登录方式(异步现在设备不在线时会报错,不知道啥原因)
                         struLoginInfo.byLoginMode   = 0;
                         //struLoginInfo.byHttps = 2;
                         //m_lstLoginInfo[i].iHandle = HikVideoAPI.NET_HIK_Login_V40(ref struLoginInfo, ref devInfor);
                         m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref devInfor);
                         //将通道信息和对应的ip存储到list集合中
                         if (m_lstLoginInfo[i].iHandle >= 0)
                         {
                             NET_DVR_IPPARACFG_V40 oIpParaCfgV40 = new NET_DVR_IPPARACFG_V40();
                             uint   dwSize          = (uint)Marshal.SizeOf(oIpParaCfgV40);
                             IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);
                             Marshal.StructureToPtr(oIpParaCfgV40, ptrIpParaCfgV40, false);
                             uint dwReturn = 0;
                             //int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取
                             for (int iGroupNo = 0; iGroupNo < 4; iGroupNo++)
                             {
                                 if (CHCNetSDK.NET_DVR_GetDVRConfig(m_lstLoginInfo[i].iHandle, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
                                 {
                                     oIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                                     m_lstStruIpParaCfgV40.Add(oIpParaCfgV40);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 14
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");
        }
Esempio n. 15
0
        /// <summary>
        /// 获取字符叠加配置
        /// </summary>
        private void GetConfig()
        {
            UInt32 dwReturn      = 0;
            Int32  nSize         = Marshal.SizeOf(m_struShowStrCfg);
            IntPtr ptrShowStrCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struShowStrCfg, ptrShowStrCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(_userID, CHCNetSDK.NET_DVR_GET_SHOWSTRING_V30, int.Parse(_cameraCfg.Channel), ptrShowStrCfg, (UInt32)nSize, ref dwReturn))
            {
            }
            else
            {
                m_struShowStrCfg = (CHCNetSDK.NET_DVR_SHOWSTRING_V30)Marshal.PtrToStructure(ptrShowStrCfg, typeof(CHCNetSDK.NET_DVR_SHOWSTRING_V30));
            }
            Marshal.FreeHGlobal(ptrShowStrCfg);

            //
        }
Esempio n. 16
0
        // get current DVR time --> timeDVR
        private bool TimeDVRUpdate()
        {
            uint bytesRet = 0;

            if (CHCNetSDK.NET_DVR_GetDVRConfig(
                    m_lUserID,
                    CHCNetSDK.NET_DVR_GET_TIMECFG,
                    0,
                    timePtr_DVR,
                    (uint)System.Runtime.InteropServices.Marshal.SizeOf(timeDVR),
                    ref bytesRet))
            {
                timeDVR = (CHCNetSDK.NET_DVR_TIME)MarshalToStruct(timePtr_DVR, typeof(CHCNetSDK.NET_DVR_TIME));
                //BeginInvoke(del, "TIMPMIN: " + timeDVR.dwMinute.ToString());
                return(true);
            }

            return(false);
        }
Esempio n. 17
0
        private void button2_Click(object sender, EventArgs e)
        {
            PreSetNo = 0;
            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++)
            {
                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));
                }
                labelP0Info.Text = Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wPanPos) + "/" +
                                   Convert.ToString(0.1 * m_struPreSetCfg[PreSetNo].wTiltPos) + "/" +
                                   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;
        }
Esempio n. 18
0
        private void btnDevCfgGet_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn     = 0;
            Int32  nSize        = Marshal.SizeOf(m_struDeviceCfg);
            IntPtr ptrDeviceCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struDeviceCfg, ptrDeviceCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_DEVICECFG_V40, -1, ptrDeviceCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GET_DEVICECFG_V40 failed, error code= " + iLastErr;
                //获取设备参数失败,输出错误号 Failed to get the basic parameters of device and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                m_struDeviceCfg = (CHCNetSDK.NET_DVR_DEVICECFG_V40)Marshal.PtrToStructure(ptrDeviceCfg, typeof(CHCNetSDK.NET_DVR_DEVICECFG_V40));

                textBoxDevName.Text     = System.Text.Encoding.GetEncoding("GBK").GetString(m_struDeviceCfg.sDVRName);
                textBoxDevType.Text     = System.Text.Encoding.UTF8.GetString(m_struDeviceCfg.byDevTypeName);
                textBoxANum.Text        = Convert.ToString(m_struDeviceCfg.byChanNum);
                textBoxIPNum.Text       = Convert.ToString(m_struDeviceCfg.byIPChanNum + 256 * m_struDeviceCfg.byHighIPChanNum);
                textBoxZeroNum.Text     = Convert.ToString(m_struDeviceCfg.byZeroChanNum);
                textBoxNetNum.Text      = Convert.ToString(m_struDeviceCfg.byNetworkPortNum);
                textBoxAlarmInNum.Text  = Convert.ToString(m_struDeviceCfg.byAlarmInPortNum);
                textBoxAlarmOutNum.Text = Convert.ToString(m_struDeviceCfg.byAlarmOutPortNum);
                textBoxDevSerial.Text   = System.Text.Encoding.UTF8.GetString(m_struDeviceCfg.sSerialNumber);

                uint iVer1 = (m_struDeviceCfg.dwSoftwareVersion >> 24) & 0xFF;
                uint iVer2 = (m_struDeviceCfg.dwSoftwareVersion >> 16) & 0xFF;
                uint iVer3 = m_struDeviceCfg.dwSoftwareVersion & 0xFFFF;
                uint iVer4 = (m_struDeviceCfg.dwSoftwareBuildDate >> 16) & 0xFFFF;
                uint iVer5 = (m_struDeviceCfg.dwSoftwareBuildDate >> 8) & 0xFF;
                uint iVer6 = m_struDeviceCfg.dwSoftwareBuildDate & 0xFF;

                textBoxDevVersion.Text = "V" + iVer1 + "." + iVer2 + "." + iVer3 + " Build " + string.Format("{0:D2}", iVer4) + string.Format("{0:D2}", iVer5) + string.Format("{0:D2}", iVer6);
            }
            Marshal.FreeHGlobal(ptrDeviceCfg);
        }
Esempio n. 19
0
        private void PtzRange_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn  = 0;
            Int32  nSize     = Marshal.SizeOf(m_struPtzCfg1);
            IntPtr ptrPtzCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struPtzCfg1, ptrPtzCfg, false);

            //获取参数失败
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PTZSCOPE, -1, ptrPtzCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_GetDVRConfig failed, error code= " + iLastErr;
                MessageBox.Show(str);
                return;
            }
            else
            {
                m_struPtzCfg1 = (CHCNetSDK.NET_DVR_PTZSCOPE)Marshal.PtrToStructure(ptrPtzCfg, typeof(CHCNetSDK.NET_DVR_PTZSCOPE));
                //成功获取显示ptz参数范围
                ushort wPanPosMax  = Convert.ToUInt16(Convert.ToString(m_struPtzCfg1.wPanPosMax, 16));
                float  WPanPosMax  = wPanPosMax * 0.1f;
                ushort wTiltPosMax = Convert.ToUInt16(Convert.ToString(m_struPtzCfg1.wTiltPosMax, 16));
                float  WTiltPosMax = wTiltPosMax * 0.1f;
                ushort wZoomPosMax = Convert.ToUInt16(Convert.ToString(m_struPtzCfg1.wZoomPosMax, 16));
                float  WZoomPosMax = wZoomPosMax * 0.1f;
                ushort wPanPosMin  = Convert.ToUInt16(Convert.ToString(m_struPtzCfg1.wPanPosMin, 16));
                float  WPanPosMin  = wPanPosMin * 0.1f;
                ushort wTiltPosMin = Convert.ToUInt16(Convert.ToString(m_struPtzCfg1.wTiltPosMin, 16));
                float  WTiltPosMin = wTiltPosMin * 0.1f;
                ushort wZoomPosMin = Convert.ToUInt16(Convert.ToString(m_struPtzCfg1.wZoomPosMin, 16));
                float  WZoomPosMin = wZoomPosMin * 0.1f;

                str          = "PMax=" + WPanPosMax + "    TMax=" + WTiltPosMax + "  ZMax=" + WZoomPosMax + "   PMin=" + WPanPosMin + "    TMin=" + WTiltPosMin + "  ZMin=" + WZoomPosMin;
                label13.Text = str;
            }
            return;
        }
Esempio n. 20
0
        private void button1_Click(object sender, EventArgs e)
        {
            CHCNetSDK.NET_DVR_TIME DevTime = new CHCNetSDK.NET_DVR_TIME();
            int    dwSize     = (int)Marshal.SizeOf(DevTime);
            IntPtr PtrDevTime = Marshal.AllocHGlobal(dwSize);

            Marshal.StructureToPtr(DevTime, PtrDevTime, true);
            uint    dwReturn = 0;
            Boolean res      = CHCNetSDK.NET_DVR_GetDVRConfig(m_loginID, CHCNetSDK.NET_DVR_GET_TIMECFG, 0, PtrDevTime, (uint)dwSize, ref dwReturn);

            DevTime = (CHCNetSDK.NET_DVR_TIME)Marshal.PtrToStructure(PtrDevTime, typeof(CHCNetSDK.NET_DVR_TIME));
            if (true == res)
            {
                g_formList.AddLog(iDevIndex, AcsDemoPublic.OPERATION_SUCC_T, "NET_DVR_GET_TIMECFG");
                textBoxDevTime.Text = DevTime.dwYear.ToString() + ":" + DevTime.dwMonth.ToString() + ":" + DevTime.dwDay.ToString() + ":" +
                                      DevTime.dwHour.ToString() + ":" + DevTime.dwMinute.ToString() + ":" + DevTime.dwSecond.ToString();
            }
            else
            {
                g_formList.AddLog(iDevIndex, AcsDemoPublic.OPERATION_FAIL_T, "NET_DVR_GET_TIMECFG");
            }
            Marshal.FreeHGlobal(PtrDevTime);
        }
Esempio n. 21
0
        /// <summary>
        /// cameraget
        /// </summary>
        /// <param name="m_lUserID"></param>
        /// <returns></returns>
        public int[] sptz(int m_lUserID)
        {
            int[]  xyz      = new int[3];
            UInt32 dwreturn = 0;

            CHCNetSDK.NET_DVR_PTZPOS x = new CHCNetSDK.NET_DVR_PTZPOS();
            Int32  nSize     = Marshal.SizeOf(x);
            IntPtr ptrPicCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(x, ptrPicCfg, false);
            bool re       = CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PTZPOS, 1, ptrPicCfg, (UInt32)nSize, ref dwreturn);
            uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();

            x = (CHCNetSDK.NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPicCfg, typeof(CHCNetSDK.NET_DVR_PTZPOS));

            loginfo.Info("NET_DVR_GetDVRConfig:" + iLastErr);
            xyz[0] = Convert.ToInt32(x.wPanPos);
            xyz[1] = Convert.ToInt32(x.wTiltPos);
            xyz[2] = Convert.ToInt32(x.wZoomPos);
            loginfo.Info("xyz:" + xyz[0] + xyz[1] + xyz[2]);

            return(xyz);
        }
Esempio n. 22
0
        public bool InitShowStr()
        {
            UInt32 dwReturn      = 0;
            Int32  nSize         = Marshal.SizeOf(m_struShowStrCfg);
            IntPtr ptrShowStrCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struShowStrCfg, ptrShowStrCfg, false);

            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_SHOWSTRING_V30, m_lChannel, ptrShowStrCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string strErr = "NET_DVR_GET_SHOWSTRING_V30 failed, error code= " + iLastErr;
                //获取字符叠加参数失败,输出错误号 Failed to get overlay parameters and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                m_struShowStrCfg = (CHCNetSDK.NET_DVR_SHOWSTRING_V30)Marshal.PtrToStructure(ptrShowStrCfg, typeof(CHCNetSDK.NET_DVR_SHOWSTRING_V30));
            }

            Marshal.FreeHGlobal(ptrShowStrCfg);

            return(true);
        }
Esempio n. 23
0
        public void Connection(bool loadCamera)
        {
            int[] iCameraNum  = new int[96];
            var   loginResult = CHCNetSDK.NET_DVR_Login_V30(this.IP,
                                                            this.Port,
                                                            this.UserName,
                                                            this.Password,
                                                            ref deviceInfo);

            UserId = loginResult;
            if (loginResult == -1)
            {
                if (ConnectionErrorAction != null)
                {
                    var arg = new HKErrorEventArg
                    {
                        Code = (int)CHCNetSDK.NET_DVR_GetLastError()
                    };
                    ConnectionErrorAction(this, arg);
                }
                this.Online = false;
                this.State  = ConnectionState.Offline;
                Logger.Default.Error($"摄像机:[{this.IP}] 连接失败!");
            }
            else
            {
                IntPtr outBuffer = new IntPtr();
                CHCNetSDK.NET_DVR_DEVICEINFO_V30 outInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
                uint outBufferReturn = 0;
                CHCNetSDK.NET_DVR_GetDVRConfig(UserId, CHCNetSDK.NET_DVR_GET_COMPRESSCFG_V30, deviceInfo.byStartChan, Marshal.ReadIntPtr(outInfo, 0), 10000000, ref outBufferReturn);
                string outBu = Marshal.PtrToStringAnsi(outBuffer);
                this.State  = ConnectionState.Online;
                this.Online = true;
                Logger.Default.Info($"摄像机:[{this.IP}] 连接成功!");
            }
        }
Esempio n. 24
0
        private void PtzGet_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn  = 0;
            Int32  nSize     = Marshal.SizeOf(m_struPtzCfg);
            IntPtr ptrPtzCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struPtzCfg, ptrPtzCfg, false);
            //获取参数失败
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PTZPOS, -1, ptrPtzCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_GetDVRConfig failed, error code= " + iLastErr;
                MessageBox.Show(str);
                return;
            }
            else
            {
                m_struPtzCfg = (CHCNetSDK.NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPtzCfg, typeof(CHCNetSDK.NET_DVR_PTZPOS));
                //成功获取显示ptz参数
                ushort wPanPos = Convert.ToUInt16(Convert.ToString(m_struPtzCfg.wPanPos, 16));
                float  WPanPos = wPanPos * 0.1f;
                textBoxPanPos.Text = Convert.ToString(WPanPos);
                ushort wTiltPos = Convert.ToUInt16(Convert.ToString(m_struPtzCfg.wTiltPos, 16));
                float  WTiltPos = wTiltPos * 0.1f;
                textBoxTiltPos.Text = Convert.ToString(WTiltPos);
                ushort wZoomPos = Convert.ToUInt16(Convert.ToString(m_struPtzCfg.wZoomPos, 16));
                float  WZoomPos = wZoomPos * 0.1f;
                textBoxZoomPos.Text = Convert.ToString(WZoomPos);

                /*textBoxPanPos.Text= Convert.ToString(Convert.ToUInt32(Convert.ToString(m_struPtzCfg.wPanPos,16))*0.1f,10);
                 * textBoxTiltPos.Text = Convert.ToString(Convert.ToUInt32(Convert.ToUInt32(Convert.ToString(m_struPtzCfg.wTiltPos, 16)) * 0.1f), 10);
                 * textBoxZoomPos.Text = Convert.ToString(Convert.ToUInt32(Convert.ToString(m_struPtzCfg.wZoomPos, 16)) * 0.1), 10);*/
                //textBoxPanPos.Text=Convert.ToString(m_struPtzCfg.wPanPos,16);
            }
            return;
        }
Esempio n. 25
0
        private void buttonGetEncode_Click(object sender, EventArgs e)
        {
            UInt32 dwReturn  = 0;
            Int32  nSize     = Marshal.SizeOf(m_struPicCfgV40);
            IntPtr ptrPicCfg = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(m_struPicCfgV40, ptrPicCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PICCFG_V40, m_lChannel, ptrPicCfg, (UInt32)nSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GET_PICCFG_V40 failed, error code= " + iLastErr;
                //获取图像参数失败,输出错误号 Failed to get image parameters and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                m_struPicCfgV40 = (CHCNetSDK.NET_DVR_PICCFG_V40)Marshal.PtrToStructure(ptrPicCfg, typeof(CHCNetSDK.NET_DVR_PICCFG_V40));
                if (m_struPicCfgV40.dwShowChanName == 1)
                {
                    checkBoxChanName.Checked = true;
                }
                else
                {
                    checkBoxChanName.Checked = false;
                }
                textBoxChanName.Text = System.Text.Encoding.GetEncoding("GBK").GetString(m_struPicCfgV40.sChanName);
                textBoxXName.Text    = Convert.ToString(m_struPicCfgV40.wShowNameTopLeftX);
                textBoxYName.Text    = Convert.ToString(m_struPicCfgV40.wShowNameTopLeftY);
                if (m_struPicCfgV40.dwShowOsd == 1)
                {
                    checkBoxOSD.Checked = true;
                }
                else
                {
                    checkBoxOSD.Checked = false;
                }
                if (m_struPicCfgV40.byDispWeek == 1)
                {
                    checkBoxWeek.Checked = true;
                }
                else
                {
                    checkBoxWeek.Checked = false;
                }
                comboBoxTime.SelectedIndex = m_struPicCfgV40.byHourOSDType;
                comboBoxDate.SelectedIndex = m_struPicCfgV40.byOSDType;

                if (m_struPicCfgV40.byFontSize == 0xff)
                {
                    comboBoxSize.SelectedIndex = 4;
                }
                else
                {
                    comboBoxSize.SelectedIndex = m_struPicCfgV40.byFontSize;
                }
                comboBoxDisplay.SelectedIndex = m_struPicCfgV40.byOSDAttrib - 1;
                textBoxXOSD.Text = Convert.ToString(m_struPicCfgV40.wOSDTopLeftX);
                textBoxYOSD.Text = Convert.ToString(m_struPicCfgV40.wOSDTopLeftY);
            }
            Marshal.FreeHGlobal(ptrPicCfg);
        }
Esempio n. 26
0
        public bool Login(bool bStatus)//true said add node login, false for the existing node to log in
        {
            LoginCallBackFlag = false;
            m_struDeviceInfo  = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();

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

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

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

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

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

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

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

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

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

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

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

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

            Marshal.StructureToPtr(struNetCfg, ptrNetCfg, false);

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

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

            Marshal.StructureToPtr(struDevCfg, ptrDevCfg, false);

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

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

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

            //}

            return(true);
        }
Esempio n. 27
0
        public bool DoGetDeviceResoureCfg(int iDeviceIndex, int iGroupNO = 0)
        {
            int  i = 0, j = 0;
            uint dwReturned = 0;
            int  dwSize     = 0;
            int  iLoopTime  = 0;

            if (g_deviceTree.g_struDeviceInfo[iDeviceIndex].iIPChanNum > 0)
            {
                if (g_deviceTree.g_struDeviceInfo[iDeviceIndex].iIPChanNum % (int)(CHCNetSDK.MAX_CHANNUM_V30) == 0)
                {
                    iLoopTime = g_deviceTree.g_struDeviceInfo[iDeviceIndex].iIPChanNum / (int)(CHCNetSDK.MAX_CHANNUM_V30);
                }
                else
                {
                    iLoopTime = g_deviceTree.g_struDeviceInfo[iDeviceIndex].iIPChanNum / (int)(CHCNetSDK.MAX_CHANNUM_V30) + 1;
                }
            }

            for (j = 0; j < iLoopTime; j++)
            {
                CHCNetSDK.NET_DVR_IPPARACFG_V40 struIPAccessCfgV40 = new CHCNetSDK.NET_DVR_IPPARACFG_V40();
                iGroupNO           = j;
                struIPAccessCfgV40 = g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruIPParaCfgV40[iGroupNO];
                dwSize             = Marshal.SizeOf(struIPAccessCfgV40);
                IntPtr ptrIPAccessCfgV40 = Marshal.AllocHGlobal(dwSize);
                Marshal.StructureToPtr(struIPAccessCfgV40, ptrIPAccessCfgV40, false);

                //2008-9-15 13:44 ip input configuration
                g_deviceTree.g_struDeviceInfo[iDeviceIndex].bIPRet =
                    CHCNetSDK.NET_DVR_GetDVRConfig(g_deviceTree.g_struDeviceInfo[iDeviceIndex].lLoginID, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNO, ptrIPAccessCfgV40, (uint)dwSize, ref dwReturned);
                if (!g_deviceTree.g_struDeviceInfo[iDeviceIndex].bIPRet)
                {       ///device no support ip access
                    g_deviceTree.g_struDeviceInfo[iDeviceIndex].lFirstEnableChanIndex = 0;
                    g_formList.AddLog(iDeviceIndex, AcsDemoPublic.OPERATION_FAIL_T, "NET_DVR_GET_IPPARACFG_V40");
                    i = j + iGroupNO * CHCNetSDK.MAX_CHANNUM_V30;
                    if (i < g_deviceTree.g_struDeviceInfo[iDeviceIndex].iAnalogChanNum)
                    {
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iDeviceIndex = iDeviceIndex;
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChanIndex   = i;
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChannelNO   = i + g_deviceTree.g_struDeviceInfo[iDeviceIndex].iStartChan;
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].bEnable      = true;
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChanType    = AcsDemoPublic.DEMO_CHANNEL_TYPE.DEMO_CHANNEL_TYPE_ANALOG;
                        g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].chChanName = string.Format("Camera{0}", i + g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iStartChan);;
                    }
                    else//clear the state of other channel
                    {
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iDeviceIndex = -1;
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChanIndex   = -1;
                        g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].bEnable      = false;
                        g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].chChanName = "";
                    }


                    g_deviceTree.g_struDeviceInfo[iDeviceIndex].iGroupNO = -1;
                }
                else
                {
                    struIPAccessCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIPAccessCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                    g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruIPParaCfgV40[iGroupNO] = struIPAccessCfgV40;
                    g_deviceTree.g_struDeviceInfo[iDeviceIndex].iGroupNO = iGroupNO;
                    g_formList.AddLog(iDeviceIndex, AcsDemoPublic.OPERATION_SUCC_T, "NET_DVR_GET_IPPARACFG_V40");
                    RefreshIPDevLocalCfg(iDeviceIndex);
                }
                Marshal.FreeHGlobal(ptrIPAccessCfgV40);
            }

            for (i = 0; i < g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iAnalogChanNum; i++)
            {
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].iDeviceIndex = m_iDeviceIndex;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].iChanIndex   = i;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].iChannelNO   = i + g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iStartChan;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].chChanName   = string.Format("Camera{0}", i + g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iStartChan);

                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].bEnable     = true;
                g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChanType     = AcsDemoPublic.DEMO_CHANNEL_TYPE.DEMO_CHANNEL_TYPE_ANALOG;
                g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i].dwImageType = AcsDemoPublic.CHAN_ORIGINAL;
            }

            if ((g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byMirrorChanNum > 0) &&
                (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].wStartMirrorChanNo > (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].iDeviceChanNum - 1)))
            {
                for (i = 0; i < g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byMirrorChanNum && i < 16; i++)
                {
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struMirrorChan[i].iDeviceIndex = m_iDeviceIndex;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struMirrorChan[i].iChanIndex   = i + AcsDemoPublic.MIRROR_CHAN_INDEX;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struMirrorChan[i].iChannelNO   = i + g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].wStartMirrorChanNo;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struMirrorChan[i].chChanName   = string.Format("MirrorChan{0}", i + 1);

                    //analog devices
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struMirrorChan[i].bEnable     = true;
                    g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChanType      = AcsDemoPublic.DEMO_CHANNEL_TYPE.DEMO_CHANNEL_TYPE_IP;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struMirrorChan[i].dwImageType = AcsDemoPublic.CHAN_ORIGINAL;
                }
            }
            if (g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byZeroChanNum > 0)
            {
                for (i = 0; i < g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].byZeroChanNum; i++)
                {
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struZeroChan[i].iDeviceIndex = m_iDeviceIndex;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struZeroChan[i].iChanIndex   = i + AcsDemoPublic.ZERO_CHAN_INDEX;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struZeroChan[i].chChanName   = string.Format("ZeroChan {0}", i);

                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struZeroChan[i].bEnable     = true;
                    g_deviceTree.g_struDeviceInfo[iDeviceIndex].pStruChanInfo[i].iChanType    = AcsDemoPublic.DEMO_CHANNEL_TYPE.DEMO_CHANNEL_TYPE_MIRROR;
                    g_deviceTree.g_struDeviceInfo[m_iDeviceIndex].struZeroChan[i].dwImageType = AcsDemoPublic.CHAN_ORIGINAL;
                }
            }
            return(g_deviceTree.g_struDeviceInfo[iDeviceIndex].bIPRet);
        }
Esempio n. 28
0
        public void InfoIPChannel()
        {
            uint dwSize = (uint)Marshal.SizeOf(m_struIpParaCfgV40);

            IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);

            Marshal.StructureToPtr(m_struIpParaCfgV40, ptrIpParaCfgV40, false);

            uint dwReturn = 0;
            int  iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取

            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str1     = "NET_DVR_GET_IPPARACFG_V40 failed, error code= " + iLastErr; //获取IP资源配置信息失败,输出错误号
                MessageBox.Show(str1);
            }
            else
            {
                // succ
                m_struIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));

                for (i = 0; i < dwAChanTotalNum; i++)
                {
                    ListAnalogChannel(i + 1, m_struIpParaCfgV40.byAnalogChanEnable[i]);
                    iChannelNum[i] = i + (int)DeviceInfo.byStartChan;
                }

                byte byStreamType;
                uint iDChanNum = 64;

                if (dwDChanTotalNum < 64)
                {
                    iDChanNum = dwDChanTotalNum; //如果设备IP通道小于64路,按实际路数获取
                }

                for (i = 0; i < iDChanNum; i++)
                {
                    iChannelNum[i + dwAChanTotalNum] = i + (int)m_struIpParaCfgV40.dwStartDChan;

                    byStreamType     = m_struIpParaCfgV40.struStreamMode[i].byGetStreamType;
                    m_unionGetStream = m_struIpParaCfgV40.struStreamMode[i].uGetStream;

                    switch (byStreamType)
                    {
                    //目前NVR仅支持0- 直接从设备取流一种方式
                    case 0:
                        dwSize = (uint)Marshal.SizeOf(m_unionGetStream);
                        IntPtr ptrChanInfo = Marshal.AllocHGlobal((Int32)dwSize);
                        Marshal.StructureToPtr(m_unionGetStream, ptrChanInfo, false);
                        m_struChanInfo = (CHCNetSDK.NET_DVR_IPCHANINFO)Marshal.PtrToStructure(ptrChanInfo, typeof(CHCNetSDK.NET_DVR_IPCHANINFO));

                        //列出IP通道
                        ListIPChannel(i + 1, m_struChanInfo.byEnable, m_struChanInfo.byIPID);
                        Marshal.FreeHGlobal(ptrChanInfo);
                        break;

                    default:
                        break;
                    }
                }
            }
            Marshal.FreeHGlobal(ptrIpParaCfgV40);
        }
Esempio n. 29
0
        /// <summary>
        /// 使用线程登录(使用)
        /// </summary>
        public void ThreadLogin()
        {
            int iDelay = 0;/*\ 延迟 /*/

            while (!m_bTerminated)
            {
                if (m_lstLoginInfo.Count == 0)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    iDelay = 0;
                    if (m_lstLoginInfo.Count > 0)
                    {
                        for (int i = 0; i < m_lstLoginInfo.Count; i++)
                        {
                            if (m_lstLoginInfo[i].iHandle == -1)
                            {
                                NET_DVR_USER_LOGIN_INFO struLoginInfo = new NET_DVR_USER_LOGIN_INFO();
                                NET_DVR_DEVICEINFO_V40  devInfor      = new NET_DVR_DEVICEINFO_V40();
                                devInfor.byRes2 = new byte[246];
                                devInfor.struDeviceV30.sSerialNumber = new byte[48];
                                devInfor.byRes2 = new byte[246];
                                devInfor.struDeviceV30.sSerialNumber = new byte[48];
                                struLoginInfo.sDeviceAddress         = m_lstLoginInfo[i].sIp;
                                struLoginInfo.wPort         = Convert.ToUInt16(m_lstLoginInfo[i].sPort); //设备服务端口
                                struLoginInfo.sUserName     = m_lstLoginInfo[i].sUser;                   //设备登录用户名
                                struLoginInfo.sPassword     = m_lstLoginInfo[i].sPass;                   //设备登录密码
                                struLoginInfo.bUseAsynLogin = false;                                     //同步登录方式(异步现在设备不在线时会报错,不知道啥原因)
                                struLoginInfo.byLoginMode   = 0;
                                //struLoginInfo.byHttps = 2;
                                //m_lstLoginInfo[i].iHandle = HikVideoAPI.NET_HIK_Login_V40(ref struLoginInfo, ref devInfor);
                                m_lstLoginInfo[i].iHandle = CHCNetSDK.NET_DVR_Login_V40(ref struLoginInfo, ref devInfor);
                                //将通道信息和对应的ip存储到list集合中
                                if (m_lstLoginInfo[i].iHandle >= 0)
                                {
                                    CSaveHikChannelInfo oSaveHikChannelInfo = new CSaveHikChannelInfo();
                                    oSaveHikChannelInfo.m_lstHikChannelInfo = new List <NET_DVR_IPPARACFG_V40>();
                                    oSaveHikChannelInfo.m_sStreamIp         = m_lstLoginInfo[i].sIp;
                                    NET_DVR_IPPARACFG_V40 oIpParaCfgV40 = new NET_DVR_IPPARACFG_V40();
                                    uint   dwSize          = (uint)Marshal.SizeOf(oIpParaCfgV40);
                                    IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize);
                                    Marshal.StructureToPtr(oIpParaCfgV40, ptrIpParaCfgV40, false);
                                    uint dwReturn = 0;
                                    //int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取
                                    /*\ 共16组每组64个 /*/
                                    for (int iGroupNo = 0; iGroupNo < 15; iGroupNo++)
                                    {
                                        if (CHCNetSDK.NET_DVR_GetDVRConfig(m_lstLoginInfo[i].iHandle, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn))
                                        {
                                            lock (m_oSingleLock)
                                            {
                                                oIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40));
                                                oSaveHikChannelInfo.m_lstHikChannelInfo.Add(oIpParaCfgV40);
                                                m_lstSaveHikChannelInfo.Add(oSaveHikChannelInfo);
                                            }
                                        }
                                    }
                                    Marshal.FreeHGlobal(ptrIpParaCfgV40);
                                }
                            }
                        }
                        while (!m_bTerminated)
                        {
                            iDelay++;
                            Thread.Sleep(1000);
                            if (iDelay > 10)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 30
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            uint dwCommand = 0;

            string[] strCommand            = { "NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50", "NET_DVR_GET_VERIFY_WEEK_PLAN", "NET_DVR_GET_WEEK_PLAN_CFG" };
            int      weekPlanNumberWPIndex = 0;

            uint   dwReturned = 0;
            string strTemp    = null;
            uint   dwSize     = (uint)Marshal.SizeOf(m_struPlanCfg);

            m_struPlanCfg.dwSize = dwSize;
            IntPtr ptrPlanCfg = Marshal.AllocHGlobal((int)dwSize);

            Marshal.StructureToPtr(m_struPlanCfg, ptrPlanCfg, false);
            switch (cbDeviceType.SelectedIndex)
            {
            case 0:
                dwCommand = (uint)CHCNetSDK.NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50;
                uint dwConSize = (uint)Marshal.SizeOf(m_struPlanCond);
                m_struPlanCond.dwSize = dwConSize;
                uint.TryParse(textBoxWPNumber.Text, out m_struPlanCond.dwWeekPlanNumber);
                ushort.TryParse(textBoxLCID.Text, out m_struPlanCond.wLocalControllerID);

                IntPtr ptrPlanCon = Marshal.AllocHGlobal((int)dwConSize);
                Marshal.StructureToPtr(m_struPlanCond, ptrPlanCon, false);
                IntPtr ptrDwReturned = Marshal.AllocHGlobal(4);

                if (!CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, dwCommand, 1, ptrPlanCon, dwConSize, ptrDwReturned, ptrPlanCfg, dwSize))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    Marshal.FreeHGlobal(ptrPlanCon);
                    Marshal.FreeHGlobal(ptrDwReturned);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[cbDeviceType.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    dwReturned = (uint)Marshal.ReadInt32(ptrDwReturned);
                    Marshal.FreeHGlobal(ptrDwReturned);
                    Marshal.FreeHGlobal(ptrPlanCon);
                    strTemp = string.Format("{0} Succ", strCommand[cbDeviceType.SelectedIndex]);
                    MessageBox.Show(strTemp);
                }
                break;

            case 1:
                dwCommand = (uint)CHCNetSDK.NET_DVR_GET_VERIFY_WEEK_PLAN;
                int.TryParse(textBoxWPNumber.Text, out weekPlanNumberWPIndex);

                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, dwCommand, weekPlanNumberWPIndex, ptrPlanCfg, dwSize, ref dwReturned))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[cbDeviceType.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    strTemp = string.Format("{0} Succ", strCommand[cbDeviceType.SelectedIndex]);
                    MessageBox.Show(strTemp);
                }
                break;

            case 2:
                dwCommand = (uint)CHCNetSDK.NET_DVR_GET_WEEK_PLAN_CFG;
                int.TryParse(textBoxWPNumber.Text, out weekPlanNumberWPIndex);

                if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, dwCommand, weekPlanNumberWPIndex, ptrPlanCfg, dwSize, ref dwReturned))
                {
                    Marshal.FreeHGlobal(ptrPlanCfg);
                    strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[cbDeviceType.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError());
                    MessageBox.Show(strTemp);
                    return;
                }
                else
                {
                    strTemp = string.Format("{0} Succ", strCommand[cbDeviceType.SelectedIndex]);
                    MessageBox.Show(strTemp);
                }
                break;

            default:
                Marshal.FreeHGlobal(ptrPlanCfg);
                MessageBox.Show("unknown command");
                return;
            }
            m_struPlanCfg        = (CHCNetSDK.NET_DVR_WEEK_PLAN_CFG)Marshal.PtrToStructure(ptrPlanCfg, typeof(CHCNetSDK.NET_DVR_WEEK_PLAN_CFG));
            cbDate.SelectedIndex = 0;
            UpdateList();

            if (1 == m_struPlanCfg.byEnable)
            {
                checkBoxEnableWP.Checked = true;
            }
            else
            {
                checkBoxEnableWP.Checked = false;
            }

            Marshal.FreeHGlobal(ptrPlanCfg);
        }