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, ISymbolConstructors
|
|
Name |
Description |
|---|---|---|
|
|
Initializes a new instance of the SymbolIteratorT class. | |
|
|
Initializes a new instance of the SymbolIteratorT class. | |
|
|
Initializes a new instance of the SymbolIteratorT class. | |
|
|
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 |
|---|---|---|
|
|
Gets or sets the SymbolIterationMask | |
|
|
Gets or sets a value indicating whether the iterator checks for Symbol recursions (true by default). |
Methods
|
|
Name |
Description |
|---|---|---|
|
|
Determines whether the specified object is equal to the current
object. | |
|
|
Allows an object to try to free resources and perform other
cleanup operations before it is reclaimed by garbage
collection. | |
|
|
Gets the enumerator that enumerates through a collection | |
|
|
Serves as the default hash function. | |
|
|
Gets the Type of the current
instance. | |
|
|
Creates a shallow copy of the current Object. | |
|
|
Returns a string that represents the current 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);
}
}
}