TcAdsClient Class

ADS Client / ADS Communication object.

Inheritance Hierarchy

System.Object
  TwinCAT.Ads.TcAdsClient
Namespace:  TwinCAT.Ads
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 4.3.0.0

Syntax

C#

public class TcAdsClient : ITcAdsRpcInvoke, 
    IDisposable, IAdsConnection, IConnection, IConnectionStateProvider, IAdsNotifications, 
    IAdsAnyAccess, IAdsHandleAccess

VB

Public Class TcAdsClient
    Implements ITcAdsRpcInvoke, IDisposable, IAdsConnection, IConnection, 
    IConnectionStateProvider, IAdsNotifications, IAdsAnyAccess, IAdsHandleAccess

The TcAdsClient type exposes the following members.

Constructors

 

Name

Description

TcAdsClient Class 1:

TcAdsClient.

Initializes a new instance of the class TcAdsClient.

TcAdsClient Class 2:

TcAdsClient(AdsClientSettings)

Initializes a new instance of the TcAdsClient class.

Properties

 

Name

Description

TcAdsClient Class 3:

Address

Gets the AmsAddress of the ADS server (Target side)

TcAdsClient Class 4:

ClientAddress

Get the AmsAddress of the ADS client (Source side)

TcAdsClient Class 5:

Disposed

Determines, whether the TcAdsClient is disposed

TcAdsClient Class 6:

Id

Gets the TcAdsClient Identifier.

TcAdsClient Class 7:

IsConnected

Gets a value indicating whether the local ADS port was opened successfully. It does not indicate if the target port is available. Use the method ReadState to determine if the target port is available.

TcAdsClient Class 8:

IsLocal

Gets a value indicating whether the ADS client is connected to a ADS Server on the local computer.

TcAdsClient Class 9:

Protocol

Gets actual ADS Transport protocol

TcAdsClient Class 10:

RouterState

Gets the current state of the local AMS Router.

TcAdsClient Class 11:

Session

Gets the session that initiated this IConnection

TcAdsClient Class 12:

Synchronize

Gets or sets a value indicating whether the TcAdsClient object synchronizes the incoming notifications (obsolete)

TcAdsClient Class 13:

Timeout

Sets the timeout for the ads communication. Unit is in ms.

Methods

 

Name

Description

TcAdsClient Class 14:

