AdsClient Class

ADS Client / ADS Communication object.

Inheritance Hierarchy

SystemObject
  TwinCAT.AdsAdsClient

Namespace: TwinCAT.Ads
Assembly: TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 7.0.0+e56d35ccc4675faac24789a4aab60071fc61d470

Syntax

C#

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

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(ILoggerFactory)

Initializes a new instance of the AdsClient class.

AdsClient(IConfiguration, ILoggerFactory)

Initializes a new instance of the AdsClient class.

AdsClient(ISession, IConfiguration, ILoggerFactory)

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

AdsClient(ISession, AdsClientSettings, ILoggerFactory)

Initializes a new instance of the AdsClient class.

AdsClient(ISession, AdsClientSettings, IConfiguration, ILoggerFactory)

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:

ChannelPortType

Gets the channel port type.

AdsClient Class 3:

ChannelProtocol

Gets the the used channel protocol.

AdsClient Class 4:

ClientAddress

Get the AmsAddress of the ADS client.
Obsolete

AdsClient Class 5:

Configuration

Gets the optional Configuration

AdsClient Class 6:

DefaultValueEncoding

Gets the default value encoding.

AdsClient Class 7:

Id

Gets the AdsClient Identifier.

AdsClient Class 8:

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 9:

IsDisposed

Gets a value indicating whether this instance is disposed.

AdsClient Class 10:

IsLocal

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

AdsClient Class 11:

Logger

Gets the logger inteface.

AdsClient Class 12:

LoggerFactory

Gets the logger factory.

AdsClient Class 13:

PlatformPointerSize

Gets the target platform pointer size

AdsClient Class 14:

Session

Gets the session that initiated this IConnection

AdsClient Class 15:

SourceAddress

Get the client/source AmsAddress (Source side).

AdsClient Class 16:

SymbolEncoding

Gets the symbol encoding.

AdsClient Class 17:

Timeout

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

Methods

 

Name

Description

AdsClient Class 18:

AddDeviceNotification(String, Int32, NotificationSettings, Object)

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

AdsClient Class 19:

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 20:

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 21:

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

Adds a device notification as an asynchronous operation.

AdsClient Class 22:

AddDeviceNotificationEx(String, NotificationSettings, Object, Type)

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

AdsClient Class 23:

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 24:

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 25:

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 26:

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 27:

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 28:

CleanupSymbolTable

Clears the internal symbol cache.

AdsClient Class 29:

Close

Closes this AdsClient

AdsClient Class 30:

Connect(AmsAddress)

Connects/Reconnects to the specified target address.

AdsClient Class 31:

Connect(AmsPort)

Connects the specified port.

AdsClient Class 32:

Connect(Int32)

Connects/Reconnects to the specified port of the local ADS target device.

AdsClient Class 33:

Connect(AmsNetId, Int32)

Connects/Reconnects to the specified target address.

AdsClient Class 34:

Connect(AmsNetId, AmsPort)

Connects the specified net identifier.

AdsClient Class 35:

Connect(String, Int32)

Connects/Reconnects to the specified target address.

AdsClient Class 36:

ConnectAndWaitAsync

Connects/Reconnects to the target address and waits until the IAdsConnection is disconnected asynchronously.

AdsClient Class 37:

ConnectAsync(AmsAddress, CancellationToken)

Connects/Reconnects to the specified target address asynchronously.

AdsClient Class 38:

ConnectAsync(Int32, CancellationToken)

Connects/Reconnects to the specified port of the local system asynchonously.

AdsClient Class 39:

ConnectAsync(AmsNetId, Int32, CancellationToken)

Connects/Reconnects to the specified target address asynchronously.

AdsClient Class 40:

CreateVariableHandle

Determines the Symbol handle by its instance path synchronously.

AdsClient Class 41:

CreateVariableHandleAsync

Determines the Symbol handle by its instance path asynchronously.

AdsClient Class 42:

DeleteDeviceNotification

Deletes a registered notification.

AdsClient Class 43:

DeleteDeviceNotificationAsync

Deletes a registered notification asynchronously.

AdsClient Class 44:

DeleteVariableHandle

Releases the specified symbol/variable handle synchronously.

AdsClient Class 45:

DeleteVariableHandleAsync

Releases the specified symbol/variable handle asynchronously.

AdsClient Class 46:

Disconnect

Disconnects this AdsClient from the local ADS router.

AdsClient Class 47:

DisconnectAsync

Disconnects this AdsClient from the local ADS router.

AdsClient Class 48:

Dispose

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

AdsClient Class 49:

Equals

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

AdsClient Class 50:

Finalize

