SumInstancePathAnyTypeRead Class

SumRead Command that uses the instancePath as symbol ID / Address and returns objects as Values (ANY Type marshaling)

Inheritance Hierarchy

System.Object
  SumCommandWrapper.SumReadWrite.
    SumInstancePathCommand.SumReadWrite, String.
      TwinCAT.Ads.SumCommand.SumInstancePathAnyTypeRead
Namespace:  TwinCAT.Ads.SumCommand
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 6.0.328+39e3229

Syntax

C#

public class SumInstancePathAnyTypeRead : SumInstancePathCommand<SumReadWrite, string>

The SumInstancePathAnyTypeRead type exposes the following members.

Constructors

 

Name

Description

SumInstancePathAnyTypeRead

Initializes a new instance of the SumRead class.

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

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

Read

Reads all the values in one ADS roundtrip and returns an result object containing all the SumCommand SubResults.

ReadAsync

Reads all the values as an asynchronous operation in one ADS roundtrip and returns an result object containing all the SumCommand SubResults.

ToString

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

Remarks

The return value results will be produced by the AnyTypeMarshaler and must be predefined following the ANY_TYPE concept. Therefore a list of specifiers must be specified for the SumInstancePathAnyTypeRead constructor. The internal single value reads are done by ValueByName / ValueByName.

Examples

Usage of the SumInstancePathAnyTypeRead SumCommand

AmsAddress address = new AmsAddress(AmsNetId.Local, AmsPort.PlcRuntime_851);

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

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 var1Sym = allSymbols["GVL.bVar1"];
    ISymbol var2Sym = allSymbols["GVL.iCount"];
    ISymbol projectNameSym = allSymbols["TwinCAT_SystemInfoVarList._AppInfo.ProjectName"];

    // Define the ANY_TYPE specifiers
    List<(ISymbol,Type,int[] args)> instancePathList = new List<(ISymbol, Type, int[] args)>(){
    (var1Sym, typeof(bool), null),
    (var2Sym, typeof(short), null),
    (projectNameSym,typeof(string),new int[] {63}) // See ANY_TYPE specifications
    };
    SumAnyTypeRead sumRead = new SumAnyTypeRead(client, instancePathList);

    var resultRead = await sumRead.Read2Async(cancel);

    if (resultRead.Succeeded)
    {
    foreach (var subResult in resultRead.ValueResults)
    {
        Console.WriteLine($"Symbol: {subResult.Source}, Value: {subResult.Value}, ErrorCode: {(AdsErrorCode) subResult.ErrorCode}");
    }

    var var1Value = (bool)resultRead.ValueResults[0].Value;
    var var2Value = (short)resultRead.ValueResults[1].Value;
    var projectName = (string)resultRead.ValueResults[2].Value;
    }

Reference

TwinCAT.Ads.SumCommand Namespace