AddDeviceNotification(String, AdsStream, AdsTransMode, Int32, Int32, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 15:

AddDeviceNotification(String, AdsStream, AdsTransMode, TimeSpan, TimeSpan, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 16:

TcAdsClient Class 17:

AddDeviceNotification(UInt32, UInt32, AdsStream, AdsTransMode, Int32, Int32, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 18:

TcAdsClient Class 19:

AddDeviceNotification(UInt32, UInt32, AdsStream, AdsTransMode, TimeSpan, TimeSpan, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 20:

AddDeviceNotification(String, AdsStream, Int32, Int32, AdsTransMode, Int32, Int32, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 21:

AddDeviceNotification(String, AdsStream, Int32, Int32, AdsTransMode, TimeSpan, TimeSpan, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 22:

TcAdsClient Class 23:

AddDeviceNotification(UInt32, UInt32, AdsStream, Int32, Int32, AdsTransMode, Int32, Int32, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 24:

TcAdsClient Class 25:

AddDeviceNotification(UInt32, UInt32, AdsStream, Int32, Int32, AdsTransMode, TimeSpan, TimeSpan, Object)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 26:

TcAdsClient Class 27:

AddDeviceNotificationEx(String, AdsTransMode, Int32, Int32, Object, Type)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 28:

TcAdsClient Class 29:

AddDeviceNotificationEx(String, AdsTransMode, TimeSpan, TimeSpan, Object, Type)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 30:

TcAdsClient Class 31:

AddDeviceNotificationEx(String, AdsTransMode, Int32, Int32, Object, Type, .Int32.)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 32:

TcAdsClient Class 33:

AddDeviceNotificationEx(String, AdsTransMode, TimeSpan, TimeSpan, Object, Type, .Int32.)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 34:

TcAdsClient Class 35:

AddDeviceNotificationEx(UInt32, UInt32, AdsTransMode, Int32, Int32, Object, Type)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 36:

TcAdsClient Class 37:

AddDeviceNotificationEx(UInt32, UInt32, AdsTransMode, TimeSpan, TimeSpan, Object, Type)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 38:

TcAdsClient Class 39:

AddDeviceNotificationEx(UInt32, UInt32, AdsTransMode, Int32, Int32, Object, Type, .Int32.)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event. If type is a string type, the first element of the parameter args specifies the number of characters of the string. If type is an array type, the number of elements for each dimension has to be specified in the parameter args. At the moment only 1 dimensional Arrays are supported.

TcAdsClient Class 40:

AddDeviceNotificationEx(UInt32, UInt32, AdsTransMode, TimeSpan, TimeSpan, Object, Type, .Int32.)

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event. If type is a string type, the first element of the parameter args specifies the number of characters of the string. If type is an array type, the number of elements for each dimension has to be specified in the parameter args. At the moment only 1 dimensional Arrays are supported.

TcAdsClient Class 41:

Close

Closes this IConnection

TcAdsClient Class 42:

Connect(Int32)

Establishes a connection to a ADS device using the local netID.

TcAdsClient Class 43:

Connect(AmsAddress)

Establishes a connection to a ADS device.

TcAdsClient Class 44:

Connect(.Byte., Int32)

Establishes a connection to a ADS device.

TcAdsClient Class 45:

Connect(String, Int32)

Establishes a connection to a ADS device.

TcAdsClient Class 46:

Connect(AmsNetId, Int32)

Establishes a connection to a ADS device.

TcAdsClient Class 47:

Connect(AmsNetId, AmsPort)

Establishes a connection to a ADS device.

TcAdsClient Class 48:

TcAdsClient Class 49:

CreateSymbolInfoLoader

Obsolete.

Creates a new instance of the TcAdsSymbolInfoLoader class (Symbol Browser V1, obsolete).

TcAdsClient Class 50:

CreateVariableHandle

Generates a unique handle for an ADS variable.

TcAdsClient Class 51:

TcAdsClient Class 52:

DeleteDeviceNotification

Deletes an existing notification.

TcAdsClient Class 53:

DeleteVariableHandle

Releases the handle of a ADS variable again.

TcAdsClient Class 54:

Disconnect

Disconnects the TcAdsClient

TcAdsClient Class 55:

Dispose.

Releases the resources used by TcAdsClient.

TcAdsClient Class 56:

Dispose(Boolean)

Disposes the TcAdsClient.

TcAdsClient Class 57:

Equals

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

TcAdsClient Class 58:

Finalize

Finalizes an instance of the TcAdsClient class. (Overrides Object.Finalize..)

TcAdsClient Class 59:

GetHashCode

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

TcAdsClient Class 60:

GetType

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

TcAdsClient Class 61:

TcAdsClient Class 62:

InvokeRpcMethod(String, Int32, .Object.)

Invokes the specified RPC Method

TcAdsClient Class 63:

TcAdsClient Class 64:

InvokeRpcMethod(String, String, .Object.)

Invokes the RPC method.

TcAdsClient Class 65:

TcAdsClient Class 66:

InvokeRpcMethod(ITcAdsSymbol, Int32, .Object.)

Invokes the specified RPC Method

TcAdsClient Class 67:

InvokeRpcMethod(ITcAdsSymbol, String, .Object.)

Invokes the RPC method.

TcAdsClient Class 68:

MemberwiseClone

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

TcAdsClient Class 69:

OnBeforeDisconnect

Called when before the TcAdsClient is disconnected.

TcAdsClient Class 70:

OnConnectionStateChanged

Called when the ConnectionState of the TcAdsClient has changed.

TcAdsClient Class 71:

Read(Int32, AdsStream)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 72:

Read(UInt32, UInt32, AdsStream)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 73:

Read(Int32, AdsStream, Int32, Int32)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 74:

Read(UInt32, UInt32, .Byte., Int32, Int32)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 75:

Read(UInt32, UInt32, AdsStream, Int32, Int32)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 76:

ReadAny(Int32, Type)

Reads data synchronously from an ADS device and writes it to an object.

TcAdsClient Class 77:

ReadAny(Int32, Type, .Int32.)

Reads data synchronously from an ADS device and writes it to an object.

TcAdsClient Class 78:

TcAdsClient Class 79:

ReadAny(UInt32, UInt32, Type)

Reads data synchronously from an ADS device and writes it to an object.

TcAdsClient Class 80:

ReadAny(UInt32, UInt32, Type, .Int32.)

Reads data synchronously from an ADS device and writes it to an object.

TcAdsClient Class 81:

TcAdsClient Class 82:

ReadAnyString(Int32, Int32, Encoding)

Reads the string.

TcAdsClient Class 83:

TcAdsClient Class 84:

ReadAnyString(UInt32, UInt32, Int32, Encoding)

Reads the string

TcAdsClient Class 85:

ReadDeviceInfo

Reads the identification and version number of an ADS server.

TcAdsClient Class 86:

ReadState

Reads the ADS status and the device status from an ADS server.

TcAdsClient Class 87:

ReadSymbol(ITcAdsSymbol)

Reads the value of a symbol and returns it as an object. Strings and all primitive datatypes(UInt32, Int32, Bool etc.) are supported. Arrays and structures cannot be read.

TcAdsClient Class 88:

ReadSymbol(String, Type, Boolean)

Reads the value of a symbol and returns the value as object. The parameter type must have the same layout as the ADS symbol.

TcAdsClient Class 89:

ReadSymbolInfo

Call this method to obtain information about the individual symbols (variables) in ADS devices.

TcAdsClient Class 90:

ReadWrite(UInt32, UInt32, AdsStream, AdsStream)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 91:

ReadWrite(Int32, AdsStream, Int32, Int32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 92:

ReadWrite(UInt32, UInt32, .Byte., Int32, Int32, .Byte., Int32, Int32)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 93:

ReadWrite(UInt32, UInt32, AdsStream, Int32, Int32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 94:

ToString

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

TcAdsClient Class 95:

TryAddDeviceNotification

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 96:

TryAddDeviceNotificationEx

Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.

TcAdsClient Class 97:

TryDeleteDeviceNotification

Deletes an existing notification.

TcAdsClient Class 98:

TryInvokeRpcMethod(String, Int32, .Object., Object.)

Invokes the specified RPC Method

TcAdsClient Class 99:

TryInvokeRpcMethod(String, String, .Object., Object.)

Tries to invoke the RPC method.

TcAdsClient Class 100:

TryInvokeRpcMethod(ITcAdsSymbol, Int32, .Object., Object.)

Invokes the specified RPC Method

TcAdsClient Class 101:

TryInvokeRpcMethod(ITcAdsSymbol, String, .Object., Object.)

Tries to invoke a RPC method.

TcAdsClient Class 102:

TryRead(UInt32, UInt32, AdsStream, Int32.)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 103:

TryRead(Int32, AdsStream, Int32, Int32, Int32.)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 104:

TryRead(UInt32, UInt32, .Byte., Int32, Int32, Int32.)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 105:

TryRead(UInt32, UInt32, AdsStream, Int32, Int32, Int32.)

Reads data synchronously from an ADS device and writes it to the given stream.

TcAdsClient Class 106:

TryReadState

Reads the ADS status and the device status from an ADS server. Unlike the ReadState method this method does not call an exception on failure. Instead an AdsErrorCode is returned. If the return value is equal to AdsErrorCode.NoError the call was successfull.

TcAdsClient Class 107:

TryReadWrite(Int32, .Byte., Int32, Int32, .Byte., Int32, Int32, Int32.)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 108:

TryReadWrite(Int32, AdsStream, Int32, Int32, AdsStream, Int32, Int32, Int32.)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 109:

TryReadWrite(UInt32, UInt32, .Byte., Int32, Int32, .Byte., Int32, Int32, Int32.)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 110:

TryReadWrite(UInt32, UInt32, AdsStream, Int32, Int32, AdsStream, Int32, Int32, Int32.)

Writes data synchronously to an ADS device and then Reads data from this device.

TcAdsClient Class 111:

TryWrite(Int32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 112:

TryWrite(UInt32, UInt32, .Byte., Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 113:

TryWrite(UInt32, UInt32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 114:

TryWriteControl(StateInfo)

Changes the ADS status and the device status of an ADS server.

TcAdsClient Class 115:

TryWriteControl(StateInfo, AdsStream, Int32, Int32)

Changes the ADS status and the device status of an ADS server.

TcAdsClient Class 116:

Write(Int32, Int32)

Trigger Client Method/Command.

TcAdsClient Class 117:

Write(Int32, AdsStream)

Writes data synchronously to an ADS device.

TcAdsClient Class 118:

Write(UInt32, UInt32)

Trigger Client Method/Command.

TcAdsClient Class 119:

Write(Int32, Int32, AdsStream)

Writes data synchronously to an ADS device.

TcAdsClient Class 120:

Write(UInt32, UInt32, AdsStream)

Writes data synchronously to an ADS device.

TcAdsClient Class 121:

Write(Int32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 122:

Write(Int32, Int32, .Byte., Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 123:

Write(Int32, Int32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 124:

Write(UInt32, UInt32, .Byte., Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 125:

Write(UInt32, UInt32, AdsStream, Int32, Int32)

Writes data synchronously to an ADS device.

TcAdsClient Class 126:

WriteAny(Int32, Object)

Writes an object synchronously to an ADS device.

TcAdsClient Class 127:

WriteAny(Int32, Object, .Int32.)

Writes an object synchronously to an ADS device.

TcAdsClient Class 128:

TcAdsClient Class 129:

WriteAny(UInt32, UInt32, Object)

Writes an object synchronously to an ADS device.

TcAdsClient Class 130:

WriteAny(UInt32, UInt32, Object, .Int32.)

Writes an object synchronously to an ADS device.

TcAdsClient Class 131:

TcAdsClient Class 132:

WriteAnyString(Int32, String, Int32, Encoding)

Writes the string (Potentially unsafe!)

TcAdsClient Class 133:

TcAdsClient Class 134:

WriteAnyString(UInt32, UInt32, String, Int32, Encoding)

Writes the string (Potentially unsafe!)

TcAdsClient Class 135:

WriteControl(StateInfo)

Changes the ADS status and the device status of an ADS server.

TcAdsClient Class 136:

WriteControl(StateInfo, AdsStream, Int32, Int32)

Changes the ADS status and the device status of an ADS server.

TcAdsClient Class 137:

WriteSymbol(ITcAdsSymbol, Object)

Writes a value to the symbol. Strings and all primitive data types(UInt32, Int32, Bool etc.) are supported. Array and structures are not supported. If a string is passed as parameter, the method attempts to parse the string according to the ADS data type of the symbol.

TcAdsClient Class 138:

WriteSymbol(String, Object, Boolean)

Writes the passed object value to the specified ADS symbol.The parameter type must have the same layout as the ADS symbol.

Events

 

Name

Description

TcAdsClient Class 139:

TcAdsClient Class 140:

AdsNotification

Occurs when the ADS device sends a ADS Notification to the client.

TcAdsClient Class 141:

AdsNotificationError

Occurs when a exception has occurred during notification management.

TcAdsClient Class 142:

TcAdsClient Class 143:

AdsNotificationEx

Occurs when the ADS devices sends an (extended) notification to the client.

TcAdsClient Class 144:

AdsStateChanged

Occurs when the ADS state changes.

TcAdsClient Class 145:

AdsSymbolVersionChanged

Occurs when the symbol version has been changed changes.

TcAdsClient Class 146:

AmsRouterNotification

Occurs when the state of the local Router has changed.

TcAdsClient Class 147:

ConnectionStateChanged

Occurs when the connection state has been changed.

Extension Methods

 

Name

Description

TcAdsClient Class 148:

TcAdsClient Class 149:

PollAdsState(IObservable.Unit.)

Overloaded.

Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.)

TcAdsClient Class 150:

TcAdsClient Class 151:

PollAdsState(TimeSpan)

Overloaded.

Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.)

TcAdsClient Class 152:

PollValues(String, Type, IObservable.Unit.)

Overloaded.

Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 153:

PollValues(String, Type, TimeSpan)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 154:

PollValues(String, Type, .Int32., TimeSpan)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 155:

PollValues(String, Type, IObservable.Unit., Func.Exception, Object.)

Overloaded.

Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 156:

PollValues(String, Type, TimeSpan, Func.Exception, Object.)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 157:

PollValues(String, Type, .Int32., IObservable.Unit., Func.Exception, Object.)

Overloaded.

Polls the symbol values on time points where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 158:

PollValues(String, Type, .Int32., TimeSpan, Func.Exception, Object.)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 159:

PollValues.T.(String, IObservable.Unit.)

Overloaded.

Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 160:

PollValues.T.(String, TimeSpan)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 161:

PollValues.T.(String, IObservable.Unit., Func.Exception, T.)

Overloaded.

Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 162:

PollValues.T.(String, TimeSpan, Func.Exception, T.)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 163:

PollValues.T.(String, .Int32., IObservable.Unit.)

Overloaded.

Polls the symbol values on time points where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 164:

TcAdsClient Class 165:

PollValues.T.(String, .Int32., TimeSpan)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 166:

PollValues.T.(String, .Int32., IObservable.Unit., Func.Exception, T.)

Overloaded.

Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.)

TcAdsClient Class 167:

TcAdsClient Class 168:

PollValues.T.(String, .Int32., TimeSpan, Func.Exception, T.)

Overloaded.

Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.)

TcAdsClient Class 169:

TcAdsClient Class 170:

WhenAdsStateChanges

Gets an observable sequence of AdsStates. (Defined by AdsClientExtensions.)

TcAdsClient Class 171:

WhenNotification(ISymbol)

Overloaded.

Gets an observable sequence of Notifications. (Defined by AdsClientExtensions.)

TcAdsClient Class 172:

TcAdsClient Class 173:

WhenNotification(ISymbolCollection)

Overloaded.

Gets an observable sequence of Notification objects. (Defined by AdsClientExtensions.)

TcAdsClient Class 174:

WhenNotification(ISymbol, NotificationSettings)

Overloaded.

Gets an observable sequence of Notifications. (Defined by AdsClientExtensions.)

TcAdsClient Class 175:

TcAdsClient Class 176:

WhenNotification(ISymbolCollection, NotificationSettings)

Overloaded.

Gets an observable sequence of Notification objects. (Defined by AdsClientExtensions.)

TcAdsClient Class 177:

TcAdsClient Class 178:

WhenValueChanged

Observable sequence of Values driven by ADS Notifications on the specified symbol. (Defined by ValueSymbolExtensions.)

TcAdsClient Class 179:

TcAdsClient Class 180:

WriteValues.T.(String, IObservable.T.)

Overloaded.

Writes the sequence of values to the symbol specified by the instance path. (Defined by AnyTypeExtensions.)

TcAdsClient Class 181:

TcAdsClient Class 182:

WriteValues.T.(String, IObservable.T., Action.Exception.)

Overloaded.

Writes the sequence of values to the symbol specified by the instance path. (Defined by AnyTypeExtensions.)

Remarks

IMPORTANT: The Default setting of the Synchronize property has changed to 'false' from Version 4.2.XX on. This has the effect that - by default - the notifications events and are not synchronized into the UI thread anymore. To re enable the obsolete behavior set to 'true'. AdsNotification AdsNotificationEx Synchronize Use an instance of this object to create a point-to-point send/receive connection to an ADS Server/Device object. The class TcAdsClient is a wrapper for the TcAdsdll.dll and enables synchronous/asynchronous access to data of an ADS Device.

Examples

The following sample shows how to instantiate and use the TcAdsClient class.

TcAdsClient Demo

using System;
using System.Threading;

using TwinCAT.Ads;
using TwinCAT.TypeSystem;
using TwinCAT.TypeSystem.Generic;

namespace Sample
{
    class AdsClient
    {
    /// <summary>
    /// Defines the entry point of the application.
    /// </summary>
    /// <param name="args">The arguments.</param>
    static void Main(string[] args)
    {
        AmsAddress address = ArgParser.Parse(args);

        using (TcAdsClient client = new TcAdsClient())
        {
        // Asynchronized access necessary for Console applications
        client.Synchronize = false;

        // Connect to Address
        client.Connect(address.NetId,address.Port); // Connect to Port (851, first PLC by default)

        // Read the identification and version number of the device
        DeviceInfo deviceInfo = client.ReadDeviceInfo();
        Version version = deviceInfo.Version.ConvertToStandard();
        Console.WriteLine(string.Format("DeviceName: {0}", deviceInfo.Name));
        Console.WriteLine(string.Format("DeviceVersion: {0}", version.ToString(3)));

        // Read the state of the device
        StateInfo stateInfo = client.ReadState();
        AdsState state = stateInfo.AdsState;
        short deviceState = stateInfo.DeviceState;
        Console.WriteLine(string.Format("DeviceState: {0}", deviceState));
        Console.WriteLine(string.Format("AdsState   : {0}", state));

        // Write ADS Commands (write state) to target
        // Set PLC to Run

        if (state == AdsState.Stop)
        {
            StateInfo setState = new StateInfo(AdsState.Run, 0);
            client.WriteControl(setState);
        }

        //create variable handle for Plc Project Name (automatic generated symbol in PLC)
        int handleProjectName = client.CreateVariableHandle("TwinCAT_SystemInfoVarList._AppInfo.ProjectName");
        int handleNotification = 0; // Notification Handle for Task1 CycleCount changes

        try
        {
            // Read value from target and Marshal data into string
            using (AdsBinaryReader reader = new AdsBinaryReader(new AdsStream(256)))
            {
            int read = client.Read(handleProjectName, (AdsStream)reader.BaseStream); 
            string projectName = reader.ReadPlcAnsiString(256);
            Console.WriteLine(string.Format("ProjectName  : {0}", projectName));
            }

            _notificationStream = new AdsStream(4); // Sizeof UDINT
            _notificationReader = new AdsBinaryReader(_notificationStream);

            client.AdsNotification += client_NotificationEvent; // Register for Notification event

            //Register Notification for Task1 CycleCount symbol (automatic generated symbol in PLC)
            handleNotification = client.AddDeviceNotification("TwinCAT_SystemInfoVarList._TaskInfo[1].CycleCount", _notificationStream, AdsTransMode.OnChange, 500, 0, null);

            // Sleep 10 Seconds to receive events
            System.Threading.Thread.Sleep(10000); 
        }
        finally
        {
            // Cleanup all handles
            // Dispose all Streams

            client.DeleteDeviceNotification(handleNotification);
            _notificationReader.Close();
            _notificationStream.Close();

            // Always delete all variable handles.
            client.DeleteVariableHandle(handleProjectName);
        }
        Console.WriteLine("");
        Console.WriteLine("Press [Enter] for leave:");
        Console.ReadLine();
        }
    }

Argument Parser

public static class ArgParser
{
    /// <summary>
    /// Parses the arguments.
    /// </summary>
    /// <param name="args">The arguments.</param>
    /// <returns>AmsAddress.</returns>
    public static AmsAddress Parse(string[] args)
    {
    AmsNetId netId = AmsNetId.Local;
    int port = 851;

    if (args != null)
    {
        if (args.Length > 0 && args[0] != null)
        netId = AmsNetId.Parse(args[0]);

        if (args.Length > 1 && args[1] != null)
        port = int.Parse(args[1]);
    }
    return new AmsAddress(netId, port);
    }
}

The following sample shows how to call (Remote Procedures / Methods) within the PLC directly from the TcAdsClient class.

RPC Call Example

namespace Sample
{
    using System;
    using System.Diagnostics;
    using TwinCAT.Ads;
    using TwinCAT.TypeSystem;

    class RpcCallV1Program
    {
    /// <summary>
    /// Defines the entry point of the application.
    /// </summary>
    /// <param name="args">The arguments.</param>
    static void Main(string[] args)
    {
        //Parse the AmsAddress from command-line arguments
        AmsAddress address = ArgParser.Parse(args);

        // Create the ADS Client
        using (TcAdsClient client = new TcAdsClient())
        {
        // Establish Connection
        client.Connect(address);

        // Call a Method that has the following signature (within MAIN Program)

        /*  {attribute 'TcRpcEnable'}
            METHOD PUBLIC M_Add : INT
            VAR_INPUT
            i1 : INT := 0;
            i2 : INT := 0;
            END_VAR 
        */

        short result = (short)client.InvokeRpcMethod("MAIN", "M_Add", new object[] {(short)1, (short)4});

        // Call a Method that has no parameter and returns VOID
        client.InvokeRpcMethod("MAIN", "M_Method1", new object[] {});
        }
    }
    }
}

Reference

TwinCAT.Ads Namespace