Ejemplo n.º 1
0
        public GroupEntity(
            XmlNode node,
            DeviceEntity parent) :
            this(parent)
        {
            #region 从Xml节点属性中获取属性值
            if (node.Attributes["Name"] != null)
            {
                name = node.Attributes["Name"].Value;
            }
            #endregion

            XmlNode childNode = node.FirstChild;
            while (childNode != null)
            {
                if (childNode.Name == "Tag")
                {
                    TagEntity tag = new TagEntity(childNode, this);
                    Tags.Add(tag);
                }
                else if (childNode.Name == "SubTagGroup")
                {
                    SubGroupEntity subGroup = new SubGroupEntity(childNode, this);
                    SubGroups.Add(subGroup);
                }

                childNode = childNode.NextSibling;
            }
        }
Ejemplo n.º 2
0
 public static int CompareByDeviceName(DeviceEntity a, DeviceEntity b)
 {
     if (a == null)
     {
         if (b == null)
         {
             return(0);
         }
         else
         {
             return(-1);
         }
     }
     else
     {
         if (b == null)
         {
             return(1);
         }
         else
         {
             return(string.Compare(a.Name, b.Name));
         }
     }
 }
Ejemplo n.º 3
0
 public GroupEntity(DeviceEntity parent)
 {
     Parent =
         parent ??
         throw new Exception(
                   "标记组对象不能单独存在,必须要依赖于DeviceEntity对象");
     name = "NewGroup";
 }
Ejemplo n.º 4
0
        public void Modify(DeviceEntity device)
        {
            if (!devices.ContainsKey(device.ID))
            {
                throw new Exception($"未找到[{device.Name}]设备");
            }

            devices[device.ID] = device;
        }
Ejemplo n.º 5
0
        public void Add(
            DeviceEntity device,
            AddToWholeEntityQueueHandler addToWholeEntityQueueHandler)
        {
            if (devices.ContainsKey(device.ID))
            {
                throw new Exception("已经相同名称的设备");
            }

            devices.Add(device.ID, device);
            addToWholeEntityQueueHandler?.Invoke(device);
        }
Ejemplo n.º 6
0
        public static DeviceEntity ImportFromXmlNode(
            ProductionLineEntity line,
            XmlNode node,
            PLCType plcType,
            PLCEntity plcEntity)
        {
            DeviceEntity rlt = null;

            if (node.Name.ToUpper() != "DEVICE")
            {
                return(rlt);
            }

            rlt = new DeviceEntity(line)
            {
                Name    = XMLHelper.GetAttributeStringValue(node, "Name", ""),
                PLCType = plcType,
                DBType  =
                    (SiemensRegisterType)Enum.Parse(
                        typeof(SiemensRegisterType),
                        XMLHelper.GetAttributeStringValue(node, "DBType", "DB")),
                DBNumber      = XMLHelper.GetAttributeIntValue(node, "DBNumber", 0),
                CycleReadMode =
                    (CycleReadMode)Enum.Parse(
                        typeof(CycleReadMode),
                        XMLHelper.GetAttributeStringValue(node, "CycleReadBlock", "ControlBlock")),
                T133LeafID   = XMLHelper.GetAttributeIntValue(node, "T133LeafID", 0),
                T216LeafID   = XMLHelper.GetAttributeIntValue(node, "T216LeafID", 0),
                T107LeafID   = XMLHelper.GetAttributeIntValue(node, "T107LeafID", 0),
                SplitterTime = XMLHelper.GetAttributeIntValue(node, "SplitterTime", 100),
            };
            rlt.BelongPLC.IPAddress = plcEntity.IPAddress;
            rlt.BelongPLC.Rack      = plcEntity.Rack;
            rlt.BelongPLC.Slot      = plcEntity.Slot;

            XmlNode xmlGroup = node.FirstChild;

            while (xmlGroup != null)
            {
                GroupEntity group =
                    GroupEntity.ImportFromXmlNode(
                        rlt,
                        xmlGroup);
                if (group != null)
                {
                    rlt.Groups.Add(group);
                }

                xmlGroup = xmlGroup.NextSibling;
            }

            return(rlt);
        }
