AdsClient Class

ADS Client / ADS Communication object.

Inheritance Hierarchy

System.Object
  TwinCAT.Ads.AdsClient
Namespace:  TwinCAT.Ads
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 6.0.328+39e3229

Syntax

C#

public sealed class AdsClient : IAdsDisposableConnection, 
    IAdsConnectAddress, IAdsConnection, IConnection, IConnectionStateProvider, IAdsNotifications, 
    IAdsSymbolicAccess, IAdsAnyAccess, IAdsHandle, IAdsReadWrite2, IAdsReadWrite, 
    IAdsStateProvider, IAdsStateControl, IAdsSymbolChangedProvider, IAdsRpcInvoke, IRouterNotificationProvider, 
    IDisposable

The AdsClient type exposes the following members.

Constructors

 

Name

Description

AdsClient.

Initializes a new instance of the AdsClient class.

AdsClient(AdsClientSettings)

Initializes a new instance of the AdsClient class with the specified settings.

AdsClient(ILogger)

Initializes a new instance of the AdsClient class.

AdsClient(ISession, ILogger)

Initializes a new instance of the AdsClient class bound to a session.

AdsClient(ISession, AdsClientSettings, ILogger)

Initializes a new instance of the AdsClient class.

Properties

 

Name

Description

AdsClient Class 1:

Address

Gets the target AmsAddress of of the established ADS connection (Destination side).

AdsClient Class 2:

ClientAddress

Get the client AmsAddress (Source side).

AdsClient Class 3:

DefaultValueEncoding

Gets the default value encoding.

AdsClient Class 4:

Id

Gets the AdsClient Identifier.

AdsClient Class 5:

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.

AdsClient Class 6:

IsDisposed

Gets a value indicating whether this instance is disposed.

AdsClient Class 7:

IsLocal

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

AdsClient Class 8:

Logger

Gets the logger inteface.

AdsClient Class 9:

Session

Gets the session that initiated this IConnection

AdsClient Class 10:

SymbolEncoding

Gets the symbol encoding.

AdsClient Class 11:

Timeout

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

Methods

 

Name

Description

AdsClient Class 12:

AddDeviceNotification(String, Int32, NotificationSettings, Object)

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

AdsClient Class 13:

AddDeviceNotification(UInt32, UInt32, Int32, NotificationSettings, Object)

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

AdsClient Class 14:

AddDeviceNotificationAsync(String, Int32, NotificationSettings, Object, CancellationToken)

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

AdsClient Class 15:

AddDeviceNotificationAsync(UInt32, UInt32, Int32, NotificationSettings, Object, CancellationToken)

Adds a device notification as an asynchronous operation.

AdsClient Class 16:

AddDeviceNotificationEx(String, NotificationSettings, Object, Type)

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

AdsClient Class 17:

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

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

AdsClient Class 18:

AddDeviceNotificationEx(UInt32, UInt32, NotificationSettings, Object, Type)

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

AdsClient Class 19:

AddDeviceNotificationEx(UInt32, UInt32, NotificationSettings, 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. Only primitive ('AnyType') types are allowed for the parameter type.

AdsClient Class 20:

AddDeviceNotificationExAsync(String, NotificationSettings, Object, Type, .Int32., CancellationToken)

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

AdsClient Class 21:

AddDeviceNotificationExAsync(UInt32, UInt32, NotificationSettings, Object, Type, .Int32., CancellationToken)

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

AdsClient Class 22:

CleanupSymbolTable

Clears the internal symbol cache.

AdsClient Class 23:

Close

Closes this AdsClient

AdsClient Class 24:

Connect(AmsAddress)

Connects the target

AdsClient Class 25:

Connect(AmsPort)

Connects to the local target ADS Device.

AdsClient Class 26:

Connect(Int32)

Connects to the local target ADS Device.

AdsClient Class 27:

Connect(AmsNetId, Int32)

Connects to the target ADS Device.

AdsClient Class 28:

Connect(AmsNetId, AmsPort)

Connects to the target ADS Device.

AdsClient Class 29:

Connect(String, Int32)

Connects to the target ADS Device.

AdsClient Class 30:

ConnectAndWaitAsync

Connects to the target address and waits until the AdsClient is disconnected asynchronously.

AdsClient Class 31:

CreateVariableHandle

Determines the Symbol handle by its instance path synchronously.

AdsClient Class 32:

CreateVariableHandleAsync

Determines the Symbol handle by its instance path asynchronously.

AdsClient Class 33:

DeleteDeviceNotification

Deletes a registered notification.

AdsClient Class 34:

DeleteDeviceNotificationAsync

Deletes a registered notification asynchronously.

AdsClient Class 35:

DeleteVariableHandle

Releases the specified symbol/variable handle synchronously.

AdsClient Class 36:

DeleteVariableHandleAsync

Releases the specified symbol/variable handle asynchronously.

AdsClient Class 37:

Disconnect

Disconnects this AdsClient from the local ADS router.

AdsClient Class 38:

Dispose

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

AdsClient Class 39:

Equals

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

AdsClient Class 40:

Finalize

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

AdsClient Class 41:

GetHashCode

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

AdsClient Class 42:

GetType

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

AdsClient Class 43:

InvokeRpcMethodAsync(IRpcCallableInstance, IRpcMethod, .Object., CancellationToken)

invoke RPC method as an asynchronous operation.

AdsClient Class 44:

AdsClient Class 45:

InvokeRpcMethodAsync(String, String, .Object., CancellationToken)

Invokes the specified RPC Method asynchronously

AdsClient Class 46:

InvokeRpcMethodAsync(IRpcCallableInstance, IRpcMethod, .Object., .AnyTypeSpecifier., AnyTypeSpecifier, CancellationToken)

invoke RPC method as an asynchronous operation.

AdsClient Class 47:

AdsClient Class 48:

InvokeRpcMethodAsync(String, String, .Object., .AnyTypeSpecifier., AnyTypeSpecifier, CancellationToken)

Invokes the specified RPC Method asynchronously

AdsClient Class 49:

Read(UInt32, Memory.Byte.)

Reads data synchronously from an ADS device and writes to the specified readBuffer.

AdsClient Class 50:

Read(UInt32, UInt32, Memory.Byte.)

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

AdsClient Class 51:

ReadAny(UInt32, Type)

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

AdsClient Class 52:

ReadAny(UInt32, Type, .Int32.)

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

AdsClient Class 53:

ReadAny(UInt32, UInt32, Type)

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

AdsClient Class 54:

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

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

AdsClient Class 55:

ReadAny.T.(UInt32)

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

AdsClient Class 56:

ReadAny.T.(UInt32, .Int32.)

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

AdsClient Class 57:

ReadAny.T.(UInt32, UInt32)

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

AdsClient Class 58:

ReadAny.T.(UInt32, UInt32, .Int32.)

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

AdsClient Class 59:

ReadAnyAsync(UInt32, Type, CancellationToken)

Reads the value of an Anytype (Primitive type) asynchronously.

AdsClient Class 60:

ReadAnyAsync(UInt32, Type, .Int32., CancellationToken)

Reads the value of an Anytype (Primitive type) asynchronously.

AdsClient Class 61:

ReadAnyAsync(UInt32, UInt32, Type, CancellationToken)

Reads the value of an Anytype (Primitive type) asynchronously.

AdsClient Class 62:

ReadAnyAsync(UInt32, UInt32, Type, .Int32., CancellationToken)

Reads the value of an Anytype (Primitive type) asynchronously.

AdsClient Class 63:

ReadAnyAsync.T.(UInt32, CancellationToken)

Reads data synchronously from an ADS device.

AdsClient Class 64:

ReadAnyAsync.T.(UInt32, .Int32., CancellationToken)

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

AdsClient Class 65:

ReadAnyAsync.T.(UInt32, UInt32, CancellationToken)

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

AdsClient Class 66:

ReadAnyAsync.T.(UInt32, UInt32, .Int32., CancellationToken)

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

AdsClient Class 67:

ReadAnyString(UInt32, Int32, Encoding)

Reads a string from the specified symbol/variable.

AdsClient Class 68:

ReadAnyString(UInt32, UInt32, Int32, Encoding)

Reads as string from a specified address.

AdsClient Class 69:

ReadAnyStringAsync(UInt32, Int32, Encoding, CancellationToken)

Reads a string asynchronously from the specified symbol/variable

AdsClient Class 70:

ReadAnyStringAsync(UInt32, UInt32, Int32, Encoding, CancellationToken)

Reads a string from a specified address asynchronously.

AdsClient Class 71:

ReadAsync(UInt32, Memory.Byte., CancellationToken)

Reads the value data of the symbol asynchronously into the readBuffer.

AdsClient Class 72:

ReadAsync(UInt32, UInt32, Memory.Byte., CancellationToken)

Reads the data asynchronously from specified IndexGroup/IndexOffset

AdsClient Class 73:

ReadDataType

Call this method to obtain information about the specified data type.

AdsClient Class 74:

ReadDataTypeAsync

read data type as an asynchronous operation.

AdsClient Class 75:

ReadDeviceInfo

Reads the identification and version number of an ADS server.

AdsClient Class 76:

ReadDeviceInfoAsync

Reads the identification and version number of an ADS server.

AdsClient Class 77:

ReadState

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

AdsClient Class 78:

ReadStateAsync

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

AdsClient Class 79:

ReadSymbol

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

AdsClient Class 80:

ReadSymbolAsync

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

AdsClient Class 81:

ReadValue(ISymbol)

Reads the value of a symbol and returns it as an object.

AdsClient Class 82:

ReadValue(String, Type)

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

AdsClient Class 83:

ReadValue.T.(ISymbol)

Reads the value of a symbol and returns it as an object.

AdsClient Class 84:

ReadValue.T.(String)

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

AdsClient Class 85:

ReadValueAsync(ISymbol, CancellationToken)

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

AdsClient Class 86:

ReadValueAsync(String, Type, CancellationToken)

Reads the value of a symbol asynchronously.

AdsClient Class 87:

ReadValueAsync.TValue.(ISymbol, CancellationToken)

Reads the value of a symbol asynchronously and returns it as an object.

AdsClient Class 88:

ReadValueAsync.TValue.(String, CancellationToken)

Reads the value of a symbol asynchronously.

AdsClient Class 89:

ReadWrite(UInt32, Memory.Byte., ReadOnlyMemory.Byte.)

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

AdsClient Class 90:

ReadWrite(UInt32, UInt32, Memory.Byte., ReadOnlyMemory.Byte.)

Writes data synchronously to an ADS device and then Reads data from this device into the readBuffer

AdsClient Class 91:

ReadWriteAsync(UInt32, Memory.Byte., ReadOnlyMemory.Byte., CancellationToken)

ReadWrites value data asynchronously to/from the symbol represented by the variableHandle.

AdsClient Class 92:

ReadWriteAsync(UInt32, UInt32, Memory.Byte., ReadOnlyMemory.Byte., CancellationToken)

Read/Writes data asynchronously to/from the specified writeBuffer, readBuffer

AdsClient Class 93:

RegisterAdsStateChangedAsync

Registers for AdsStateChanged events as an asynchronous operation.

AdsClient Class 94:

RegisterSymbolVersionChanged

Registers for an AdsSymbolVersionChanged event as an asynchronous operation.

AdsClient Class 95:

RegisterSymbolVersionChangedAsync

Registers for an AdsSymbolVersionChanged event as an asynchronous operation.

AdsClient Class 96:

ToString

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

AdsClient Class 97:

TryAddDeviceNotification(String, Int32, NotificationSettings, Object, UInt32.)

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

AdsClient Class 98:

TryAddDeviceNotification(UInt32, UInt32, Int32, NotificationSettings, Object, UInt32.)

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

AdsClient Class 99:

TryAddDeviceNotificationEx(String, NotificationSettings, Object, Type, .Int32., UInt32.)

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

AdsClient Class 100:

TryAddDeviceNotificationEx(UInt32, UInt32, NotificationSettings, Object, Type, .Int32., UInt32.)

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

AdsClient Class 101:

TryCreateVariableHandle

Determines the Symbol handle by its instance path synchronously.

AdsClient Class 102:

TryDeleteDeviceNotification(UInt32)

Deletes a registered notification.

AdsClient Class 103:

TryDeleteDeviceNotification(UInt32, Int32)

Deletes a registered notification.

AdsClient Class 104:

TryDeleteVariableHandle

Releases the specified symbol/variable handle synchronously.

AdsClient Class 105:

AdsClient Class 106:

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

Invokes the specified RPC Method

AdsClient Class 107:

AdsClient Class 108:

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

Invokes the specified RPC Method

AdsClient Class 109:

AdsClient Class 110:

TryInvokeRpcMethod(IRpcCallableInstance, IRpcMethod, .Object., .AnyTypeSpecifier., AnyTypeSpecifier, .Object.., Object.)

Tries the invoke RPC method.

AdsClient Class 111:

AdsClient Class 112:

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

Invokes the RPC Method

AdsClient Class 113:

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

Reads the value synchronously data of the symbol, that is represented by the variable handle into the readBuffer.

AdsClient Class 114:

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

Reads value data from the specified IndexGroup/IndexOffset to the specified memory location.

AdsClient Class 115:

TryReadDataType

Call this method to obtain information about the specified data type.

AdsClient Class 116:

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

AdsClient Class 117:

TryReadSymbol

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

AdsClient Class 118:

TryReadValue(ISymbol, Object.)

Reads the value of a symbol and returns it as an object.

AdsClient Class 119:

TryReadValue(String, Type, Object.)

Reads the value of a symbol and returns the value as object.

AdsClient Class 120:

TryReadValue.T.(ISymbol, T.)

Reads the value of a symbol and returns it as an object.

AdsClient Class 121:

TryReadValue.T.(String, T.)

Reads the value of a symbol and returns the value as object.

AdsClient Class 122:

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

ReadWrites value data synchronously to/from the symbol represented by the variableHandle.

AdsClient Class 123:

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

Writes data synchronously to an ADS device and reads data from that device.

AdsClient Class 124:

TryResurrect

Resurrects the connection

AdsClient Class 125:

TryWrite(UInt32, ReadOnlyMemory.Byte.)

Writes the value data synchronously that is represented in the writeBuffer to the symbol with the specified variableHandle.

AdsClient Class 126:

TryWrite(UInt32, UInt32, ReadOnlyMemory.Byte.)

Writes data synchronously to an ADS device.

AdsClient Class 127:

TryWriteControl(StateInfo)

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

AdsClient Class 128:

TryWriteControl(StateInfo, ReadOnlyMemory.Byte.)

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

AdsClient Class 129:

TryWriteValue(ISymbol, 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.

AdsClient Class 130:

TryWriteValue(String, Object)

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

AdsClient Class 131:

TryWriteValue.T.(ISymbol, T)

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

AdsClient Class 132:

TryWriteValue.T.(String, T)

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

AdsClient Class 133:

UnregisterAdsStateChangedAsync

unregister ads state changed as an asynchronous operation.

AdsClient Class 134:

UnregisterSymbolVersionChanged

Unregisters the symbol version changed.

AdsClient Class 135:

UnregisterSymbolVersionChangedAsync

Unregisters from an AdsSymbolVersionChanged event as an asynchronous operation.

AdsClient Class 136:

Write(UInt32, ReadOnlyMemory.Byte.)

Writes data synchronously to an ADS device.

AdsClient Class 137:

Write(UInt32, UInt32)

Triggers a 'Write' call to the ADS device at the specified address.

AdsClient Class 138:

Write(UInt32, UInt32, ReadOnlyMemory.Byte.)

Writes data synchronously to an ADS device.

AdsClient Class 139:

WriteAny(UInt32, Object)

Writes an object synchronously to an ADS device.

AdsClient Class 140:

WriteAny(UInt32, Object, .Int32.)

Writes an object synchronously to an ADS device. If the Type of the object to be written is a string type, the first element of parameter args specifies the number of characters of the string.

AdsClient Class 141:

WriteAny(UInt32, UInt32, Object)

Writes an object synchronously to an ADS device.

AdsClient Class 142:

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

Writes an object synchronously to an ADS device.

AdsClient Class 143:

WriteAnyAsync(UInt32, Object, CancellationToken)

Writes an object synchronously to an ADS device. If the Type of the object to be written is a string type, the first element of parameter args specifies the number of characters of the string.

AdsClient Class 144:

WriteAnyAsync(UInt32, Object, .Int32., CancellationToken)

Writes an object asynchronously to an ADS device. If the Type of the object to be written is a string type, the first element of parameter args specifies the number of characters of the string.

AdsClient Class 145:

WriteAnyAsync(UInt32, UInt32, Object, CancellationToken)

Write the value of an Anytype (Primitive type) asynchronously.

AdsClient Class 146:

WriteAnyAsync(UInt32, UInt32, Object, .Int32., CancellationToken)

Write the value of an Anytype (Primitive type) asynchronously.

AdsClient Class 147:

WriteAnyStringAsync(String, String, Int32, Encoding, CancellationToken)

Writes the string (Potentially unsafe!)

AdsClient Class 148:

WriteAnyStringAsync(UInt32, String, Int32, Encoding, CancellationToken)

Writes the string (Potentially unsafe!)

AdsClient Class 149:

WriteAsync(UInt32, ReadOnlyMemory.Byte., CancellationToken)

Writes the value data asynchronously that is represented by the writeBuffer to the symbol specified by the variableHandle.

AdsClient Class 150:

WriteAsync(UInt32, UInt32, CancellationToken)

Triggers a write call at the specified IndexGroup/IndexOffset asynchronously.

AdsClient Class 151:

WriteAsync(UInt32, UInt32, ReadOnlyMemory.Byte., CancellationToken)

Writes the data / Value asynchronously into the specified writeBuffer.

AdsClient Class 152:

WriteControl(StateInfo)

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

AdsClient Class 153:

WriteControl(StateInfo, ReadOnlyMemory.Byte.)

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

AdsClient Class 154:

WriteControlAsync(AdsState, UInt16, CancellationToken)

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

AdsClient Class 155:

WriteControlAsync(AdsState, UInt16, ReadOnlyMemory.Byte., CancellationToken)

Writes the state asynchronously

AdsClient Class 156:

WriteSymbolAsync

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

AdsClient Class 157:

WriteValue(ISymbol, 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.

AdsClient Class 158:

WriteValue(String, Object)

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

AdsClient Class 159:

WriteValue.T.(ISymbol, T)

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

AdsClient Class 160:

WriteValue.T.(String, T)

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

AdsClient Class 161:

WriteValueAsync(ISymbol, Object, CancellationToken)

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.

AdsClient Class 162:

WriteValueAsync.T.(ISymbol, T, CancellationToken)

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

AdsClient Class 163:

WriteValueAsync.T.(String, T, CancellationToken)

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

AdsClient Class 164:

AdsClient Class 165:

AdsNotification

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

AdsClient Class 166:

AdsNotificationError

Occurs when a exception has occurred during notification management.

AdsClient Class 167:

AdsClient Class 168:

AdsNotificationEx

Occurs when the ADS devices sends a notification to the client.

AdsClient Class 169:

AdsNotificationsInvalidated

Occurs when Notification Unregistrations / Invalidates are received from the AdsServer

AdsClient Class 170:

AdsStateChanged

Occurs when the ADS state changes.

AdsClient Class 171:

AdsClient Class 172:

AdsSumNotification

Occurs when Notifications are send (bundled notifications)

AdsClient Class 173:

AdsSymbolVersionChanged

Occurs when the symbol version has been changed changes.

AdsClient Class 174:

ConnectionStateChanged

Occurs when the connection state has been changed.

AdsClient Class 175:

RouterStateChanged

(Local) Router state changed event.

Extension Methods

 

Name

Description

AdsClient Class 176:

PollAdsState(IObservable.Unit.)

Overloaded.

Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by ConnectionStateExtension.)

AdsClient Class 177:

AdsClient Class 178:

PollAdsState(IObservable.Unit.)

Overloaded.

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

AdsClient Class 179:

AdsClient Class 180:

PollAdsState(TimeSpan)

Overloaded.

Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by ConnectionStateExtension.)

AdsClient Class 181:

AdsClient Class 182:

PollAdsState(TimeSpan)

Overloaded.

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

AdsClient Class 183:

PollAdsState2(IObservable.Unit.)

Overloaded.

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

AdsClient Class 184:

AdsClient Class 185:

PollAdsState2(TimeSpan)

Overloaded.

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

AdsClient Class 186:

PollAdsState2Async(IObservable.Unit., CancellationToken)

Overloaded.

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

AdsClient Class 187:

PollAdsState2Async(TimeSpan, CancellationToken)

Overloaded.

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

AdsClient Class 188:

AdsClient Class 189:

PollAdsStateAsync(IObservable.Unit., CancellationToken)

Overloaded.

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

AdsClient Class 190:

AdsClient Class 191:

PollAdsStateAsync(IObservable.Unit., CancellationToken)

Overloaded.

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

AdsClient Class 192:

AdsClient Class 193:

PollAdsStateAsync(TimeSpan, CancellationToken)

Overloaded.

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

AdsClient Class 194:

AdsClient Class 195:

PollAdsStateAsync(TimeSpan, CancellationToken)

Overloaded.

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

AdsClient Class 196:

PollDeviceState(IObservable.Unit.)

Overloaded.

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

AdsClient Class 197:

AdsClient Class 198:

PollDeviceState(TimeSpan)

Overloaded.

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

AdsClient Class 199:

AdsClient Class 200:

PollDeviceStateAsync(IObservable.Unit., CancellationToken)

Overloaded.

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

AdsClient Class 201:

AdsClient Class 202:

PollDeviceStateAsync(TimeSpan, CancellationToken)

Overloaded.

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

AdsClient Class 203:

PollSystemServiceState

Polls the state of the system service. (Defined by SystemServiceExtension.)

AdsClient Class 204:

PollSystemServiceStateAsync

Polls the system service state asynchronously (Defined by SystemServiceExtension.)

AdsClient Class 205:

PollValues(ISymbol, Type, IObservable.Unit.)

Overloaded.

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

AdsClient Class 206:

PollValues(ISymbol, Type, TimeSpan)

Overloaded.

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

AdsClient Class 207:

PollValues(String, Type, IObservable.Unit.)

Overloaded.

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

AdsClient Class 208:

PollValues(String, Type, TimeSpan)

Overloaded.

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

AdsClient Class 209:

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

Overloaded.

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

AdsClient Class 210:

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

Overloaded.

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

AdsClient Class 211:

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

Overloaded.

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

AdsClient Class 212:

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

Overloaded.

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

AdsClient Class 213:

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

AdsClient Class 214:

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

AdsClient Class 215:

PollValues(ISymbol, 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.)

AdsClient Class 216:

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

Overloaded.

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

AdsClient Class 217:

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

AdsClient Class 218:

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

AdsClient Class 219:

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

Overloaded.

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

AdsClient Class 220:

PollValues.T.(ISymbol, TimeSpan)

Overloaded.

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

AdsClient Class 221:

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

Overloaded.

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

AdsClient Class 222:

PollValues.T.(String, TimeSpan)

Overloaded.

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

AdsClient Class 223:

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

Overloaded.

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

AdsClient Class 224:

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

Overloaded.

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

AdsClient Class 225:

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

Overloaded.

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

AdsClient Class 226:

AdsClient Class 227:

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

Overloaded.

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

AdsClient Class 228:

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

AdsClient Class 229:

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

AdsClient Class 230:

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

Overloaded.

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

AdsClient Class 231:

AdsClient Class 232:

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

Overloaded.

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

AdsClient Class 233:

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

Overloaded.

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

AdsClient Class 234:

AdsClient Class 235:

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

Overloaded.

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

AdsClient Class 236:

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

AdsClient Class 237:

AdsClient Class 238:

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

AdsClient Class 239:

PollValues2.T.(ISymbol, .Int32., IObservable.Unit.)

Overloaded.

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

AdsClient Class 240:

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

Overloaded.

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

AdsClient Class 241:

ReadSysServState

Reads the System Service state (AdsSysServState) (Defined by SystemServiceExtension.)

AdsClient Class 242:

ReadSysServStateAsync

Reads the System Service state (AdsSysServState) (asynchronous) (Defined by SystemServiceExtension.)

AdsClient Class 243:

ReadWithFallback(UInt32, UInt32, Memory.Byte., UInt32, Boolean.)

Overloaded.

Ads Read with fallback. (Defined by AdsClientExtensions.)

AdsClient Class 244:

ReadWithFallback(UInt32, UInt32, UInt32, Memory.Byte., Func.ResultRead, Boolean., Boolean.)

Overloaded.

Ads Read with Fallback. (Defined by AdsClientExtensions.)

AdsClient Class 245:

ReadWithFallbackAsync(UInt32, UInt32, UInt32, Memory.Byte., CancellationToken)

Overloaded.

Ads Read with fallback as an asynchronous operation. (Defined by AdsClientExtensions.)

AdsClient Class 246:

ReadWithFallbackAsync(UInt32, UInt32, UInt32, Memory.Byte., Func.ResultRead, Boolean., CancellationToken)

Overloaded.

Ads Read with fallback as an asynchronous operation. (Defined by AdsClientExtensions.)

AdsClient Class 247:

RepeatedRead(UInt32, UInt32, Memory.Byte., Int32, TimeSpan)

Overloaded.

Repeated AdsRead. (Defined by AdsClientExtensions.)

AdsClient Class 248:

RepeatedRead(UInt32, UInt32, Memory.Byte., Int32, TimeSpan, Func.ResultRead, Boolean.)

Overloaded.

Repeated AdsRead. (Defined by AdsClientExtensions.)

AdsClient Class 249:

RepeatedReadAsync(UInt32, UInt32, Memory.Byte., Int32, TimeSpan, CancellationToken)

Overloaded.

Repeated AdsRead as an asynchronous operation. (Defined by AdsClientExtensions.)

AdsClient Class 250:

RepeatedReadAsync(UInt32, UInt32, Memory.Byte., Int32, TimeSpan, Func.ResultRead, Boolean., CancellationToken)

Overloaded.

Repeated AdsRead as an asynchronous operation. (Defined by AdsClientExtensions.)

AdsClient Class 251:

RestartTwinCATAsync

Sends a SystemService Restart to the target system and waits until the system has finished the state changes (SystemService, Port 10000) (asynchronously) (Defined by SystemServiceExtension.)

AdsClient Class 252:

SetAdsState

Sets an AdsState/AdsStateCommand to an AdsServer and waits until the StateChange finishes. (Defined by ConnectionStateExtension.)

AdsClient Class 253:

SetAdsStateAsync

Sets an AdsState/AdsStateCommand to an AdsServer and waits until the StateChange finishes. (Defined by ConnectionStateExtension.)

AdsClient Class 254:

WaitUntilRestarted

Waits until the Restart is detected on the client (SystemService, Port 10000) (Defined by SystemServiceExtension.)

AdsClient Class 255:

WaitUntilRestartedAsync

Waits until the SystemService Restart is detectd on the client (SystemService, Port 10000) (asynchronously) (Defined by SystemServiceExtension.)

AdsClient Class 256:

AdsClient Class 257:

WhenAdsStateChanges

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

AdsClient Class 258:

WhenNotification(ISymbol)

Overloaded.

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

AdsClient Class 259:

AdsClient Class 260:

WhenNotification(ISymbolCollection)

Overloaded.

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

AdsClient Class 261:

AdsClient Class 262:

WhenNotification(IList.ISymbol., NotificationSettings)

Overloaded.

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

AdsClient Class 263:

WhenNotification(ISymbol, NotificationSettings)

Overloaded.

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

AdsClient Class 264:

AdsClient Class 265:

WhenNotification(String, Type, NotificationSettings)

Overloaded.

Creates an observable sequence of values that are created by ADS Notifications. (Defined by AnyTypeExtensions.)

AdsClient Class 266:

AdsClient Class 267:

WhenNotification.T.(String, NotificationSettings)

Overloaded.

Creates an observable sequence of values that are created by ADS Notifications. (Defined by AnyTypeExtensions.)

AdsClient Class 268:

WhenSymbolVersionChanges.

Overloaded.

Gets an observable sequence of SymbolVersion changed counts. (Defined by AdsClientExtensions.)

AdsClient Class 269:

WhenSymbolVersionChanges(IScheduler)

Overloaded.

Gets an observable sequence of SymbolVersion changed counts. (Defined by AdsClientExtensions.)

AdsClient Class 270:

AdsClient Class 271:

WhenValueChanged

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

AdsClient Class 272:

AdsClient Class 273:

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

Overloaded.

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

AdsClient Class 274:

AdsClient Class 275:

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

The class AdsClient enables synchronous/asynchronous access to data of an ADS Device.

Examples

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

AdsClient Demo (async)

using System;
using System.Buffers.Binary;
using System.Threading;
using System.Threading.Tasks;
using TwinCAT.Ads;
using TwinCAT.TypeSystem;

namespace Sample
{
    class ClientAsync
    {
    /// <summary>
    /// Defines the entry point of the application.
    /// </summary>
    /// <param name="args">The arguments.</param>
    static async void Main(string[] args)
    {
        AmsAddress address = ArgParser.Parse(args);
        CancellationTokenSource cancelSource = new CancellationTokenSource();
        CancellationToken cancel = cancelSource.Token;

        using (AdsClient client = new AdsClient())
        {

        // 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
        ResultDeviceInfo resultDeviceInfo = await client.ReadDeviceInfoAsync(cancel);

        if (resultDeviceInfo.Succeeded)
        {
            DeviceInfo deviceInfo = resultDeviceInfo.DeviceInfo;
            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
        ResultReadDeviceState resultReadDeviceState  = await client.ReadStateAsync(cancel);
        AdsState state = AdsState.Invalid;

        if (resultReadDeviceState.Succeeded)
        {
            StateInfo stateInfo = resultReadDeviceState.State;

            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)
        {
            await client.WriteControlAsync(AdsState.Run,0,cancel);
        }

        //create variable handle for Plc Project Name (automatic generated symbol in PLC)
        ResultHandle resultHandle = await client.CreateVariableHandleAsync("TwinCAT_SystemInfoVarList._AppInfo.ProjectName",cancel);

        if (resultHandle.Succeeded)
        {
            uint handleProjectName = resultHandle.Handle;
            uint handleNotification = 0; // Notification Handle for Task1 CycleCount changes

            try
            {
            // Read value from target and Marshal data into string
            byte[] readData = new byte[256];

                ResultRead resultRead = await client.ReadAsync(handleProjectName,readData.AsMemory(), cancel);

                if (resultRead.Succeeded)
                {
                PrimitiveTypeMarshaler marshaler = PrimitiveTypeMarshaler.Default;

                string projectName = null; 
                int unmarshaledBytes = marshaler.Unmarshal(readData, out projectName);
                Console.WriteLine(string.Format("ProjectName  : {0}", projectName));
                }

            //_notificationBuffer = new byte[4]; // Sizeof UDINT
            int size = sizeof(UInt32); // Sizeof UDINT

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

            //Register Notification for Task1 CycleCount symbol (automatic generated symbol in PLC)
            resultHandle = await client.AddDeviceNotificationAsync("TwinCAT_SystemInfoVarList._TaskInfo[1].CycleCount", size, NotificationSettings.Default, null, cancel);

            if (resultHandle.Succeeded)
            {
                handleNotification = resultHandle.Handle;
                // Sleep 10 Seconds to receive events
                await Task.Delay(10000, cancel); // Async Delay (some time for notifications)
            }
            }
            finally
            {
            // Cleanup all handles
            // Dispose all Streams

            ResultAds result = await client.DeleteDeviceNotificationAsync(handleNotification, cancel);

            // Always delete all variable handles.
            result = await client.DeleteVariableHandleAsync(handleProjectName, cancel);
            }
        }
        Console.WriteLine("");
        Console.WriteLine("Press [Enter] for leave:");
        Console.ReadLine();
        }
    }

AdsClient Demo (sync)

using System;
using System.Buffers.Binary;
using System.Threading;
using System.Threading.Tasks;
using TwinCAT.Ads;
using TwinCAT.TypeSystem;

namespace Sample
{
    class Client
    {
    /// <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 (AdsClient client = new AdsClient())
        {

        // 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 = AdsState.Invalid;

        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)
        {
            client.WriteControl(new StateInfo(AdsState.Run, 0));
        }

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

        try
        {
            // Read value from target and Marshal data into string
            byte[] readData = new byte[256];
            int readBytes = client.Read(handleProjectName, readData.AsMemory());

            PrimitiveTypeMarshaler marshaler = PrimitiveTypeMarshaler.Default;

            string projectName = null;
            int unmarshaledBytes = marshaler.Unmarshal(readData, client.DefaultValueEncoding, out projectName);
            Console.WriteLine(string.Format("ProjectName  : {0}", projectName));

            //_notificationBuffer = new byte[4]; // Sizeof UDINT
            int size = sizeof(UInt32); // Sizeof UDINT

            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", size, NotificationSettings.Default, null);

            // Sleep 10 Seconds to receive events
            Thread.Sleep(10000); // Sleep to get notifications
        }
        finally
        {
            // Cleanup all handles
            // Dispose all Streams
            client.DeleteDeviceNotification(handleNotification);

            // 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 AdsClient class.

RPC Call Example (async)

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

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

        // Create the ADS Client
        using (AdsClient client = new AdsClient())
        {
        // 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 
        */

        ResultRpcMethod result1 = await client.InvokeRpcMethodAsync("MAIN", "M_Add", new object[] { (short)1, (short)4 }, CancellationToken.None);
        short result = (short)result1.ReturnValue;

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

RPC Call Example (sync)

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

    class RpcCall
    {
    /// <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 (AdsClient client = new AdsClient())
        {
        // 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