Пример #1
0
        public CHCNetSDK.NET_DVR_GIS_INFO GetGISInfo(string devIp, int devPort, string userName, string password)
        {
            int           userId        = -1;
            DevLoginModel devLoginModel = DeviceLogin(devIp, devPort, userName, password);

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

            CHCNetSDK.NET_DVR_GIS_INFO gis_info_tmp = new CHCNetSDK.NET_DVR_GIS_INFO();
            int    nSize      = Marshal.SizeOf(gis_info_tmp);
            IntPtr ptrGisInfo = Marshal.AllocHGlobal(nSize);

            Marshal.StructureToPtr(gis_info_tmp, ptrGisInfo, false);

            int    channel    = 1;
            int    nCondSize  = Marshal.SizeOf(channel);
            IntPtr ptrCondCfg = Marshal.AllocHGlobal(nCondSize);

            Marshal.StructureToPtr(channel, ptrCondCfg, false);

            CHCNetSDK.NET_DVR_STD_CONFIG std_config = new CHCNetSDK.NET_DVR_STD_CONFIG();
            std_config.lpStatusBuffer = IntPtr.Zero;
            std_config.dwStatusSize   = 0;
            std_config.lpOutBuffer    = ptrGisInfo;
            std_config.dwOutSize      = (uint)Marshal.SizeOf(gis_info_tmp);
            std_config.byDataType     = 0;
            std_config.lpCondBuffer   = ptrCondCfg;
            std_config.dwCondSize     = (uint)Marshal.SizeOf(channel);

            bool ret = CHCNetSDK.NET_DVR_GetSTDConfig(userId, CHCNetSDK.NET_DVR_GET_GISINFO, ref std_config);

            if (ret)
            {
                gis_info_tmp = (CHCNetSDK.NET_DVR_GIS_INFO)Marshal.PtrToStructure(ptrGisInfo, typeof(CHCNetSDK.NET_DVR_GIS_INFO));
            }

            Marshal.FreeHGlobal(ptrGisInfo);
            Marshal.FreeHGlobal(ptrCondCfg);

            return(gis_info_tmp);
        }
