Access Data via Symbolic path
The Read/Write Access by symbol path solves the issue of directly accessing the process image. With specifying the access path to the symbol, the symbol address can be found by a binary search (internally) and reading / writing symbols is independent of the location within the process image.
This access method can only be used, when the ADS device is supporting symbolic information like the TwinCAT PLC.
Because its indirect access, the performance is slightly worse than the direct access via IndexGroup/IndexOffset. However there are internal optimizations to cache handles to the already used symbols to accelerate repeated access.
Asynchronous access
Access symbolic data by instance/symbol path
using (AdsClient client = new AdsClient())
{
CancellationToken cancel = CancellationToken.None;
uint valueToRead = 0;
uint valueToWrite = 42;
client.Connect(AmsNetId.Local, 851);
ResultWrite resultWrite = await client.WriteValueAsync("MAIN.nCounter", valueToWrite, cancel);
ResultValue<uint> resultRead = await client.ReadValueAsync<uint>("MAIN.nCounter",cancel);
if (resultRead.Succeeded)
valueToRead = resultRead.Value;
}
Synchronous access
Access symbolic data by instance/symbol path
using (AdsClient client = new AdsClient())
{
uint valueToRead = 0;
uint valueToWrite = 42;
client.Connect(AmsNetId.Local, 851);
client.WriteValue("MAIN.nCounter", valueToWrite);
valueToRead = (uint)client.ReadValue("MAIN.nCounter", typeof(uint));
}