예제 #1
0
 static void ReadModbus(ModbusConfiguration config, XmlNode node)
 {
     foreach (XmlNode child in node.ChildNodes)
     {
         if (child.Name == "pollinginterval")
         {
             int  value = 0;
             bool r     = int.TryParse(child.InnerText, out value);
             if (!r)
             {
                 value = 10;
             }
             config.PollingInterval = value;
         }
         else if (child.Name == "mapping")
         {
             var dm = new DeviceTypeMapping();
             ReadDeviceTypeMapping(dm, child);
             config.DeviceTypes.Add(dm);
         }
         else if (child.Name == "device")
         {
             var dd = new DeviceDescription();
             ReadDeviceDescription(config, dd, child);
             config.Devices.Add(dd);
         }
     }
 }
예제 #2
0
        public static ModbusConfiguration ReadFromFile(string path)
        {
            var xml = new XmlDocument();

            xml.Load(path);

            var config = new ModbusConfiguration();

            foreach (XmlNode node in xml.ChildNodes)
            {
                //Console.WriteLine("Node: " + node.Name);

                if (node.Name == "modbus")
                {
                    ReadModbus(config, node);
                }
            }

            return(config);
        }
예제 #3
0
 static void ReadDeviceDescription(ModbusConfiguration config, DeviceDescription dd, XmlNode node)
 {
     dd.Name = node.Attributes["name"].Value;
     dd.Id   = node.Attributes["id"].Value;
     foreach (XmlNode child in node.ChildNodes)
     {
         if (child.Name == "network")
         {
             dd.IpAddress = child.Attributes["ipaddr"].Value;
             if (child.Attributes["port"] != null)
             {
                 dd.IpPort = ParseInt(child.Attributes["port"].Value, 502);
             }
         }
         else if (child.Name == "mapping")
         {
             dd.Mapping = config.DeviceTypes.Single(x => x.Name == child.Attributes["name"].Value);
         }
         else if (child.Name == "slave")
         {
             dd.SlaveAddress = ParseInt(child.Attributes["address"].Value, 126);
         }
     }
 }