Exemple #1
0
        private List <IO> GetIOs()
        {
            var XMLIOs = _DB.Element("IOs").Elements().ToList();
            var IOs    = new List <IO>();

            //Return null if empty
            if (XMLIOs.Count == 0)
            {
                return(IOs);
            }

            foreach (var IO in XMLIOs)
            {
                var newIO = new IO
                {
                    Id             = Convert.ToInt32(IO.Attribute("Id").Value),
                    Name           = IO.Attribute("Name").Value,
                    Comment        = IO.Attribute("Comment").Value,
                    Location       = IO.Attribute("Location").Value,
                    ParentName     = IO.Attribute("ParentName").Value,
                    ComponentId    = Convert.ToInt32(IO.Attribute("ComponentId").Value),
                    ConnectionType = (ConnectionType)Convert.ToInt32(IO.Attribute("ConnectionType").Value),
                    MatchStatus    = (MatchStatus)Convert.ToInt32(IO.Attribute("MatchStatus").Value)
                };

                newIO.IOAddress      = new IOAddress();
                newIO.IOAddress.Type = (IOType)(Convert.ToInt32(IO.Attribute("IOAddressType").Value));

                switch (newIO.IOAddress.Type)
                {
                case (IOType.IO):
                    newIO.IOAddress.IPorMBAddress = " ";
                    newIO.IOAddress.Rack          = Convert.ToInt32(IO.Attribute("IOAddressRack").Value);
                    newIO.IOAddress.Module        = Convert.ToInt32(IO.Attribute("IOAddressModule").Value);
                    newIO.IOAddress.Channel       = Convert.ToInt32(IO.Attribute("IOAddressChannel").Value);

                    break;

                case (IOType.IP):
                    newIO.IOAddress.Rack          = 0;
                    newIO.IOAddress.Module        = 0;
                    newIO.IOAddress.Channel       = 0;
                    newIO.IOAddress.IPorMBAddress = IO.Attribute("IOAddressIPorMBAddress").Value;
                    break;

                case (IOType.MB):
                    newIO.IOAddress.Rack          = 0;
                    newIO.IOAddress.Module        = 0;
                    newIO.IOAddress.Channel       = 0;
                    newIO.IOAddress.IPorMBAddress = IO.Attribute("IOAddressIPorMBAddress").Value;
                    break;

                default:
                    throw new Exception("PLC address type not recognized - should be IO/IP/MB");
                }

                IOs.Add(newIO);
            }

            return(IOs);
        }