SymbolIterator Class

Iterator class for enumerations of Symbols.

Inheritance Hierarchy

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

Syntax

C#

public class SymbolIterator : SymbolIterator<ISymbol>

The SymbolIterator type exposes the following members.

Constructors

 

Name

Description

SymbolIterator Class 1:

SymbolIterator(IInstanceCollection.ISymbol.)

Initializes a new instance of the SymbolIterator class.

SymbolIterator Class 2:

SymbolIterator(IEnumerable.ISymbol., Boolean)

Initializes a new instance of the SymbolIterator class.

SymbolIterator Class 3:

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

Initializes a new instance of the SymbolIterator class.

SymbolIterator Class 4:

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

Initializes a new instance of the SymbolIterator class.

SymbolIterator Class 5:

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

Initializes a new instance of the SymbolIterator class.

Properties

 

Name

Description

SymbolIterator Class 6:

Mask

Gets or sets the SymbolIterationMask (Inherited from SymbolIterator.T..)

SymbolIterator Class 7:

SymbolRecursionDetection

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

Methods

 

Name

Description

SymbolIterator Class 8:

Equals

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

SymbolIterator 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 Class 10:

GetEnumerator

Gets the enumerator that enumerates through a collection (Inherited from SymbolIterator.T..)

SymbolIterator Class 11:

GetHashCode

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

SymbolIterator Class 12:

GetType

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

SymbolIterator Class 13:

MemberwiseClone

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

SymbolIterator 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.Ads.TypeSystem Namespace