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
Constructors
|
Name |
Description |
---|---|---|
|
Initializes a new instance of the SymbolIterator.T. class. | |
|
Initializes a new instance of the SymbolIterator.T. class. | |
|
Initializes a new instance of the SymbolIterator.T. class. | |
|
SymbolIterator.T.(IEnumerable.T., Boolean, Func.T, Boolean.) |
Initializes a new instance of the SymbolIterator.T. class. |
|
SymbolIterator.T.(IEnumerable.T., Boolean, SymbolIterationMask, Func.T, Boolean., Func.T, Boolean.) |
Initializes a new instance of the SymbolIterator.T. 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 |
---|---|---|
|
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.) |
|
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).
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);
}
}
}