Finalizes an instance of the AdsClient class.
(Overrides ObjectFinalize)

AdsClient Class 51:

GetHashCode

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

AdsClient Class 52:

GetType

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

AdsClient Class 53:

InvokeRpcMethodAsync(IRpcCallableInstance, IRpcMethod, Object, CancellationToken)

invoke RPC method as an asynchronous operation.

AdsClient Class 54:

AdsClient Class 55:

InvokeRpcMethodAsync(String, String, Object, CancellationToken)

Invokes the specified RPC Method asynchronously

AdsClient Class 56:

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

invoke RPC method as an asynchronous operation.

AdsClient Class 57:

AdsClient Class 58:

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

Invokes the specified RPC Method asynchronously

AdsClient Class 59:

ReadAny(String, Type)

Reads any.

AdsClient Class 60:

ReadAny(UInt32, Type)

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

AdsClient Class 61:

ReadAny(String, Type, Int32)

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

AdsClient Class 62:

ReadAny(UInt32, Type, Int32)

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

AdsClient Class 63:

ReadAny(UInt32, UInt32, Type)

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

AdsClient Class 64:

ReadAny(UInt32, UInt32, Type, Int32)

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

AdsClient Class 65:

ReadAnyT(String)

Reads any.

AdsClient Class 66:

ReadAnyT(UInt32)

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

AdsClient Class 67:

ReadAnyT(String, Int32)

Reads any.

AdsClient Class 68:

ReadAnyT(UInt32, Int32)

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

AdsClient Class 69:

ReadAnyT(UInt32, UInt32)

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

AdsClient Class 70:

ReadAnyT(UInt32, UInt32, Int32)

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

AdsClient Class 71:

ReadAnyAsResultT(String)

Reads any as result.

AdsClient Class 72:

ReadAnyAsResultT(String, Int32)

Reads any as result.

AdsClient Class 73:

ReadAnyAsync(String, Type, CancellationToken)

Reads any asynchronous.

AdsClient Class 74:

ReadAnyAsync(UInt32, Type, CancellationToken)

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

AdsClient Class 75:

