SymbolIteratorT Class

Iterator class for enumerations of Symbols.

Inheritance Hierarchy

SystemObject
  TwinCAT.TypeSystemSymbolIteratorT
    TwinCAT.TypeSystemSymbolIterator

Namespace: TwinCAT.TypeSystem
Assembly: TwinCAT.Ads.Abstractions (in TwinCAT.Ads.Abstractions.dll) Version: 7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470

Syntax

C#

public class SymbolIterator<T> : IEnumerable<T>, 
    IEnumerable
where T : class, ISymbol

Type Parameters

T

Concrete ISymbol type.

The SymbolIteratorT type exposes the following members.

Constructors

 

Name

Description

SymbolIteratorT(IInstanceCollectionT)

Initializes a new instance of the SymbolIteratorT class.

SymbolIteratorT(IEnumerableT, Boolean)

Initializes a new instance of the SymbolIteratorT class.

SymbolIteratorT(IInstanceCollectionT, FuncT, Boolean)

Initializes a new instance of the SymbolIteratorT class.

SymbolIteratorT(IEnumerableT, Boolean, FuncT, Boolean)

Initializes a new instance of the SymbolIteratorT class.

SymbolIteratorT(IEnumerableT, Boolean, SymbolIterationMask, FuncT, Boolean, FuncT, Boolean)

Initializes a new instance of the SymbolIteratorT class.

Properties

 

Name

Description

Mask

Gets or sets the SymbolIterationMask

SymbolRecursionDetection

Gets or sets a value indicating whether the iterator checks for Symbol recursions (true by default).

Methods

 

Name

Description

Equals

Determines whether the specified object is equal to the current object.
(Inherited from Object)

Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)

GetEnumerator

Gets the enumerator that enumerates through a collection

GetHashCode

Serves as the default hash function.
(Inherited from Object)

GetType

Gets the Type of the current instance.
(Inherited from Object)

MemberwiseClone

Creates a shallow copy of the current Object.
(Inherited from Object)

ToString

Returns a string that represents the current object.
(Inherited from Object)

Remarks

This iterator class can be used to iterate over collections of symbol trees (root symbols + sub symbols). By constructor the user can choose if the iterator works recursively within the symbol tree and optionally a filter function to select only specific symbols (predicate).

Example

The following example shows how to determine, browse and filter symbols.

Browsing and filtering Symbols

using (AdsClient client = new AdsClient())
{
    CancellationToken cancel = CancellationToken.None;

    uint valueToRead = 0;
    uint valueToWrite = 42;

    client.Connect(AmsNetId.Local, 851);

    // Load all Symbols + DataTypes
    ISymbolLoader loader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.Default);

    ResultSymbols resultSymbols  = await loader.GetSymbolsAsync(cancel);

    if (resultSymbols.Succeeded)
    {
    Symbol symbol = (Symbol)resultSymbols.Symbols["MAIN.nCounter"];

    // Works for ALL Primitive 'ANY TYPES' Symbols
    ResultWriteAccess resultWrite = await symbol.WriteValueAsync(valueToWrite, cancel);
    ResultReadValueAccess resultRead = await symbol.ReadValueAsync(cancel);

    if (resultRead.Succeeded)
        valueToRead = (uint)resultRead.Value;

    // Simple filtering of Symbols
    Regex filterExpression = new Regex(pattern: @"^MAIN.*"); // Everything that starts with "MAIN"

    // FilterFunction that filters for the InstancePath
    Func<ISymbol, bool> filter = s => filterExpression.IsMatch(s.InstancePath);
    SymbolIterator iterator = new SymbolIterator(symbols: resultSymbols.Symbols, recurse: true, selector: filter);

    foreach (ISymbol filteredSymbol in iterator)
    {
        Console.WriteLine(filteredSymbol.InstancePath);
    }
    }
}

Reference

TwinCAT.TypeSystem Namespace IEnumerableT

Beckhoff Automation GmbH & Co. KG 2001-2026