private void ImportChildTagsRecursively(Tag parentTag, TcAdsSymbolInfo symbol, int adsPort)
        {
            while (symbol != null)
            {
                var tag = new Tag();

                try
                {
                    tag        = BeckhoffHelper.ConvertSymbolToTag(symbol, adsPort);
                    tag.Parent = parentTag;
                    parentTag.Childs.Add(tag);
                }
                catch (TagException e)
                {
                    Console.WriteLine("Cannot import tags online (will skip it): " + e);
                }

                if (symbol.SubSymbolCount > 0 && !symbol.IsPointer && !symbol.IsReference)
                {
                    ImportChildTagsRecursively(tag, symbol.FirstSubSymbol, adsPort);
                }

                symbol = symbol.NextSymbol;
            }
        }
        private Tag ImportTagWithChilds(TcAdsSymbolInfo symbol, int adsPort, HashSet <string> tagHashSet)
        {
            Tag tag = null;

            if (symbol == null)
            {
                return(tag);
            }

            try
            {
                tag = BeckhoffHelper.ConvertSymbolToTag(symbol, adsPort);
            }
            catch (TagException e)
            {
                _logger.Warn("Cannot import tags online (will skip it): " + e);
                return(tag);
            }

            // prevent circular reads (endless loop) by checking if the hashset already contains the tag
            if ((symbol.IsReference || symbol.IsPointer) && (!tag.MetaData.ReadPointer || tagHashSet.Contains(tag.GetPointerlessFullName())))
            {
                return(tag);
            }

            if (tag.MetaData.ReadPointer)
            {
                tagHashSet.Add(tag.GetPointerlessFullName());
            }

            tag.FullName();

            TcAdsSymbolInfo subSymbol = symbol.FirstSubSymbol;

            while (subSymbol != null)
            {
                Tag subTag = ImportTagWithChilds(subSymbol, adsPort, tagHashSet);
                if (subTag != null)
                {
                    tag.Childs.Add(subTag);
                    subTag.Parent = tag;
                }
                subSymbol = subSymbol.NextSymbol;
            }
            return(tag);
        }
        public Tag ImportTag(string name, int adsPort)
        {
            _logger.Debug(string.Format("Importing tag '{0}' on port '{1}", name, adsPort));
            if (_twinCatClient == null)
            {
                return(null);
            }

            var symbol = _twinCatClient.ReadSymbolInfo(name);

            if (symbol == null)
            {
                return(null);
            }

            Tag result = BeckhoffHelper.ConvertSymbolToTag(symbol, adsPort);

            return(result);
        }