private short GetMaxAddress(SiemensPLCAddress addr)
        {
            short result = 0;

            if (addr != null)
            {
                if (addr.Type == "int32")
                {
                    result = (short)(addr.Offset + 3);
                }
                else if (addr.Type == "int16")
                {
                    result = (short)(addr.Offset + 1);
                }
                else if (addr.Type == "bool")
                {
                    result = addr.Offset;
                }
                else if (addr.Type == "string")
                {
                    result = (short)(addr.Offset + 2 + addr.BitOffset - 1);
                }
                else if (addr.Type == "ByteArray") //2020/6/11 ByteArray
                {
                    result = (short)(addr.Offset + addr.BitOffset - 1);
                }
                else
                {
                    throw new Exception("Tag类型不支持");
                }
                return(result);
            }

            return(-1);
        }
        // 根据地址增加需要读取的DB块
        public void AddAddress(Tag tag)
        {
            try
            {
                if (tag.AccessType == TagAccessType.Read || tag.AccessType == TagAccessType.ReadWrite)
                {
                    var address = tag.Address.ToUpper();
                    if (address.Substring(0, 2) == "DB")
                    {
                        var addr = SiemensPLCAddress.ConvertAddressAsDB(address);
                        //检查定义的Tag类型与地址自动解析的类型是否一致
                        if (addr.Type.ToLower() != tag.TagType.ToLower())
                        {
                            throw new Exception("Tag类型与地址自动解析的类型不一致");
                        }
                        DbAddress.Add(address, addr);

                        if (addr != null)
                        {
                            var dbId     = addr.DBBlockID;
                            var dbOffset = addr.Offset;

                            if (_dbStartAddress.ContainsKey(dbId))
                            {
                                //如果存在该DB ID
                                if (_dbStartAddress[dbId] > dbOffset)
                                {
                                    //如果是最小地址
                                    _dbStartAddress[dbId] = dbOffset;
                                }
                            }
                            else
                            {
                                _dbStartAddress.Add(dbId, dbOffset);
                            }

                            var maxAddr = GetMaxAddress(addr);
                            if (_dbAreaMaxAddress.ContainsKey(dbId))
                            {
                                //如果存在该DB ID
                                if (_dbAreaMaxAddress[dbId] < maxAddr)
                                {
                                    //如果是最大地址
                                    _dbAreaMaxAddress[dbId] = maxAddr;
                                }
                            }
                            else
                            {
                                _dbAreaMaxAddress.Add(dbId, maxAddr);
                            }

                            if (_dbAreaLength.ContainsKey(dbId))
                            {
                                //如果存在该DB ID
                                _dbAreaLength[dbId] = (short)(_dbAreaMaxAddress[dbId] - _dbStartAddress[dbId] + 1);
                            }
                            else
                            {
                                _dbAreaLength.Add(dbId,
                                                  (short)(_dbAreaMaxAddress[dbId] - _dbStartAddress[dbId] + 1));
                            }
                        }
                    }
                    else if (address.Substring(0, 1) == "M")
                    {
                        var addr = SiemensPLCAddress.ConvertAddressAsM(address);
                        //检查定义的Tag类型与地址自动解析的类型是否一致
                        if (addr.Type.ToLower() != tag.TagType.ToLower())
                        {
                            throw new Exception("Tag类型与地址自动解析的类型不一致");
                        }
                        _mAddress.Add(address, addr);
                        if (addr != null)
                        {
                            var mOffset = addr.Offset;

                            if (_mAreaMinAddress > mOffset)
                            {
                                //如果是最小地址
                                _mAreaMinAddress = mOffset;
                            }

                            var maxAddr = GetMaxAddress(addr);

                            if (_mAreaMaxAddress < maxAddr)
                            {
                                //如果是最大地址
                                _mAreaMaxAddress = maxAddr;
                            }

                            _mAreaLength = (short)(_mAreaMaxAddress - _mAreaMinAddress + 1);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //LOG.Error(string.Format("S7驱动添加地址{0}出错{1}", tag.Address, ex));
                Log.Error($"S7 driver added address:{tag.Address} error,Message: {ex}");
            }
        }