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 |
---|---|---|
|
Initializes a new instance of the AdsClient class. | |
|
Initializes a new instance of the AdsClient class with the specified settings. | |
|
Initializes a new instance of the AdsClient class. | |
|
Initializes a new instance of the AdsClient class bound to a session. | |
|
Initializes a new instance of the AdsClient class. |
Properties
|
Name |
Description |
---|---|---|
|
Gets the target AmsAddress of of the established ADS connection (Destination side). | |
|
Get the client AmsAddress (Source side). | |
|
Gets the default value encoding. | |
|
Gets the AdsClient Identifier. | |
|
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. | |
|
Gets a value indicating whether this instance is disposed. | |
|
Gets a value indicating whether the ADS client is connected to a ADS Server on the local computer. | |
|
Gets the logger inteface. | |
|
Gets the session that initiated this IConnection | |
|
Gets the symbol encoding. | |
|
Sets the timeout for the ads communication. Unit is in ms. |
Methods
|
Name |
Description |
---|---|---|
|
AddDeviceNotification(String, Int32, NotificationSettings, Object) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event. |
|
AddDeviceNotification(UInt32, UInt32, Int32, NotificationSettings, Object) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event. |
|
AddDeviceNotificationAsync(String, Int32, NotificationSettings, Object, CancellationToken) |
Connects a variable to the ADS client asynchronously. The ADS client will be notified by the AdsNotification event. |
|
AddDeviceNotificationAsync(UInt32, UInt32, Int32, NotificationSettings, Object, CancellationToken) |
Adds a device notification as an asynchronous operation. |
|
AddDeviceNotificationEx(String, NotificationSettings, Object, Type) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotificationEx event. |
|
AddDeviceNotificationEx(String, NotificationSettings, Object, Type, .Int32.) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotificationEx event. |
|
AddDeviceNotificationEx(UInt32, UInt32, NotificationSettings, Object, Type) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotificationEx event. |
|
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. |
|
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. |
|
Connects a variable to the ADS client asynchronously. The ADS client will be notified by the AdsNotificationEx event. | |
|
Clears the internal symbol cache. | |
|
Closes this AdsClient | |
|
Connects the target | |
|
Connects to the local target ADS Device. | |
|
Connects to the local target ADS Device. | |
|
Connects to the target ADS Device. | |
|
Connects to the target ADS Device. | |
|
Connects to the target ADS Device. | |
|
Connects to the target address and waits until the AdsClient is disconnected asynchronously. | |
|
Determines the Symbol handle by its instance path synchronously. | |
|
Determines the Symbol handle by its instance path asynchronously. | |
|
Deletes a registered notification. | |
|
Deletes a registered notification asynchronously. | |
|
Releases the specified symbol/variable handle synchronously. | |
|
Releases the specified symbol/variable handle asynchronously. | |
|
Disconnects this AdsClient from the local ADS router. | |
|
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | |
|
Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
|
Finalizes an instance of the AdsClient class. (Overrides Object.Finalize..) | |
|
Serves as the default hash function. (Inherited from Object.) | |
|
Gets the Type of the current instance. (Inherited from Object.) | |
|
InvokeRpcMethodAsync(IRpcCallableInstance, IRpcMethod, .Object., CancellationToken) |
invoke RPC method as an asynchronous operation. |
|
InvokeRpcMethodAsync(String, String, .Object., CancellationToken) |
Invokes the specified RPC Method asynchronously |
|
invoke RPC method as an asynchronous operation. | |
|
Invokes the specified RPC Method asynchronously | |
|
Reads data synchronously from an ADS device and writes to the specified readBuffer. | |
|
Reads data synchronously from an ADS device and writes it to the given readBuffer | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads data synchronously from an ADS device and writes it to an object. | |
|
Reads the value of an Anytype (Primitive type) asynchronously. | |
|
Reads the value of an Anytype (Primitive type) asynchronously. | |
|
Reads the value of an Anytype (Primitive type) asynchronously. | |
|
ReadAnyAsync(UInt32, UInt32, Type, .Int32., CancellationToken) |
Reads the value of an Anytype (Primitive type) asynchronously. |
|
Reads data synchronously from an ADS device. | |
|
Reads data asynchronously from an ADS device and writes it to an object. | |
|
Reads data asynchronously from an ADS device and writes it to an object. | |
|
Reads data asynchronously from an ADS device and writes it to an object. | |
|
Reads a string from the specified symbol/variable. | |
|
Reads as string from a specified address. | |
|
ReadAnyStringAsync(UInt32, Int32, Encoding, CancellationToken) |
Reads a string asynchronously from the specified symbol/variable |
|
ReadAnyStringAsync(UInt32, UInt32, Int32, Encoding, CancellationToken) |
Reads a string from a specified address asynchronously. |
|
Reads the value data of the symbol asynchronously into the readBuffer. | |
|
Reads the data asynchronously from specified IndexGroup/IndexOffset | |
|
Call this method to obtain information about the specified data type. | |
|
read data type as an asynchronous operation. | |
|
Reads the identification and version number of an ADS server. | |
|
Reads the identification and version number of an ADS server. | |
|
Reads the ADS status and the device status from an ADS server. | |
|
Reads the ADS status and the device status from an ADS server. | |
|
Call this method to obtain information about the individual symbols (variables) in ADS devices. | |
|
Call this method to obtain information about the individual symbols (variables) in ADS devices. | |
|
Reads the value of a symbol and returns it as an object. | |
|
Reads the value of a symbol and returns the value as object. The parameter type must have the same layout as the ADS symbol. | |
|
Reads the value of a symbol and returns it as an object. | |
|
Reads the value of a symbol and returns the value. The parameter type must have the same layout as the ADS symbol. | |
|
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. | |
|
Reads the value of a symbol asynchronously. | |
|
Reads the value of a symbol asynchronously and returns it as an object. | |
|
Reads the value of a symbol asynchronously. | |
|
Writes data synchronously to an ADS device and then Reads data from that target. | |
|
ReadWrite(UInt32, UInt32, Memory.Byte., ReadOnlyMemory.Byte.) |
Writes data synchronously to an ADS device and then Reads data from this device into the readBuffer |
|
ReadWriteAsync(UInt32, Memory.Byte., ReadOnlyMemory.Byte., CancellationToken) |
ReadWrites value data asynchronously to/from the symbol represented by the variableHandle. |
|
ReadWriteAsync(UInt32, UInt32, Memory.Byte., ReadOnlyMemory.Byte., CancellationToken) |
Read/Writes data asynchronously to/from the specified writeBuffer, readBuffer |
|
Registers for AdsStateChanged events as an asynchronous operation. | |
|
Registers for an AdsSymbolVersionChanged event as an asynchronous operation. | |
|
Registers for an AdsSymbolVersionChanged event as an asynchronous operation. | |
|
Returns a string that represents the current object. (Inherited from Object.) | |
|
TryAddDeviceNotification(String, Int32, NotificationSettings, Object, UInt32.) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event. |
|
TryAddDeviceNotification(UInt32, UInt32, Int32, NotificationSettings, Object, UInt32.) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event. |
|
TryAddDeviceNotificationEx(String, NotificationSettings, Object, Type, .Int32., UInt32.) |
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotificationEx event. |
|
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. |
|
Determines the Symbol handle by its instance path synchronously. | |
|
Deletes a registered notification. | |
|
Deletes a registered notification. | |
|
Releases the specified symbol/variable handle synchronously. | |
|
Invokes the specified RPC Method | |
|
TryInvokeRpcMethod(String, String, .Object., .Object.., Object.) |
Invokes the specified RPC Method |
|
Tries the invoke RPC method. | |
|
Invokes the RPC Method | |
|
Reads the value synchronously data of the symbol, that is represented by the variable handle into the readBuffer. | |
|
Reads value data from the specified IndexGroup/IndexOffset to the specified memory location. | |
|
Call this method to obtain information about the specified data type. | |
|
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. | |
|
Call this method to obtain information about the individual symbols (variables) in ADS devices. | |
|
Reads the value of a symbol and returns it as an object. | |
|
Reads the value of a symbol and returns the value as object. | |
|
Reads the value of a symbol and returns it as an object. | |
|
Reads the value of a symbol and returns the value as object. | |
|
TryReadWrite(UInt32, Memory.Byte., ReadOnlyMemory.Byte., Int32.) |
ReadWrites value data synchronously to/from the symbol represented by the variableHandle. |
|
TryReadWrite(UInt32, UInt32, Memory.Byte., ReadOnlyMemory.Byte., Int32.) |
Writes data synchronously to an ADS device and reads data from that device. |
|
Resurrects the connection | |
|
Writes the value data synchronously that is represented in the writeBuffer to the symbol with the specified variableHandle. | |
|
Writes data synchronously to an ADS device. | |
|
Changes the ADS status and the device status of an ADS server. | |
|
Changes the ADS status and the device status of an ADS server. | |
|
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. | |
|
Writes the passed object value to the specified ADS symbol.The parameter type must have the same layout as the ADS symbol. | |
|
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. | |
|
Writes the passed object value to the specified ADS symbol.The parameter type must have the same layout as the ADS symbol. | |
|
unregister ads state changed as an asynchronous operation. | |
|
Unregisters the symbol version changed. | |
|
Unregisters from an AdsSymbolVersionChanged event as an asynchronous operation. | |
|
Writes data synchronously to an ADS device. | |
|
Triggers a 'Write' call to the ADS device at the specified address. | |
|
Writes data synchronously to an ADS device. | |
|
Writes an object synchronously to an ADS device. | |
|
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. | |
|
Writes an object synchronously to an ADS device. | |
|
Writes an object synchronously to an ADS device. | |
|
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. | |
|
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. | |
|
Write the value of an Anytype (Primitive type) asynchronously. | |
|
WriteAnyAsync(UInt32, UInt32, Object, .Int32., CancellationToken) |
Write the value of an Anytype (Primitive type) asynchronously. |
|
WriteAnyStringAsync(String, String, Int32, Encoding, CancellationToken) |
Writes the string (Potentially unsafe!) |
|
WriteAnyStringAsync(UInt32, String, Int32, Encoding, CancellationToken) |
Writes the string (Potentially unsafe!) |
|
Writes the value data asynchronously that is represented by the writeBuffer to the symbol specified by the variableHandle. | |
|
Triggers a write call at the specified IndexGroup/IndexOffset asynchronously. | |
|
WriteAsync(UInt32, UInt32, ReadOnlyMemory.Byte., CancellationToken) |
Writes the data / Value asynchronously into the specified writeBuffer. |
|
Changes the ADS status and the device status of an ADS server. | |
|
Changes the ADS status and the device status of an ADS server. | |
|
Changes the ADS status and device status of the ADS server asynchronously. | |
|
WriteControlAsync(AdsState, UInt16, ReadOnlyMemory.Byte., CancellationToken) |
Writes the state asynchronously |
|
Writes the passed object value to the specified ADS symbol.The parameter type must have the same layout as the ADS symbol. | |
|
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. | |
|
Writes the passed object value to the specified ADS symbol.The parameter type must have the same layout as the ADS symbol. | |
|
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. | |
|
Writes the passed object value to the specified ADS symbol.The parameter type must have the same layout as the ADS symbol. | |
|
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. | |
|
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. | |
|
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 |
---|---|---|
|
Occurs when the ADS device sends a notification to the client. | |
|
Occurs when a exception has occurred during notification management. | |
|
Occurs when the ADS devices sends a notification to the client. | |
|
Occurs when Notification Unregistrations / Invalidates are received from the AdsServer | |
|
Occurs when the ADS state changes. | |
|
Occurs when Notifications are send (bundled notifications) | |
|
Occurs when the symbol version has been changed changes. | |
|
Occurs when the connection state has been changed. | |
|
(Local) Router state changed event. |
Extension Methods
|
Name |
Description |
---|---|---|
|
Overloaded. Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by ConnectionStateExtension.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by ConnectionStateExtension.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadAdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by ConnectionStateExtension.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by ConnectionStateExtension.) | |
|
Overloaded. Gets an observable sequence of AdsStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadDeviceStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadDeviceStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadDeviceStates via Polling. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of ResultReadDeviceStates via Polling. (Defined by AdsClientExtensions.) | |
|
Polls the state of the system service. (Defined by SystemServiceExtension.) | |
|
Polls the system service state asynchronously (Defined by SystemServiceExtension.) | |
|
Overloaded. Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
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.) |
|
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.) |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
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.) |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
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.) |
|
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.) |
|
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.) |
|
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.) |
|
Overloaded. Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
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.) |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol values on time points where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
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.) |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol values on time points where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol as value sequence of object values with a specified period time. (Defined by AnyTypeExtensions.) | |
|
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.) |
|
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.) |
|
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.) |
|
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.) |
|
Overloaded. Polls the symbol values on timepoints where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Overloaded. Polls the symbol values on time points where the polling observable streams data / triggers (Defined by AnyTypeExtensions.) | |
|
Reads the System Service state (AdsSysServState) (Defined by SystemServiceExtension.) | |
|
Reads the System Service state (AdsSysServState) (asynchronous) (Defined by SystemServiceExtension.) | |
|
ReadWithFallback(UInt32, UInt32, Memory.Byte., UInt32, Boolean.) |
Overloaded. Ads Read with fallback. (Defined by AdsClientExtensions.) |
|
ReadWithFallback(UInt32, UInt32, UInt32, Memory.Byte., Func.ResultRead, Boolean., Boolean.) |
Overloaded. Ads Read with Fallback. (Defined by AdsClientExtensions.) |
|
ReadWithFallbackAsync(UInt32, UInt32, UInt32, Memory.Byte., CancellationToken) |
Overloaded. Ads Read with fallback as an asynchronous operation. (Defined by AdsClientExtensions.) |
|
Overloaded. Ads Read with fallback as an asynchronous operation. (Defined by AdsClientExtensions.) | |
|
Overloaded. Repeated AdsRead. (Defined by AdsClientExtensions.) | |
|
RepeatedRead(UInt32, UInt32, Memory.Byte., Int32, TimeSpan, Func.ResultRead, Boolean.) |
Overloaded. Repeated AdsRead. (Defined by AdsClientExtensions.) |
|
RepeatedReadAsync(UInt32, UInt32, Memory.Byte., Int32, TimeSpan, CancellationToken) |
Overloaded. Repeated AdsRead as an asynchronous operation. (Defined by AdsClientExtensions.) |
|
Overloaded. Repeated AdsRead as an asynchronous operation. (Defined by AdsClientExtensions.) | |
|
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.) | |
|
Sets an AdsState/AdsStateCommand to an AdsServer and waits until the StateChange finishes. (Defined by ConnectionStateExtension.) | |
|
Sets an AdsState/AdsStateCommand to an AdsServer and waits until the StateChange finishes. (Defined by ConnectionStateExtension.) | |
|
Waits until the Restart is detected on the client (SystemService, Port 10000) (Defined by SystemServiceExtension.) | |
|
Waits until the SystemService Restart is detectd on the client (SystemService, Port 10000) (asynchronously) (Defined by SystemServiceExtension.) | |
|
Gets an observable sequence of AdsStates. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of Notifications. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of Notification objects. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of Notification objects. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of SymbolValueNotifications. (Defined by AdsClientExtensions.) | |
|
Overloaded. Creates an observable sequence of values that are created by ADS Notifications. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Creates an observable sequence of values that are created by ADS Notifications. (Defined by AnyTypeExtensions.) | |
|
Overloaded. Gets an observable sequence of SymbolVersion changed counts. (Defined by AdsClientExtensions.) | |
|
Overloaded. Gets an observable sequence of SymbolVersion changed counts. (Defined by AdsClientExtensions.) | |
|
Observable sequence of Values driven by ADS Notifications on the specified symbol. (Defined by ValueSymbolExtensions.) | |
|
Overloaded. Writes the sequence of values to the symbol specified by the instance path. (Defined by AnyTypeExtensions.) | |
|
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[] { });
}
}
}
}