SumSymbolRead Class

Symbolic ADS Sum read access (automatic marshalling)

Inheritance Hierarchy

System.Object
  SumCommandWrapper.SumReadWrite.
    SumSymbolCommand.SumReadWrite.
      SumSymbolReadBase
        TwinCAT.Ads.SumCommand.SumSymbolRead
Namespace:  TwinCAT.Ads.SumCommand
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 6.0.328+39e3229

Syntax

C#

public class SumSymbolRead : SumSymbolReadBase, 
    ISumRead, ISumCommand, ISumRead2<ISymbol>

The SumSymbolRead type exposes the following members.

Methods

 

Name

Description

SumSymbolRead Class 1:

createResults

Creates the SumCommand results (abstract) (Overrides SumSymbolReadBase.createResults(IList.SumDataEntity., IList.ReadOnlyMemory.Byte.., .AdsErrorCode.).)

SumSymbolRead Class 2:

Equals

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

SumSymbolRead Class 3:

Finalize

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

SumSymbolRead Class 4:

GetHashCode

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

SumSymbolRead Class 5:

GetType

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

SumSymbolRead Class 6:

MemberwiseClone

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

SumSymbolRead Class 7:

Read

Reads the combined (Sum) Symbols and returns them as value array.

SumSymbolRead Class 8:

Read2

Reads the Values.

SumSymbolRead Class 9:

Read2Async

Read2 as an asynchronous operation.

SumSymbolRead Class 10:

ReadAsResult

Reads the combined (Sum) Symbols and returns them as Result object.

SumSymbolRead Class 11:

ReadAsync

Reads Symbol values as an asynchronous operation.

SumSymbolRead Class 12:

ToString

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

SumSymbolRead Class 13:

TryRead

Reads the specified symbols.

Extension Methods

 

Name

Description

AllFailed

Gets a value indicating, that all SubCommands failed. (Defined by ISumCommandExtension.)

AllSucceeded

Gets a value indicating, that all SubCommands succeeded. (Defined by ISumCommandExtension.)

FirstSubError

Gets the first SubError that is not NoError (Defined by ISumCommandExtension.)

OneFailed

Gets a value indicating, whether the overall Sumcommand failed (checking all subcommand results). (Defined by ISumCommandExtension.)

OneSucceeded

Gets a value indicating, whether the overall SumCommand succeeded (including all subcommands) (Defined by ISumCommandExtension.)

OverallError

Gets the Overall (combined error) from SumCommand AND SubCommands. (Defined by ISumCommandExtension.)

PollValues(IObservable.Unit.)

Overloaded.

Polls a series of symbols via a ISumRead command. The SumCommand will read all contained values with every trigger. (Defined by ValueSymbolExtensions.)

PollValues(TimeSpan)

Overloaded.

Polls a series of symbols via a ISumRead2.S. command. The SumCommand will read all contained values with every trigger in one roundtrip. (Defined by ValueSymbolExtensions.)

PollValues2.ISymbol.(IObservable.Unit.)

Overloaded.

Polls a series of symbols via a ISumRead2.S. command. The SumCommand will read all contained values with every trigger in one roundtrip. (Defined by ValueSymbolExtensions.)

PollValues2.ISymbol.(TimeSpan)

Overloaded.

Polls a series of symbols via a ISumRead2.S. command. The SumCommand will read all contained values with every trigger. (Defined by ValueSymbolExtensions.)

Remarks

The SumSymbolRead implements symbolic read access with automatic (dynamic) value marshalling. The advantage of the symbolic access is (in contrast to the handle access classes SumHandleRead,SumHandleWrite) that all type information is available when using this ADS Sum Command. The disadvantage is, that the Symbolic information must be loaded beforehand, see examples. The SumSymbolWrite defaults to an InstancPath/SymbolName read (ValueByName).

Examples

Usage of SumSymbolRead/SumSymbolWrite with AdsSession