ReadAnyAsync(String, Type, Int32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 76:

ReadAnyAsync(UInt32, Type, Int32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 77:

ReadAnyAsync(UInt32, UInt32, Type, CancellationToken)

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

AdsClient Class 78:

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

Read any as an asynchronous operation.

AdsClient Class 79:

ReadAnyAsyncT(String, CancellationToken)

Reads any asynchronous.

AdsClient Class 80:

ReadAnyAsyncT(UInt32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 81:

ReadAnyAsyncT(String, Int32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 82:

ReadAnyAsyncT(UInt32, Int32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 83:

ReadAnyAsyncT(UInt32, UInt32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 84:

ReadAnyAsyncT(UInt32, UInt32, Int32, CancellationToken)

Read any as an asynchronous operation.

AdsClient Class 85:

ReadAnyString(String, Int32, Encoding)

Reads any string.

AdsClient Class 86:

ReadAnyString(UInt32, Int32, Encoding)

Reads a string from the specified symbol/variable.

AdsClient Class 87:

ReadAnyString(UInt32, UInt32, Int32, Encoding)

Reads as string from a specified address.

AdsClient Class 88:

ReadAnyStringAsync(String, Int32, Encoding, CancellationToken)

Reads a string asynchronously from the specified symbol/variable

AdsClient Class 89:

ReadAnyStringAsync(UInt32, Int32, Encoding, CancellationToken)

Reads a string asynchronously from the specified symbol/variable

AdsClient Class 90:

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

Reads a string from a specified address asynchronously.

AdsClient Class 91:

ReadAsResult(UInt32, Int32)

Reads the value synchronously />.

AdsClient Class 92:

ReadAsResult(UInt32, UInt32, Int32)

Reads data synchronously from an ADS device.

AdsClient Class 93:

ReadDataType

Reads/Determines the DataType Inforrmation with the specifed name.

AdsClient Class 94:

ReadDataTypeAsync

Read data type as an asynchronous operation.

AdsClient Class 95:

ReadDeviceInfo

Reads the identification and version number of an ADS server.

AdsClient Class 96:

ReadDeviceInfoAsync

Reads the identification and version number of an ADS server.

AdsClient Class 97:

ReadState

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

AdsClient Class 98:

ReadStateAsync

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

AdsClient Class 99:

ReadSymbol

Reads the symbol.

AdsClient Class 100:

ReadSymbolAsync

Read symbol as an asynchronous operation.

AdsClient Class 101:

ReadValue(ISymbol)

Reads the value of a symbol and returns the value as (boxed) object.

AdsClient Class 102:

ReadValue(String)

Reads the value of a symbol specified with its instance path and returns the value as boxed object.

AdsClient Class 103:

ReadValue(String, Type)

Reads the value of a symbol specified with its instance path and returns the value as object of the specified type.

AdsClient Class 104:

ReadValueT(ISymbol)

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

AdsClient Class 105:

ReadValueT(String)

Reads the value.

AdsClient Class 106:

ReadValueAsync(ISymbol, CancellationToken)

Read value as an asynchronous operation.

AdsClient Class 107:

ReadValueAsync(String, Type, CancellationToken)

Read value as an asynchronous operation.

AdsClient Class 108:

ReadValueAsyncTValue(ISymbol, CancellationToken)

Read value as an asynchronous operation.

AdsClient Class 109:

ReadValueAsyncT(String, CancellationToken)

Read value as an asynchronous operation.

AdsClient Class 110:

ReadWrite(UInt32, MemoryByte, ReadOnlyMemoryByte)

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

AdsClient Class 111:

ReadWrite(UInt32, UInt32, MemoryByte, ReadOnlyMemoryByte)

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

AdsClient Class 112:

ReadWriteAsResult

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

AdsClient Class 113:

RegisterAdsStateChangedAsync

Registers for AdsStateChanged events as an asynchronous operation.

AdsClient Class 114:

RegisterSymbolVersionChanged

Registers the symbol version changed event (synchronously)

AdsClient Class 115:

RegisterSymbolVersionChangedAsync

Register symbol version changed as an asynchronous operation.

AdsClient Class 116:

ResurrectAsync

Resurrects the connection

AdsClient Class 117:

ToString

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

AdsClient Class 118:

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 119:

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 120:

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 121:

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 122:

TryCreateVariableHandle

Determines the Symbol handle by its instance path synchronously.

AdsClient Class 123:

TryDeleteDeviceNotification(UInt32)

Deletes a registered notification.

AdsClient Class 124:

TryDeleteDeviceNotification(UInt32, Int32)

Deletes a registered notification.

AdsClient Class 125:

TryDeleteVariableHandle

Releases the specified symbol/variable handle synchronously.

AdsClient Class 126:

AdsClient Class 127:

TryInvokeRpcMethod(String, String, Object, Object)

Invokes the specified RPC Method

AdsClient Class 128:

AdsClient Class 129:

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

Invokes the specified RPC Method

AdsClient Class 130:

AdsClient Class 131:

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

Tries the invoke RPC method.

AdsClient Class 132:

AdsClient Class 133:

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

Invokes the RPC Method

AdsClient Class 134:

TryReadAnyString

Tries the read any string.

AdsClient Class 135:

TryReadDataType

Tries to Read/Determine the DataType of the specified type.

AdsClient Class 136:

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 137:

TryReadSymbol

Tries to read the symbol information object specified by the instance path.

AdsClient Class 138:

TryReadValue(ISymbol, Object)

Tries to read the value of a symbol and returns the value as boxed object.

AdsClient Class 139:

TryReadValue(String, Type, Object)

Tries to the value of a symbol specified as instance path and returns the value as (boxed) object.

AdsClient Class 140:

TryReadValueT(ISymbol, T)

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

AdsClient Class 141:

TryReadValueT(String, T)

Tries to reads the value of a symbol specified with instance path and returns the typed value.

AdsClient Class 142:

TryReadWrite(UInt32, MemoryByte, ReadOnlyMemoryByte, Int32)

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

AdsClient Class 143:

TryReadWrite(UInt32, UInt32, MemoryByte, ReadOnlyMemoryByte, Int32)

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

AdsClient Class 144:

TryResurrect

Resurrects the connection

AdsClient Class 145:

TryWrite(UInt32, ReadOnlyMemoryByte)

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

AdsClient Class 146:

TryWrite(UInt32, UInt32, ReadOnlyMemoryByte)

Writes data synchronously to an ADS device.

AdsClient Class 147:

TryWriteControl(StateInfo)

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

AdsClient Class 148:

TryWriteControl(StateInfo, ReadOnlyMemoryByte)

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

AdsClient Class 149:

TryWriteValue(ISymbol, Object)

Tries to write a (boxed) value to the symbol

AdsClient Class 150:

TryWriteValue(String, Object)

Tries to write a (boxed) value to the symbol instance specified by its instance/symbol path.

AdsClient Class 151:

TryWriteValueT(ISymbol, T)

Tries to write a value to the symbol.

AdsClient Class 152:

TryWriteValueT(String, T)

Tries to Write a (typed) value to the symbol instance specified by its instance/symbol path.

AdsClient Class 153:

UnregisterAdsStateChangedAsync

unregister ads state changed as an asynchronous operation.

AdsClient Class 154:

UnregisterSymbolVersionChanged

Unregisters the symbol version changed event (synchronously)

AdsClient Class 155:

UnregisterSymbolVersionChangedAsync

Unregister symbol version changed as an asynchronous operation.

AdsClient Class 156:

Write(UInt32, ReadOnlyMemoryByte)

Writes data synchronously to an ADS device.

AdsClient Class 157:

Write(UInt32, UInt32)

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

AdsClient Class 158:

Write(UInt32, UInt32, ReadOnlyMemoryByte)

Writes data synchronously to an ADS device.

AdsClient Class 159:

WriteAny(UInt32, Object)

Writes an object synchronously to an ADS device.

AdsClient Class 160:

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 161:

WriteAny(UInt32, UInt32, Object)

Writes an object synchronously to an ADS device.

AdsClient Class 162:

WriteAny(UInt32, UInt32, Object, Int32)

Writes an object synchronously to an ADS device.

AdsClient Class 163:

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 164:

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 165:

WriteAnyAsync(UInt32, UInt32, Object, 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 166:

WriteAnyAsync(UInt32, 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 167:

WriteAnyStringAsync

Writes the string (Potentially unsafe!)

AdsClient Class 168:

WriteAsResult

Writes the data / Value into the specified writeBuffer.

AdsClient Class 169:

WriteAsync(UInt32, ReadOnlyMemoryByte, CancellationToken)

Write as an asynchronous operation.

AdsClient Class 170:

WriteAsync(UInt32, UInt32, CancellationToken)

Writes the asynchronous.

AdsClient Class 171:

WriteAsync(UInt32, UInt32, ReadOnlyMemoryByte, CancellationToken)

Write as an asynchronous operation.

AdsClient Class 172:

WriteControl(StateInfo)

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

AdsClient Class 173:

WriteControl(StateInfo, ReadOnlyMemoryByte)

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

AdsClient Class 174:

WriteControlAsync(AdsState, UInt16, CancellationToken)

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

AdsClient Class 175:

WriteControlAsync(AdsState, UInt16, ReadOnlyMemoryByte, CancellationToken)

Writes the state asynchronously

AdsClient Class 176:

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 177:

WriteValue(ISymbol, Object)

Writes a (boxed) value to the symbol.

AdsClient Class 178:

WriteValue(String, Object)

Writes a (boxed value) to the symbol instance specified by its instance/symbol path.

AdsClient Class 179:

WriteValueT(ISymbol, T)

Writes a (typed) value to the symbol.

AdsClient Class 180:

WriteValueT(String, T)

Writes a typed value to the symbol instance specified by its instance/symbol path.

AdsClient Class 181:

WriteValueAsync(ISymbol, Object, CancellationToken)

Writes a (boxed) value to the symbol as an asynchronous operation.

AdsClient Class 182:

WriteValueAsyncT(ISymbol, T, CancellationToken)

Writes a (typed) value to the symbol as an asynchronous operation.

AdsClient Class 183:

WriteValueAsyncT(String, T, CancellationToken)

Writes a (typed) value to the symbol instance specified by its instance/symbol path as an asynchronous operation.

Events

 

Name

Description

AdsClient Class 184:

AdsClient Class 185:

AdsNotification

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

AdsClient Class 186:

AdsNotificationError

Occurs when a exception has occurred during notification management.

AdsClient Class 187:

AdsClient Class 188:

AdsNotificationEx

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

AdsClient Class 189:

AdsNotificationsInvalidated

Occurs when Notification Unregistrations / Invalidates are received from the AdsServer

AdsClient Class 190:

AdsStateChanged

Occurs when the ADS state changes.

AdsClient Class 191:

AdsClient Class 192:

AdsSumNotification

Occurs when Notifications are send (bundled notifications)

AdsClient Class 193:

AdsSymbolVersionChanged

Occurs when the SymbolVersion table of a TwinCAT PLC System has been changed.

AdsClient Class 194:

ConnectionStateChanged

Occurs when the connection state has been changed.

AdsClient Class 195:

RouterStateChanged

(Local) Router state changed event.

Extension Methods

 

Name

Description

PollAdsState

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

PollAdsState

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

PollAdsState

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

PollAdsState

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

PollAdsState2

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

PollAdsState2

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

PollAdsState2Async

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

PollAdsState2Async

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

PollAdsStateAsync

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

PollAdsStateAsync

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

PollAdsStateAsync

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

PollAdsStateAsync

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

PollDeviceState

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

PollDeviceState

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

PollDeviceStateAsync

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

PollDeviceStateAsync

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

PollSystemServiceState

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

PollSystemServiceStateAsync

Polls the system service state asynchronously
(Defined by SystemServiceExtension)

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValues

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValuesT

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

PollValues2T

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

PollValues2T

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

ReadSysServState

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

ReadSysServStateAsync

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

ReadWithFallback

Read with fallback.
(Defined by AdsClientExtensions)

ReadWithFallback

Ads Read with Fallback.
(Defined by AdsClientExtensions)

ReadWithFallback

Ads Read with Fallback.
(Defined by AdsClientExtensions)

ReadWithFallbackAsync

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

ReadWithFallbackAsync

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

ReadWithFallbackAsync

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

ReadWriteWithFallback

Ads Read with Fallback.
(Defined by AdsClientExtensions)

ReadWriteWithFallback

ReadWrite with Fallback.
(Defined by AdsClientExtensions)

ReadWriteWithFallbackAsync

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

ReadWriteWithFallbackAsync

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

RepeatedRead

Repeated AdsRead.
(Defined by AdsClientExtensions)

RepeatedRead

Repeated AdsRead.
(Defined by AdsClientExtensions)

RepeatedReadAsync

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

RepeatedReadAsync

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

RepeatedReadWrite

Repeated AdsRead.
(Defined by AdsClientExtensions)

RepeatedReadWriteAsync

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

RepeatedWrite

Repeated AdsWrie.
(Defined by AdsClientExtensions)

RepeatedWriteAsync

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

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)

SetAdsState

Sends an AdsState/AdsStateCommand Request to an AdsServer and waits until the StateChange is done or fails.
(Defined by ConnectionStateExtension)

SetAdsStateAsync

Sends an AdsState/AdsStateCommand Request to an AdsServer and waits until the StateChange is done or fails (asynchronously)
(Defined by ConnectionStateExtension)

WaitForTargetState

Waits until the target AdsServer reaches the requested state.
(Defined by ConnectionStateExtension)

WaitForTargetStateAsync

Waits until the target AdsServer reaches the requested state (asynchronous)
(Defined by ConnectionStateExtension)

WaitUntilRestarted

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

WaitUntilRestartedAsync

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

WhenAdsStateChanges

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

WhenNotification

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

WhenNotification

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

WhenNotification

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

WhenNotification

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

WhenNotification

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

WhenNotificationT

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

WhenSymbolVersionChanges

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

WhenSymbolVersionChanges

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

WhenValueChanged

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

WriteValuesT

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

WriteValuesT

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.

Example

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
            ResultReadBytes resultRead = await client.ReadAsync(handleProjectName, 256, cancel);

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

                string projectName = null;
                int unmarshaledBytes = marshaler.Unmarshal(resultRead.Data.Span, 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
            var readResult = client.ReadAsResult(handleProjectName, 256);
            readResult.ThrowOnError(); // Throw if error

            PrimitiveTypeMarshaler marshaler = PrimitiveTypeMarshaler.Default;

            string projectName = null;
            int unmarshaledBytes = marshaler.Unmarshal(readResult.Data.Span, 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 the FunctionBlock instance 'fbInst')

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

        ResultRpcMethod result1 = await client.InvokeRpcMethodAsync("fbInst", "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("fbInst", "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 the FunctionBlock instance 'fbInst')

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

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

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

Add a custom logger

static async void Main(string[] args)
{
    CancellationTokenSource cancelSource = new CancellationTokenSource();
    CancellationToken cancel = cancelSource.Token;

    var address = new AmsAddress(AmsNetId.Local, AmsPort.SystemService);
    var sessionSettings = SessionSettings.Default;

    //https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line

    // Create a configuration for the custom logger
    var loggerConfig = new AdsLoggerConfiguration
    {
    LogLevel = LogLevel.Information,
    EventId = 0
    };

    // Create an ILoggerFactory and add the custom logger provider
    var loggerFactory = LoggerFactory.Create(builder =>
    {
    //builder.SetMinimumLevel(LogLevel.Information)
    builder.AddProvider(new AdsLoggerProvider(() => loggerConfig))
       .AddConsole(); // Adds the console
    });

    // Use AdsClient with custom logger
    using (AdsClient client = new AdsClient(loggerFactory))
    {
    // Connect
    client.Connect(address);
    }

    // Use AdsSession with custom logger
    using (AdsSession session = new AdsSession(address, sessionSettings, loggerFactory))
    {
    // Connect
    session.Connect();
    }
}

Reference

TwinCAT.Ads Namespace

Beckhoff Automation GmbH & Co. KG 2001-2026