SymbolIterator.T. Class

Iterator class for enumerations of Symbols.

Inheritance Hierarchy

System.Object
  TwinCAT.TypeSystem.Generic.SymbolIterator.T.
    TwinCAT.Ads.TypeSystem.SymbolIterator
Namespace:  TwinCAT.TypeSystem.Generic
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 6.0.328+39e3229

Syntax

C#

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

Type Parameters

T

Concrete ISymbol type.

The SymbolIterator.T. type exposes the following members.

Constructors

 

Name

Description

SymbolIterator.T. Class 1:

SymbolIterator.T.(IInstanceCollection.T.)

Initializes a new instance of the SymbolIterator.T. class.

SymbolIterator.T. Class 2:

SymbolIterator.T.(IEnumerable.T., Boolean)

Initializes a new instance of the SymbolIterator.T. class.

SymbolIterator.T. Class 3:

SymbolIterator.T.(IInstanceCollection.T., Func.T, Boolean.)

Initializes a new instance of the SymbolIterator.T. class.

SymbolIterator.T. Class 4:

SymbolIterator.T.(IEnumerable.T., Boolean, Func.T, Boolean.)

Initializes a new instance of the SymbolIterator.T. class.

SymbolIterator.T. Class 5:

SymbolIterator.T.(IEnumerable.T., Boolean, SymbolIterationMask, Func.T, Boolean., Func.T, Boolean.)

Initializes a new instance of the SymbolIterator.T. class.

Properties

 

Name

Description

SymbolIterator.T. Class 6:

Mask

Gets or sets the SymbolIterationMask

SymbolIterator.T. Class 7:

SymbolRecursionDetection

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

Methods

 

Name

Description

SymbolIterator.T. Class 8:

Equals

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

SymbolIterator.T. Class 9:

Finalize

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

SymbolIterator.T. Class 10:

GetEnumerator

Gets the enumerator that enumerates through a collection

SymbolIterator.T. Class 11:

GetHashCode

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

SymbolIterator.T. Class 12:

GetType

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

SymbolIterator.T. Class 13:

MemberwiseClone

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

SymbolIterator.T. Class 14:

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).

Examples

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.Generic Namespace

System.Collections.Generic.IEnumerable.T.