Example #1
0
        private static void addDevicestoNode(IDs groupID)
        {
            uint            errorInfo = 0;
            uint            utaskID   = myAPI.Kdm_GetGroupByGroup(mcuHandle, groupID, ref errorInfo);
            DeviceGroupInfo groupInfo = new DeviceGroupInfo();

            groupInfo.szGroupName = new byte[max_str_len];

            uint _uRtn = myAPI.Kdm_GetGroupNext(mcuHandle, utaskID, ref groupInfo, ref errorInfo);

            while (_uRtn != 0)
            {
                idsList.Add(groupInfo.groupID);
                addDevicestoNode(groupInfo.groupID);
                _uRtn = myAPI.Kdm_GetGroupNext(mcuHandle, utaskID, ref groupInfo, ref errorInfo);
            }
        }
Example #2
0
        /// <summary>
        /// GetFacilities by craftDID
        /// </summary>
        /// <param name="craftDID">craftDID</param>
        /// <returns></returns>
        public IList <FacilityInfo> GetFacilities(int craftDID)
        {
            List <FacilityInfo> lst = new List <FacilityInfo>();
            DataTable           dt  = getFacilities(craftDID);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    FacilityInfo info = new FacilityInfo();
                    info.FacilityDID    = int.Parse(row[0].ToString());
                    info.MMName         = row[1].ToString();
                    info.ProcessDID     = int.Parse(row[2].ToString());
                    info.DeviceGroupDID = int.Parse(row[3].ToString());
                    info.State          = int.Parse(row[4].ToString());
                    info.MMIP           = row[5].ToString();
                    info.MMPort         = row[6].ToString();
                    info.MMIsUse        = row[7].ToString() == "1" ? true : false;
                    info.MMClearAddr    = row[8].ToString();
                    info.MMRestAddr     = row[9].ToString();
                    if (row[10].ToString() != "")
                    {
                        info.MMSeq = int.Parse(row[10].ToString());
                    }
                    info.MAAddress = row[11].ToString();
                    info.IsUse     = row[12].ToString() == "1" ? true : false;
                    info.Remark    = row[13].ToString();

                    ProcessInfo processInfo = new ProcessInfo();
                    DataTable   tbProcess   = getProcessesByID(info.ProcessDID);
                    if (tbProcess != null && tbProcess.Rows.Count > 0)
                    {
                        processInfo.ProcessDID  = int.Parse(tbProcess.Rows[0][0].ToString());
                        processInfo.ProcessNO   = tbProcess.Rows[0][1].ToString();
                        processInfo.ProcessName = tbProcess.Rows[0][2].ToString();
                        processInfo.CraftDID    = int.Parse(tbProcess.Rows[0][3].ToString());


                        DataTable tb = getCraftsByID(processInfo.CraftDID);
                        if (tb != null && tb.Rows.Count > 0)
                        {
                            CraftInfo craftInfo = new CraftInfo();
                            craftInfo.CraftDID  = processInfo.CraftDID;
                            craftInfo.CraftNO   = tb.Rows[0][1].ToString();
                            craftInfo.CraftName = tb.Rows[0][2].ToString();
                            processInfo.Craft   = craftInfo;
                        }
                        else
                        {
                            processInfo.Craft = null;
                            throw new Exception("执行getCraftsByID查询为空");
                        }
                        info.Process = processInfo;
                    }
                    else
                    {
                        info.Process = null;
                        processInfo  = null;
                        throw new Exception("执行getProcessesByID查询为空");
                    }



                    DataTable tbDeviceGroup = getDeviceGroupByID(info.DeviceGroupDID);
                    if (tbDeviceGroup != null && tbDeviceGroup.Rows.Count > 0)
                    {
                        DeviceGroupInfo deviceGroupInfo = new DeviceGroupInfo();
                        deviceGroupInfo.DeviceGroupDID  = info.DeviceGroupDID;
                        deviceGroupInfo.DeviceGroupNO   = tbDeviceGroup.Rows[0][1].ToString();
                        deviceGroupInfo.DeviceGroupName = tbDeviceGroup.Rows[0][2].ToString();
                        deviceGroupInfo.CraftDID        = int.Parse(tbDeviceGroup.Rows[0][3].ToString());


                        DataTable tb = getCraftsByID(deviceGroupInfo.CraftDID);
                        if (tb != null && tb.Rows.Count > 0)
                        {
                            CraftInfo craftInfo = new CraftInfo();
                            craftInfo.CraftDID    = processInfo.CraftDID;
                            craftInfo.CraftNO     = tb.Rows[0][1].ToString();
                            craftInfo.CraftName   = tb.Rows[0][2].ToString();
                            deviceGroupInfo.Craft = craftInfo;
                        }
                        else
                        {
                            deviceGroupInfo.Craft = null;
                            throw new Exception("执行getCraftsByID查询为空");
                        }

                        info.DeviceGroup = deviceGroupInfo;
                    }
                    else
                    {
                        info.DeviceGroup = null;
                        throw new Exception("执行getDeviceGroupByID查询为空");
                    }
                    lst.Add(info);
                }
            }
            return(lst);
        }
