Ejemplo n.º 1
0
        /// <summary>
        /// 根据关键字处理指定TagGroup所对应的数据块数据
        /// </summary>
        private void DealPartBlockBuffer(string key, byte[] buffer)
        {
            PLCDBBlock block = ControlBlock[key];

            if (block != null && key != "COMM")
            {
                _log.Debug(
                    $"[{key}.Offset={block.Start_Offset}, " +
                    $"{key}.Length={block.BufferLength}]");
                _log.Debug($"[{key}]|[Data:{Tools.BytesToBCD(buffer)}]");
            }

            // 根据key解析出TagGroup和SubTagGroup
            string[] keys           = key.Split('.');
            string   keyTagGroup    = keys[0];
            string   keySubTagGroup = "";

            if (keys.Length >= 2)
            {
                keySubTagGroup = keys[1];
            }

            SiemensTagGroup group = _groups[keyTagGroup] as SiemensTagGroup;

            if (group == null)
            {
                _log.Error($"设备[{Name}]未找到[{keyTagGroup}]Tag组");
                return;
            }
            if (keySubTagGroup == "")
            {
                SetControlTagValueInGroup(group, buffer, block.Start_Offset);
            }
            else
            {
                SiemensSubTagGroup subGroup =
                    group.SubGroups[keySubTagGroup] as SiemensSubTagGroup;
                if (subGroup == null)
                {
                    _log.Error($"设备[{Name}]未找到[{keyTagGroup}.{keySubTagGroup}]Tag组");
                    return;
                }
                else
                {
                    SetControlTagValueInGroup(subGroup, buffer, block.Start_Offset);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 设置控制Tag值
 /// </summary>
 /// <param name="group">TagGroup对象</param>
 /// <param name="buffer">数据块内容</param>
 /// <param name="offset">当前数据块内容在整个数据块的起始偏移量</param>
 private void SetControlTagValueInGroup(
     SiemensTagGroup group,
     byte[] buffer,
     int offset)
 {
     foreach (CustomTag tag in group.Tags)
     {
         if (tag.Type == TagType.C)
         {
             if (SetTagValue(buffer, tag, offset))
             {
                 ControlTagValueChanged(tag);
             }
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 处理 FullBlock 模式下获取到的数据块数据
 /// </summary>
 /// <param name="buffer">数据块数据</param>
 private void DealFullBlockModeBuffer(byte[] buffer)
 {
     foreach (CustomTagGroup group in _groups)
     {
         SiemensTagGroup sGroup = group as SiemensTagGroup;
         foreach (CustomTag tag in sGroup.Tags)
         {
             SetTagValue(buffer, tag, 0);
         }
         foreach (SiemensSubTagGroup subGroup in sGroup.SubGroups)
         {
             foreach (CustomTag tag in subGroup.Tags)
             {
                 SetTagValue(buffer, tag, 0);
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 增加TagGroup对象
        /// </summary>
        /// <param name="group">TagGroup对象</param>
        public override void Add(CustomTagGroup group)
        {
            if (!(group is SiemensTagGroup))
            {
                throw new Exception("group对象必须是SiemensTagGroup对象");
            }

            SiemensTagGroup sGroup = group as SiemensTagGroup;

            if (sGroup.Parent != _parent)
            {
                throw new Exception("group对象隶属的设备和当前TagGroup集合不是同一个设备");
            }

            if (_groups.Keys.Contains(sGroup.Name))
            {
                throw new Exception($"当前TagGroup集合中已经存在[{sGroup.Name}]!");
            }

            _groups.Add(sGroup.Name, group);
        }