Ejemplo n.º 1
0
        /// <summary>
        /// Tag对象注册事件
        /// </summary>
        /// <param name="group">TagGroup对象</param>
        /// <param name="tag">Tag对象</param>
        private void OnTagRegister(CustomGroup group, CustomTag tag)
        {
            _log.Trace($"Device[{Name}]:Tag[{tag.Name}],Offset[{tag.DB_Offset}]");

            if (!(tag is SiemensTag))
            {
                throw new Exception($"tag对象:{tag.Name}不是SiemensTag对象");
            }

            SiemensTag siemensTag = tag as SiemensTag;

            switch (CycleReadMode)
            {
            case SiemensCycleReadMode.FullBlock:
                FullBlock.Add(siemensTag.DB_Offset, siemensTag.Length);
                break;

            case SiemensCycleReadMode.ControlBlock:
                if (siemensTag.Type == TagType.C)
                {
                    string key = "";
                    if (group is SiemensTagGroup)
                    {
                        key = (group as SiemensTagGroup).Name;
                    }
                    else if (group is SiemensSubTagGroup)
                    {
                        SiemensSubTagGroup subGroup = group as SiemensSubTagGroup;
                        key = $"{subGroup.Parent.Name}.{subGroup.Prefix}";
                    }

                    PLCDBBlock block = ControlBlock[key];
                    if (block == null)
                    {
                        block = new PLCDBBlock();
                        ControlBlock.Add(key, block);
                    }
                    block.Add(siemensTag.DB_Offset, siemensTag.Length);
                }
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="parent">所属的TagGroup对象</param>
        /// <param name="node">Tag属性的Xml节点</param>
        public SiemensBoolOfTag(CustomGroup parent, XmlNode node) : base(parent, node)
        {
            _log = Logger.Get <SiemensBoolOfTag>();

            if (node.Attributes["Offset"] == null)
            {
                throw new Exception($"{Name}节点中未找到[Offset]属性,请注意属性名的大小写");
            }
            string[] offsets = node.Attributes["Offset"].Value.Split('.');
            int.TryParse(offsets[0], out int offset);
            DB_Offset = offset;
            if (offsets.Length >= 2)
            {
                int.TryParse(offsets[1], out int pos);
                Position = pos;
            }
            _log.Trace($"创建Tag[{Name}],Offset={DB_Offset},Position={Position}");

            value = false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建一个西门子Tag对象
        /// </summary>
        /// <param name="parent">Tag所属Group对象</param>
        /// <param name="node">Tag属性的Xml节点</param>
        public override CustomTag CreateProduct(CustomGroup parent, XmlNode node)
        {
            if (node.Name.ToUpper() != "TAG")
            {
                throw new Exception("node节点名不是Tag");
            }

            if (node.Attributes["Datatype"] == null)
            {
                throw new Exception("node节点中没有定义[Datatype]属性,请注意大小写");
            }

            string dataType = node.Attributes["Datatype"].Value;

            switch (dataType)
            {
            case "Bool":
                return(new SiemensBoolOfTag(parent, node));

            case "Byte":
                return(new SiemensByteOfTag(parent, node));

            case "Word":
                return(new SiemensWordOfTag(parent, node));

            case "Int":
                return(new SiemensIntOfTag(parent, node));

            case "DWord":
                return(new SiemensDWordOfTag(parent, node));

            case "Real":
                return(new SiemensRealOfTag(parent, node));

            case "ArrayChar":
                return(new SiemensArrayCharOfTag(parent, node));

            default:
                throw new Exception($"当前版本不支持Datatype=[{dataType}]类型的Tag");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="parent">所属的TagGroup对象</param>
 /// <param name="node">Tag属性的Xml节点</param>
 public SiemensTag(CustomGroup parent, XmlNode node) : base(parent, node)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="parent">所属的TagGroup对象</param>
 /// <param name="registerEvent">Tag对象在SiemensDevice对象中进行注册的委托</param>
 public SiemensTagCollection(CustomGroup parent, TagRegisterHandler registerEvent) :
     base(parent)
 {
     OnTagRegister = registerEvent;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="parent">Tag所属CustomGroup对象</param>
 /// <param name="node">Tag属性的Xml节点</param>
 public abstract CustomTag CreateProduct(CustomGroup parent, XmlNode node);