예제 #1
0
        public bool LoadFromFile(String fileName,bool merge)
        {
            if (!File.Exists(fileName))
                return false;

            Xml watchList = new Xml(fileName);
            watchList.RootName = "watchlist";
            String[] sections = watchList.GetSectionNames();

            if (sections.Length == 0)
                return false;

            if(!merge)
                Clear();

            Array.Sort(sections);
            String sectionName, name, addressString;
            int sizeInt;
            WatchDataSize dataSize;
            UInt32[] address;

            for (int i = 0; i < sections.Length; i++)
            {
                sectionName = sections[i];
                if(!watchList.HasEntry(sections[i],"name"))
                    continue;
                if(!watchList.HasEntry(sections[i],"address"))
                    continue;

                name = watchList.GetValue(sections[i], "name", "Name");
                addressString = watchList.GetValue(sections[i], "address", "80000000");
                if (!TryStrToAddressList(addressString, out address))
                    continue;

                sizeInt = watchList.GetValue(sections[i], "size", 2);
                switch (sizeInt)
                {
                    case 0:
                        dataSize = WatchDataSize.Bit8;
                        break;
                    case 1:
                        dataSize = WatchDataSize.Bit16;
                        break;
                    case 3:
                        dataSize = WatchDataSize.SingleFp;
                        break;
                    default:
                        dataSize = WatchDataSize.Bit32;
                        break;
                }

                AddWatch(name, address, dataSize);
            }

            return true;
        }