SumCreateHandles Class

SumCommandBase for getting variable handles by a set of InstancePaths

Inheritance Hierarchy

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

Syntax

C#

public class SumCreateHandles : SumCommandWrapper<SumReadWrite>

The SumCreateHandles type exposes the following members.

Constructors

 

Name

Description

SumCreateHandles Class 1:

SumCreateHandles(IAdsConnection, IList.String.)

Initializes a new instance of the SumCreateHandles class.

SumCreateHandles Class 2:

SumCreateHandles(IAdsConnection, .String.)

Initializes a new instance of the SumCreateHandles class.

SumCreateHandles Class 3:

SumCreateHandles(IAdsConnection, IList.String., SumCommandErrorStrategy)

Initializes a new instance of the SumCreateHandles class.

SumCreateHandles Class 4:

SumCreateHandles(IAdsConnection, .String., SumCommandErrorStrategy)

Initializes a new instance of the SumCreateHandles class.

Methods

 

Name

Description

SumCreateHandles Class 5:

CreateHandles

Creates the ADS handles.

SumCreateHandles Class 6:

CreateHandlesAsync

Create handles asynchronously.

SumCreateHandles Class 7:

Equals

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

SumCreateHandles Class 8:

Finalize

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

SumCreateHandles Class 9:

GetHashCode

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

SumCreateHandles Class 10:

GetType

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

SumCreateHandles Class 11:

MemberwiseClone

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

SumCreateHandles Class 12:

ToString

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

Examples

Usage of Sum commands with handles (CreateHandles, Read, Write, ReleaseHandles)

/// <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 (AdsClient client = new AdsClient())
    {
    // Connect the AdsClient to the device target.
    client.Connect(address);

    string[] instancePathList = {
        "GVL.bVar",
        "GVL.iCount",
        "TwinCAT_SystemInfoVarList._AppInfo.ProjectName"
    };
    SumCreateHandles createHandlesCommand = new SumCreateHandles(client,instancePathList);

    var resultCreateHandles = await createHandlesCommand.CreateHandlesAsync(cancel);

    if (resultCreateHandles.Succeeded)
    {
        uint[] handles = resultCreateHandles.Handles;
        Type[] valueTypes = new Type[]
        {
        typeof(bool),
        typeof(short),
        typeof(string)
        };
        SumHandleRead readCommand = new SumHandleRead(client, handles, valueTypes);
        var resultRead = await readCommand.ReadAsync(cancel);

        if (resultRead.Succeeded)
        {
        object[] readValues = resultRead.Values;

        for (int i = 0; i < instancePathList.Length; i++)
        {
            Console.WriteLine("Symbol: {0} (Value: {1}, Type: {2})", instancePathList[i], readValues[i].ToString(), valueTypes[i].Name);
        }

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

        await writeCommand.WriteAsync(writeValues,cancel);
        }

        SumReleaseHandles releaseCommand = new SumReleaseHandles(client, handles);
        await releaseCommand.ReleaseHandlesAsync(cancel);
    }
    }

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

Reference

TwinCAT.Ads.SumCommand Namespace

TwinCAT.Ads.SumCommand.ISumCommand

TwinCAT.Ads.SumCommand.SumReleaseHandles

TwinCAT.Ads.SumCommand.SumHandleRead

TwinCAT.Ads.SumCommand.SumHandleWrite