SumSymbolWrite Class
Class for ADS Sum symbolic Write Access.
Inheritance Hierarchy
SystemObject
SumCommandWrapperSumWrite
SumSymbolCommandSumWrite
TwinCAT.Ads.SumCommandSumSymbolWrite
Namespace: TwinCAT.Ads.SumCommand
Assembly: TwinCAT.Ads (in TwinCAT.Ads.dll)
Version: 7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470
Syntax
C#
public class SumSymbolWrite : SumSymbolCommand<SumWrite>The SumSymbolWrite type exposes the following members.
Methods
|
|
Name |
Description |
|---|---|---|
|
|
Determines whether the specified object is equal to the current
object. | |
|
|
Allows an object to try to free resources and perform other
cleanup operations before it is reclaimed by garbage
collection. | |
|
|
Serves as the default hash function. | |
|
|
Gets the Type of the current
instance. | |
|
|
Creates a shallow copy of the current Object. | |
|
|
Returns a string that represents the current object. | |
|
|
Writes the specified values. | |
|
|
Reads the symbol values asynchronously. | |
|
|
Writes raw values | |
|
|
Writes raw 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 SumHandleReadAnyType,SumHandleWriteAnyType) 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 IndexGroup/IndexOffset read (IndexGroupIndexOffset), because the the write access by InstancePath/SymbolName is not supported (for SumCommands). The disadvantage of this mode is, that dereferencing References/Pointers don't work and their values cannot be resolved. An option is to use the ValueByHandle, but that means to use more ADS roundtrips because the handles have to be requested first!
Example
Usage of SumRead/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, SumFallbackMode.All);
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, SumFallbackMode.All);
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();
}Reference
TwinCAT.Ads.SumCommand Namespace ISumCommandSumSymbolWriteSumWriteBySymbolPath
Beckhoff Automation GmbH & Co. KG 2001-2026