SumSymbolWrite Class

Class for ADS Sum symbolic Write Access.

Inheritance Hierarchy

System.Object
  SumCommandWrapper.SumWrite.
    SumSymbolCommand.SumWrite.
      TwinCAT.Ads.SumCommand.SumSymbolWrite
Namespace:  TwinCAT.Ads.SumCommand
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 4.3.0.0

Syntax

C#

public class SumSymbolWrite : SumSymbolCommand<SumWrite>

VB

Public Class SumSymbolWrite
    Inherits SumSymbolCommand(Of SumWrite)

The SumSymbolWrite type exposes the following members.

Constructors

 

Name

Description

SumSymbolWrite

Initializes a new instance of the SumSymbolWrite 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.)

ToString

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

TryWrite

Tries the write.

Write

Writes the specified values.

Remarks

The SumSymbolWrite implements symbolic write 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.

Examples

Usage of SumSymbolRead/SumSymbolWrite with AdsSession

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

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

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

    // Load symbolic information
    ReadOnlySymbolCollection symbols = session.SymbolServer.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);
    object[] values = readCommand.Read();

    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"};

    writeCommand.Write(writeValues);
    }

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

Examples

Usage of SumSymbolRead/SumSymbolWrite with TcAdsClient

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

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

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

    // Load symbolic information
    ISymbolLoader loader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.Default);
    ReadOnlySymbolCollection allSymbols = loader.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);
    object[] values = readCommand.Read();

    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"};

    writeCommand.Write(writeValues);
    }

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

Reference

TwinCAT.Ads.SumCommand Namespace

TwinCAT.Ads.SumCommand.ISumCommand

TwinCAT.Ads.SumCommand.SumSymbolWrite