Пример #2
0
        private void GetEagleChannelAblity()//判断通道码流是否是鹰眼码流  对应的接口命令是 NET_DVR_GET_SINGLE_CHANNELINFO
        {
            const uint XML_ABILITY_OUT_LEN = 4 * 1024;
            IntPtr     ptrCoundBuffer;

            string pOutBuf    = "\0";
            uint   dwcondSize = 0;

            //[out]
            dwcondSize = sizeof(int);
            //CTinyXmlTrans XMLBASE = new CTinyXmlTrans();
            uint dwXmlSize = XML_ABILITY_OUT_LEN;

            if (g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo != null && g_struDeviceInfo[m_iDeviceIndex].iDeviceChanNum > 0)
            {
                for (int i = 0; i < g_struDeviceInfo[m_iDeviceIndex].iDeviceChanNum; i++)
                {
                    if (i >= Configurations.CameraCount)
                    {
                        break;
                    }
                    if (g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i + g_struDeviceInfo[m_iDeviceIndex].iGroupNO * 64].iChannelNO > 0)
                    {//存在的通道号
                        IntPtr m_pXmlOutBuf;
                        m_pXmlOutBuf   = Marshal.AllocHGlobal((Int32)XML_ABILITY_OUT_LEN);
                        ptrCoundBuffer = Marshal.AllocHGlobal((int)dwcondSize);
                        int m_lChannel = g_struDeviceInfo[m_iDeviceIndex].pStruChanInfo[i + g_struDeviceInfo[m_iDeviceIndex].iGroupNO * 64].iChannelNO;
                        Marshal.WriteInt32(ptrCoundBuffer, m_lChannel);
                        CHCNetSDK.NET_DVR_STD_CONFIG struCfg = new CHCNetSDK.NET_DVR_STD_CONFIG();
                        struCfg.lpCondBuffer = ptrCoundBuffer;
                        struCfg.dwCondSize   = dwcondSize;
                        struCfg.byDataType   = 1;
                        struCfg.lpXmlBuffer  = m_pXmlOutBuf;
                        struCfg.dwXmlSize    = dwXmlSize;
                        int    dwSTDSize = Marshal.SizeOf(struCfg);
                        IntPtr ptrSTDCfg = Marshal.AllocHGlobal(dwSTDSize);
                        Marshal.StructureToPtr(struCfg, ptrSTDCfg, false);
                        bool m_dwReturnValue = CHCNetSDK.NET_DVR_GetSTDConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_SINGLE_CHANNELINFO, ptrSTDCfg);
                        Marshal.FreeHGlobal(ptrCoundBuffer);
                        if (m_dwReturnValue)
                        {
                            int lentemp = (int)dwXmlSize;
                            pOutBuf = Marshal.PtrToStringAnsi(m_pXmlOutBuf, lentemp);

                            //XmlDocument xd = new XmlDocument();

                            //xd.LoadXml(pOutBuf);
                            ////使用xpath表达式选择文档中所有的student子节点
                            //XmlNodeList studentNodeList = xd.SelectNodes("ChannelInfo");
                            using (XmlReader xmlReader = XmlTextReader.Create(new StringReader(pOutBuf)))
                            {
                                try
                                {
                                    string parentnode = "";
                                    while (xmlReader.Read())
                                    {
                                        switch (xmlReader.NodeType)
                                        {
                                        case XmlNodeType.Element:
                                            if (xmlReader.Name == "ChannelInfo")
                                            {
                                                parentnode = "ChannelInfo";
                                                if (xmlReader.HasAttributes)
                                                {
                                                    //if (xmlReader.MoveToAttribute("EagleEye"))
                                                    //{
                                                    //}
                                                    //if (xmlReader.MoveToAttribute("PanoramicMetaData"))
                                                    //{
                                                    //}
                                                    //if (xmlReader.MoveToAttribute("InsertChanNo"))
                                                    //{
                                                    //}
                                                }
                                            }
                                            if (xmlReader.Name == "EagleEye")
                                            {
                                                parentnode = "EagleEye";
                                            }
                                            if (xmlReader.Name == "PanoramicMetaData")
                                            {
                                                parentnode = "PanoramicMetaData";
                                            }
                                            if (xmlReader.Name == "InsertChanNo" && parentnode == "PanoramicMetaData")
                                            {
                                                parentnode = "InsertChanNo";
                                                dicChannelType.Add(m_lChannel, EnumChannelType.EagleChannel);
                                            }
                                            break;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                }
                            }


                            //XMLBASE.Parse(pOutBuf);
                            //XMLBASE.SetRoot();
                            //string XMLStrTemp = XMLBASE.GetChildrenText();
                            //XMLStrTemp.Replace("\n", "\r\n");
                            //if (XMLBASE.FindElem("ChannelInfo") && XMLBASE.IntoElem())
                            //{
                            //    if (XMLBASE.FindElem("EagleEye") && XMLBASE.IntoElem())
                            //    {
                            //        if (XMLBASE.FindElem("PanoramicMetaData") && XMLBASE.IntoElem())
                            //        {
                            //            if (XMLBASE.FindElem("InsertChanNo"))
                            //            {
                            //                //string strChannel;
                            //                //strChannel = XMLBASE.GetAttributeValue("InsertChanNo");
                            //                dicChannelType.Add(i, EnumChannelType.EagleChannel);
                            //                //m_EagleEyeChannelStream = true;
                            //            }
                            //        }
                            //    }
                            //}
                        }
                        else
                        {
                            //m_dwLastError = CHCNetSDK.NET_DVR_GetLastError();
                        }
                        if (!dicChannelType.ContainsKey(m_lChannel))
                        {
                            dicChannelType.Add(m_lChannel, EnumChannelType.QiangJiChannel);
                        }
                        Marshal.FreeHGlobal(ptrSTDCfg);
                        Marshal.FreeHGlobal(m_pXmlOutBuf);
                    }
                }
            }
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            //CHCNetSDK.NET_DVR_CHANNEL_GROUP m_struTraverseCond = new CHCNetSDK.NET_DVR_CHANNEL_GROUP();
            //Int32 dwInBufferSize = Marshal.SizeOf(m_struTraverseCond);
            //m_struTraverseCond.dwSize = (uint)dwInBufferSize;
            //m_struTraverseCond.dwChannel = 1;
            //m_struTraverseCond.dwGroup = 1;
            //m_struTraverseCond.byID = 0;
            //IntPtr ptrTraverseCond = Marshal.AllocHGlobal(dwInBufferSize);
            //Marshal.StructureToPtr(m_struTraverseCond, ptrTraverseCond, false);

            //CHCNetSDK.NET_VCA_TRAVERSE_PLANE_DETECTION m_struTraverseCfg = new CHCNetSDK.NET_VCA_TRAVERSE_PLANE_DETECTION();
            //Int32 dwOutBufferSize = Marshal.SizeOf(m_struTraverseCfg);
            //IntPtr ptrTraverseCfg = Marshal.AllocHGlobal(dwOutBufferSize);
            //Marshal.StructureToPtr(m_struTraverseCfg, ptrTraverseCfg, false);

            //UInt32 dwStatusList = 0;
            //IntPtr lpStatusList = Marshal.AllocHGlobal(4);
            //Marshal.StructureToPtr(dwStatusList, lpStatusList, false);

            //if (!CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_TRAVERSE_PLANE_DETECTION, 1, ptrTraverseCond, (UInt32)dwInBufferSize, lpStatusList, ptrTraverseCfg, (UInt32)dwOutBufferSize))
            //{
            //    uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
            //    string str = "NET_ITS_GET_OVERLAP_CFG failed, error code= " + iLastErr;
            //}
            //else
            //{
            //    m_struTraverseCfg = (CHCNetSDK.NET_VCA_TRAVERSE_PLANE_DETECTION)Marshal.PtrToStructure(ptrTraverseCfg, typeof(CHCNetSDK.NET_VCA_TRAVERSE_PLANE_DETECTION));

            //}
            //Marshal.FreeHGlobal(ptrTraverseCond);
            //Marshal.FreeHGlobal(ptrTraverseCfg);
            //Marshal.FreeHGlobal(lpStatusList);

            /* CHCNetSDK.NET_DVR_THERMOMETRY_COND struThermometryCond = new CHCNetSDK.NET_DVR_THERMOMETRY_COND();
             * Int32 nCondSize = Marshal.SizeOf(struThermometryCond);
             * struThermometryCond.dwSize = (uint)nCondSize;
             * struThermometryCond.dwChannel = 2;
             * struThermometryCond.wPresetNo = 1;
             *
             * CHCNetSDK.NET_DVR_THERMOMETRY_ALARMRULE struThermometryAlarmRule = new CHCNetSDK.NET_DVR_THERMOMETRY_ALARMRULE();
             * Int32 nOutSize = Marshal.SizeOf(struThermometryAlarmRule);
             *
             * CHCNetSDK.NET_DVR_STD_CONFIG struConfigParam = new CHCNetSDK.NET_DVR_STD_CONFIG();
             * struConfigParam.lpCondBuffer = Marshal.AllocHGlobal(nCondSize);
             * Marshal.StructureToPtr(struThermometryCond, struConfigParam.lpCondBuffer, false);
             * struConfigParam.dwCondSize = (uint)nCondSize;
             * struConfigParam.lpOutBuffer = Marshal.AllocHGlobal(nOutSize);
             * struConfigParam.dwOutSize = (uint)nOutSize;
             *
             * if (!CHCNetSDK.NET_DVR_GetSTDConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_THERMOMETRY_ALARMRULE, ref struConfigParam))
             * {
             *  iLastErr = CHCNetSDK.NET_DVR_GetLastError();
             *  strErr = "NET_DVR_GET_THERMOMETRY_ALARMRULE failed, error code= " + iLastErr;
             *  //获取预置点测温报警规则配置,输出错误号 Failed to get the parameters of thermometry rule and output the error code
             *  MessageBox.Show(strErr);
             *  return;
             * }
             * struThermometryAlarmRule = (CHCNetSDK.NET_DVR_THERMOMETRY_ALARMRULE)Marshal.PtrToStructure(struConfigParam.lpOutBuffer, typeof(CHCNetSDK.NET_DVR_THERMOMETRY_ALARMRULE));
             * struThermometryAlarmRule.struThermometryAlarmRuleParam[0].szRuleName = "test_rule01";
             * struThermometryAlarmRule.struThermometryAlarmRuleParam[0].fAlert = 20;
             * struThermometryAlarmRule.struThermometryAlarmRuleParam[0].fAlarm = 30;
             * struThermometryAlarmRule.struThermometryAlarmRuleParam[0].fThreshold = 5;
             *
             * struConfigParam.lpInBuffer = Marshal.AllocHGlobal(nOutSize);
             * struConfigParam.dwInSize = (uint)nOutSize;
             * Marshal.StructureToPtr(struThermometryAlarmRule, struConfigParam.lpInBuffer, false);
             *
             * if (!CHCNetSDK.NET_DVR_SetSTDConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_THERMOMETRY_ALARMRULE, ref struConfigParam))
             * {
             *  iLastErr = CHCNetSDK.NET_DVR_GetLastError();
             *  strErr = "NET_DVR_SET_THERMOMETRY_ALARMRULE failed, error code= " + iLastErr;
             *  //设置预置点测温报警规则配置,输出错误号 Failed to set the parameters of thermometry rule and output the error code
             *  MessageBox.Show(strErr);
             * }
             * else
             * {
             *  MessageBox.Show("设置预置点测温报警规则配置成功!");
             * }
             */


            CHCNetSDK.NET_DVR_STD_CONFIG struConfigParam = new CHCNetSDK.NET_DVR_STD_CONFIG();
            uint dwChannel  = 2;
            uint dwCondSize = sizeof(uint);

            struConfigParam.lpCondBuffer = Marshal.AllocHGlobal((int)dwCondSize);
            Marshal.WriteInt32(struConfigParam.lpCondBuffer, (int)dwChannel);
            struConfigParam.dwCondSize = dwCondSize;

            CHCNetSDK.NET_SDK_MANUALTHERM_BASICPARAM struManulThermometryBasic = new CHCNetSDK.NET_SDK_MANUALTHERM_BASICPARAM();
            Int32 nOutSize = Marshal.SizeOf(struManulThermometryBasic);

            struConfigParam.lpOutBuffer = Marshal.AllocHGlobal(nOutSize);
            struConfigParam.dwOutSize   = (uint)nOutSize;

            if (!CHCNetSDK.NET_DVR_GetSTDConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_MANUALTHERM_BASICPARAM, ref struConfigParam))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_GET_THERMOMETRY_ALARMRULE failed, error code= " + iLastErr;
                //获取手动测温基本参数,输出错误号 Failed to get the basic parameters of manual thermometry and output the error code
                MessageBox.Show(strErr);
                return;
            }
            struManulThermometryBasic           = (CHCNetSDK.NET_SDK_MANUALTHERM_BASICPARAM)Marshal.PtrToStructure(struConfigParam.lpOutBuffer, typeof(CHCNetSDK.NET_SDK_MANUALTHERM_BASICPARAM));
            struManulThermometryBasic.wDistance = 20;
            struConfigParam.lpInBuffer          = Marshal.AllocHGlobal(nOutSize);
            struConfigParam.dwInSize            = (uint)nOutSize;
            Marshal.StructureToPtr(struManulThermometryBasic, struConfigParam.lpInBuffer, false);

            if (!CHCNetSDK.NET_DVR_SetSTDConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_MANUALTHERM_BASICPARAM, ref struConfigParam))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_SET_MANUALTHERM_BASICPARAM failed, error code= " + iLastErr;
                //设置手动测温基本参数失败,输出错误号 Failed to set the basic parameters of manual thermometry and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                MessageBox.Show("设置手动测温基本参数成功!");
            }


            //手动测温规则配置
            CHCNetSDK.NET_SDK_MANUAL_THERMOMETRY struManualTherm = new CHCNetSDK.NET_SDK_MANUAL_THERMOMETRY();
            int iInSize = Marshal.SizeOf(struManualTherm);

            struManualTherm.dwSize                = (uint)iInSize;
            struManualTherm.dwChannel             = 2;
            struManualTherm.byThermometryUnit     = 0; //测温单位: 0-摄氏度(℃),1-华氏度(℉),2-开尔文(K)
            struManualTherm.struRuleInfo.byRuleID = 1;
            struManualTherm.struRuleInfo.byEnable = 1;

            byte[] byName = System.Text.Encoding.Default.GetBytes("TestName");
            struManualTherm.struRuleInfo.szRuleName = new byte[32];
            byName.CopyTo(struManualTherm.struRuleInfo.szRuleName, 0);

            struManualTherm.struRuleInfo.byRuleCalibType             = 0;
            struManualTherm.struRuleInfo.struPointTherm.struPoint.fX = 0.50f; //归一化值,取值范围[0.001,1]
            struManualTherm.struRuleInfo.struPointTherm.struPoint.fY = 0.50f; //归一化值,取值范围[0.001,1]

            struConfigParam.lpCondBuffer = Marshal.AllocHGlobal((int)dwCondSize);
            Marshal.WriteInt32(struConfigParam.lpCondBuffer, (int)dwChannel);
            struConfigParam.dwCondSize = dwCondSize;

            struConfigParam.lpInBuffer = Marshal.AllocHGlobal(iInSize);
            struConfigParam.dwInSize   = (uint)iInSize;
            Marshal.StructureToPtr(struManualTherm, struConfigParam.lpInBuffer, false);

            if (!CHCNetSDK.NET_DVR_SetSTDConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_MANUALTHERM, ref struConfigParam))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_SET_MANUALTHERM failed, error code= " + iLastErr;
                //设置手动测温失败,输出错误号 Failed to set the manual thermometry and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                MessageBox.Show("设置手动测温成功!");
            }
        }