/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
static async void Main(string[] args)
{
    Console.WriteLine("");
    Console.WriteLine("Press [Enter] for start:");
    Console.ReadLine();

    // Parse the command-line arguments
    AmsAddress address = ArgParser.Parse(args);

    CancellationTokenSource cancelSource = new CancellationTokenSource();
    CancellationToken cancel = cancelSource.Token;

    using (AdsSession session = new AdsSession(address))
    {
    // Connect to the device target.
    AdsConnection connection = (AdsConnection)session.Connect();

    // Load symbolic information
    var resultSymbols = await session.SymbolServer.GetSymbolsAsync(cancel);
    resultSymbols.ThrowOnError();

    ISymbolCollection<ISymbol> symbols = resultSymbols.Symbols;

    ISymbol bVar1 = symbols["GVL.bVar1"];
    ISymbol bVar2 = symbols["GVL.bVar2"];
    ISymbol projectName = symbols["TwinCAT_SystemInfoVarList._AppInfo.ProjectName"];

    SymbolCollection coll = new SymbolCollection() {bVar1, bVar2, projectName};

    // Sum Command Read
    SumSymbolRead readCommand = new SumSymbolRead(connection,coll);
    var resultReadValues = await readCommand.ReadAsync(cancel);

    if (resultReadValues.Succeeded)
    {
        object[] values = resultReadValues.Values;

        for (int i = 0; i < coll.Count; i++)
        {
        Console.WriteLine("Symbol: {0} (Value: {1}, Type: {2})", coll[i].InstancePath, values[i].ToString(), values[i].GetType().Name);
        }
    }
    // Sum Command Write

    SumSymbolWrite writeCommand = new SumSymbolWrite(connection,coll);
    object[] writeValues = new object[] {true, (short) 42, "MyNewProjectName"};

    var resultWrite = await writeCommand.WriteAsync(writeValues,cancel);
    }

    Console.WriteLine("");
    Console.WriteLine("Press [Enter] for leave:");
    Console.ReadLine();
}

Examples

Usage of SumSymbolRead/SumSymbolWrite with AdsClient

/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
static async void Main(string[] args)
{
    Console.WriteLine("");
    Console.WriteLine("Press [Enter] for start:");
    Console.ReadLine();

    CancellationTokenSource cancelSource = new CancellationTokenSource();
    CancellationToken cancel = cancelSource.Token;

    // Parse the command-line arguments
    AmsAddress address = ArgParser.Parse(args);

    using (AdsClient client = new AdsClient())
    {
    // Connect the AdsClient to the device target.
    client.Connect(address);

    // Load symbolic information
    ISymbolLoader loader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.Default);
    var resultReadSymbols = await loader.GetSymbolsAsync(cancel);

    resultReadSymbols.ThrowOnError();

    ISymbolCollection<ISymbol> allSymbols = resultReadSymbols.Symbols;

    ISymbol bVar1 = allSymbols["GVL.bVar1"];
    ISymbol bVar2 = allSymbols["GVL.iCount"];
    ISymbol projectName = allSymbols["TwinCAT_SystemInfoVarList._AppInfo.ProjectName"];

    SymbolCollection symbols = new SymbolCollection() {bVar1, bVar2, projectName};

    // Sum Command Read
    SumSymbolRead readCommand = new SumSymbolRead(client,symbols);
    var resultSumRead = await readCommand.ReadAsync(cancel);

    if (resultSumRead.Succeeded)
    {
        object[] values = resultSumRead.Values;

        for (int i = 0; i < symbols.Count; i++)
        {
        Console.WriteLine("Symbol: {0} (Value: {1}, Type: {2})", symbols[i].InstancePath, values[i].ToString(), values[i].GetType().Name);
        }

        // Sum Command Write
        SumSymbolWrite writeCommand = new SumSymbolWrite(client, symbols);
        object[] writeValues = new object[] { true, (short)42, "MyNewProjectName" };

        var resultSumWrite = await writeCommand.WriteAsync(writeValues, cancel);
    }
    }

    Console.WriteLine("");
    Console.WriteLine("Press [Enter] for leave:");
    Console.ReadLine();
}

Reference

TwinCAT.Ads.SumCommand Namespace

TwinCAT.Ads.SumCommand.ISumCommand

TwinCAT.Ads.SumCommand.SumAnyTypeRead

TwinCAT.Ads.SumCommand.SumSymbolWrite