Example #3
0
        static void Main(string[] args)
        {
            uint errorInfo = 0;

            bool isLogined = false;

            mcuHandle = myAPI.Kdm_CreateMcuSdk();
            uint ret = myAPI.Kdm_Init(mcuHandle);

            myAPI.Kdm_SetScreenShowLog(mcuHandle, 1);
            byte[] filename;
            filename = stringToBytes("c:\\log", max_id_len);
            myAPI.Kdm_SetSaveLogFile(mcuHandle, 1, filename);

            cbFun       = new myAPI.cbFreshDevStatusD(cbFreshDevStatus);
            cbEventInfo = new myAPI.cbSDKEventCallbackD(cbSDKEventCallback);
            myAPI.Kdm_SetSDKEventCallback(mcuHandle, cbEventInfo, 0);
            DateTime myNow = DateTime.Now;

            m_startTime = new DateTime(myNow.Year, myNow.Month, myNow.Day, 0, 0, 0, 0);
            m_endTime   = m_startTime.AddDays(1);
            //startTime.Text = m_startTime.Date.ToString();
            //endTime.Text = m_endTime.Date.ToString();
            //cb_platform.Checked = true;
            uint errorCode = 0;

            // 切换码流的浏览方式
            myAPI.Kdm_SetStreamPattern(mcuHandle, 0, ref errorCode);

            string strIP       = "45.4.8.10";
            string strUserName = "******";
            string strPassWord = "******";

            byte[] byteIP       = stringToBytes(strIP, 257);
            byte[] byteUserName = stringToBytes(strUserName, 257);
            byte[] bytePassWord = stringToBytes(strPassWord, 257);

            // 初始化登录平台
            EBussinessMod type = myAPI.Kdm_PlatTypeDetect(mcuHandle, byteIP, ref errorInfo);

            myAPI.Kdm_ModualSelect(mcuHandle, type, EStreamMod.emG900, EDecoderMod.emBaseDec);
            ret = myAPI.Kdm_Login(mcuHandle, byteUserName, bytePassWord, byteIP, "windows", ref errorInfo);
            if (ret != 1)
            {
                isLogined = false;
                Console.WriteLine("登录失败");
            }
            else
            {
                isLogined = true;
                //设置设备状态回调
                myAPI.Kdm_SetDevStatusCallback(mcuHandle, cbFun, 0);
                Console.WriteLine("登录成功");


                // 获取分组
                string temp = "";
                IDs    root = new IDs();
                root.szID = stringToBytes(temp, max_id_len);
                uint            utaskID   = myAPI.Kdm_GetGroupByGroup(mcuHandle, root, ref errorInfo);
                DeviceGroupInfo groupInfo = new DeviceGroupInfo();
                groupInfo.szGroupName = new byte[max_str_len];
                idsList.Clear();

                uint _uRtn = myAPI.Kdm_GetGroupNext(mcuHandle, utaskID, ref groupInfo, ref errorInfo);
                while (_uRtn != 0)
                {
                    string deviceName    = bytesToString(groupInfo.szGroupName);
                    string deviceGroupID = bytesToString(groupInfo.groupID.szID);
                    string groupUnnamed  = "IsUnnamedGroup";
                    if (deviceGroupID.Substring(0, groupUnnamed.Length) == groupUnnamed)
                    {
                        deviceName = "未分组";
                    }
                    idsList.Add(groupInfo.groupID);
                    addDevicestoNode(groupInfo.groupID);
                    _uRtn = myAPI.Kdm_GetGroupNext(mcuHandle, utaskID, ref groupInfo, ref errorInfo);
                }



                // 获取设备
                for (int i = 0; i < idsList.Count; i++)
                {
                    Console.WriteLine(i + 1 + "/" + idsList.Count);
                    uint   utID       = myAPI.Kdm_GetDeviceByGroup(mcuHandle, idsList[i], ref errorInfo);
                    string deviceName = bytesToString(idsList[i].szID);
                    uint   uRet       = 1;
                    while (uRet != 0)
                    {
                        DeviceInfo deviceInfo = new DeviceInfo();
                        deviceInfo.deviceID           = new IDs();
                        deviceInfo.deviceID.szID      = new byte[max_id_len];
                        deviceInfo.domainID           = new IDs();
                        deviceInfo.domainID.szID      = new byte[max_id_len];
                        deviceInfo.szDevSrcAlias      = new byte[max_str_len];
                        deviceInfo.szManufacturer     = new byte[max_str_len];
                        deviceInfo.aDevSrcChn         = new VIDSRC[128];
                        deviceInfo.parentGroupID      = new IDs();
                        deviceInfo.parentGroupID.szID = new byte[max_id_len];
                        for (int x = 0; x < 128; x++)
                        {
                            deviceInfo.aDevSrcChn[x].szSrcName = new byte[max_str_len];
                        }
                        uRet = myAPI.Kdm_GetDeviceNext(mcuHandle, utID, ref deviceInfo, ref errorInfo);

                        if (uRet != 0)
                        {
                            if ((deviceInfo.nDevType == (UInt16)eDeviceType.emTypeEncoder) ||
                                (deviceInfo.nDevType == (UInt16)eDeviceType.emTypeSVR) ||
                                (deviceInfo.nDevType == (UInt16)eDeviceType.emTypeNVR))
                            {
                                allDeviceList.Add(deviceInfo);
                            }
                        }
                    }
                }

                // 获取状态
                ESubscriptInfo emDevSubType = (ESubscriptInfo.emOnline | ESubscriptInfo.emVidChn);
                TSUBSDEVS      tSubsDEV     = new TSUBSDEVS();
                tSubsDEV.m_bySubsDevNum = 1;
                tSubsDEV.m_vctDevID     = new IDs[20];
                for (int i = 0; i < 20; i++)
                {
                    tSubsDEV.m_vctDevID[i].szID = new byte[max_id_len];
                }

                int y = 0;
                for (int j = 0; j < allDeviceList.Count; j++)
                {
                    if (y < 20)
                    {
                        Array.Copy(allDeviceList[j].deviceID.szID, 0, tSubsDEV.m_vctDevID[y].szID, 0, max_id_len);
                    }
                    y++;
                    if (y == 20 || j == allDeviceList.Count - 1)
                    {
                        tSubsDEV.m_bySubsDevNum = (Byte)y;
                        myAPI.Kdm_SubscriptDeviceStatus(mcuHandle, tSubsDEV, emDevSubType, ref errorInfo);
                        y = 0;
                    }
                }

                System.Threading.Thread.Sleep(10000);
                Console.Write("按任意键继续...");
                Console.ReadKey();



                // 生成在线列表
                for (int j = 0; j < allDeviceList.Count; j++)
                {
                    DEVSRC_ST _DEVSRC_ST = new DEVSRC_ST();
                    _DEVSRC_ST.bEnable = new bool();
                    _DEVSRC_ST.bOnline = new bool();

                    DEVCHN tDevSrc = new DEVCHN();
                    tDevSrc.deviceID.szID = allDeviceList[j].deviceID.szID;
                    tDevSrc.domainID.szID = allDeviceList[j].domainID.szID;
                    tDevSrc.nSrc          = 0;
                    tDevSrc.nChn          = 0;

                    DEVCHN tDevDst = new DEVCHN();
                    tDevDst.deviceID.szID = allDeviceList[j].deviceID.szID;
                    tDevDst.domainID.szID = allDeviceList[j].domainID.szID;
                    tDevDst.nSrc          = 0;
                    tDevDst.nChn          = 0;

                    uint r1 = myAPI.Kdm_GetDevSrcStatus(mcuHandle, tDevSrc, ref _DEVSRC_ST, ref errorInfo);
                    uint r2 = myAPI.Kdm_GetDeviceGBID(mcuHandle, tDevSrc, ref tDevDst, ref errorInfo);
                    if (_DEVSRC_ST.bOnline)
                    {
                        onlineList.Add(bytesToString(tDevDst.deviceID.szID).Substring(0, 20));
                        //Console.WriteLine("gbId:" + bytesToString(tDevDst.deviceID.szID).Substring(0, 20));
                    }
                    // 生成全量设备列表
                    allList.Add(bytesToString(tDevDst.deviceID.szID).Substring(0, 20));
                }

                // 生成在线xml文件

                if (File.Exists("online.xml"))
                {
                    File.Delete("online.xml");
                }

                for (int i = 0; i < onlineList.Count; i++)
                {
                    if (i == 0)
                    {
                        File.AppendAllText("online.xml", "<?xml version=\"1.0\" encoding=\"GBK\" standalone = \"no\" ?>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<XmlRoot>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<UserInfo>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<UserName>admin</UserName>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "</UserInfo>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<Switch>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<!--0 无限制, 1 仅限主流, 2 仅限辅流-->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<PriSec>1</PriSec>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<!--0 无限制, 1 正选, 2 反选-->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<IdLimit>1</IdLimit>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "</Switch>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<!--国标限制,把有限制的设备国标ID列在此处,EntryNum为ID的总个数 -->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<!---如<EntryNum>2</EntryNum><Entry0>31010000001120000086</Entry0><Entry1>31010000001120000090</Entry1>-->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<GbId>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("online.xml", "<EntryNum>" + onlineList.Count + "</EntryNum>\n", Encoding.GetEncoding("GBK"));
                    }
                    File.AppendAllText("online.xml", "<Entry" + i + ">" + onlineList[i] + "</Entry" + i + ">\n", Encoding.GetEncoding("GBK"));
                }
                File.AppendAllText("online.xml", "</GbId>\n", Encoding.GetEncoding("GBK"));
                File.AppendAllText("online.xml", "</XmlRoot>\n", Encoding.GetEncoding("GBK"));


                // 生成所有设备xml文件

                if (File.Exists("all.xml"))
                {
                    File.Delete("all.xml");
                }

                for (int i = 0; i < allList.Count; i++)
                {
                    if (i == 0)
                    {
                        File.AppendAllText("all.xml", "<?xml version=\"1.0\" encoding=\"GBK\" standalone = \"no\" ?>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<XmlRoot>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<UserInfo>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<UserName>admin</UserName>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "</UserInfo>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<Switch>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<!--0 无限制, 1 仅限主流, 2 仅限辅流-->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<PriSec>1</PriSec>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<!--0 无限制, 1 正选, 2 反选-->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<IdLimit>1</IdLimit>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "</Switch>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<!--国标限制,把有限制的设备国标ID列在此处,EntryNum为ID的总个数 -->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<!---如<EntryNum>2</EntryNum><Entry0>31010000001120000086</Entry0><Entry1>31010000001120000090</Entry1>-->\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<GbId>\n", Encoding.GetEncoding("GBK"));
                        File.AppendAllText("all.xml", "<EntryNum>" + allList.Count + "</EntryNum>\n", Encoding.GetEncoding("GBK"));
                    }
                    File.AppendAllText("all.xml", "<Entry" + i + ">" + allList[i] + "</Entry" + i + ">\n", Encoding.GetEncoding("GBK"));
                }
                File.AppendAllText("all.xml", "</GbId>\n", Encoding.GetEncoding("GBK"));
                File.AppendAllText("all.xml", "</XmlRoot>\n", Encoding.GetEncoding("GBK"));
            }

            Console.Write("按任意键关闭...");
            Console.ReadKey();
        }
Example #4
0
 //通过“组查询任务ID”获得组信息
 public extern static uint Kdm_GetGroupNext(IntPtr mcuHandle, uint taskID, ref DeviceGroupInfo groupID, ref uint errorCode);