Ejemplo n.º 7
0
        public static GroupEntity ImportFromXmlNode(
            DeviceEntity parent,
            XmlNode node)
        {
            GroupEntity rlt = null;

            if (node.Name.ToUpper() != "TAGGROUP")
            {
                return(rlt);
            }

            rlt = new GroupEntity(parent)
            {
                Name = XMLHelper.GetAttributeStringValue(node, "Name", "Unknown"),
            };

            XmlNode child = node.FirstChild;

            while (child != null)
            {
                switch (child.Name.ToUpper())
                {
                case "TAG":
                    TagEntity tag =
                        TagEntity.ImportFromXmlNode(rlt, child);
                    if (tag != null)
                    {
                        rlt.Tags.Add(tag);
                    }
                    break;

                case "SUBTAGGROUP":
                    SubGroupEntity sgroup =
                        SubGroupEntity.ImportFromXmlNode(rlt, child);
                    if (sgroup != null)
                    {
                        rlt.SubGroups.Add(sgroup);
                    }
                    break;
                }

                child = child.NextSibling;
            }

            return(rlt);
        }
Ejemplo n.º 8
0
        public ProductionLineEntity(
            XmlNode node,
            AddToWholeEntityQueueHandler addToWholeEntityQueueHandler)
        {
            _addToWholeEntityQueueHandler = addToWholeEntityQueueHandler;

            #region 从Xml节点属性中获取属性值
            if (node.Attributes["Name"] != null)
            {
                Name = node.Attributes["Name"].Value;
            }
            #endregion

            XmlNode deviceNode = node.FirstChild;
            while (deviceNode != null)
            {
                if (deviceNode.Name.ToLower() == "device")
                {
                    try
                    {
                        DeviceEntity device =
                            new DeviceEntity(
                                deviceNode,
                                this,
                                addToWholeEntityQueueHandler);
                        if (device != null)
                        {
                            Devices.Add(device, addToWholeEntityQueueHandler);
                        }
                    }
                    catch (Exception error)
                    {
                        XtraMessageBox.Show(
                            error.Message,
                            "出错啦",
                            MessageBoxButtons.OK);
                    }
                }

                deviceNode = deviceNode.NextSibling;
            }
        }
Ejemplo n.º 9
0
        public List <DeviceEntity> ImportDevice(string path)
        {
            List <DeviceEntity> rlt = new List <DeviceEntity>();

            if (path == "")
            {
                return(rlt);
            }

            XmlDocument xml = new XmlDocument();

            try
            {
                xml.Load(path);
            }
            catch (Exception error)
            {
                throw new Exception(
                          $"解析[{Path.GetFileName(path)}]时出错:[{error.Message}]");
            }

            XmlNode root = xml.SelectSingleNode("root");

            if (root == null)
            {
                throw new Exception("配置文件中没有 root 根节点");
            }

            PLCType plcType = PLCType.SIEMENS;
            XmlNode plcNode = root.FirstChild;

            while (plcNode != null)
            {
                if (plcNode.Name.ToUpper() == "SIEMENSPLC")
                {
                    plcType = PLCType.SIEMENS;
                    PLCEntity plcEntity = new PLCEntity()
                    {
                        IPAddress = XMLHelper.GetAttributeStringValue(plcNode, "IPAddress", "127.0.0.1"),
                        Rack      = XMLHelper.GetAttributeIntValue(plcNode, "Rack", 0),
                        Slot      = XMLHelper.GetAttributeIntValue(plcNode, "Slot", 0),
                    };

                    XmlNode deviceNode = plcNode.FirstChild;
                    while (deviceNode != null)
                    {
                        DeviceEntity device =
                            DeviceEntity.ImportFromXmlNode(
                                this,
                                deviceNode,
                                plcType,
                                plcEntity);
                        if (device != null)
                        {
                            Devices.Add(device, _addToWholeEntityQueueHandler);
                            rlt.Add(device);
                        }

                        deviceNode = deviceNode.NextSibling;
                    }
                }

                plcNode = plcNode.NextSibling;
            }

            return(rlt);
        }
Ejemplo n.º 10
0
 public void Remove(DeviceEntity device)
 {
     device.RemoveChildren();
     devices.Remove(device.ID);
 }