Access Data via IndexGroup/IndexOffset
Reading/Writing values by Index/Group index offset are the most basic way to access data via ADS. This address combination directly link into the process image of virtual ADS Devices.
As long the process image is static this is unproblematic and a system near access, but if the content is more dynamic and the address changes over time the IndexGroup/IndexOffset can get invalid.
Examples about moving addresses could be:
- Changed Parametrization of IO (and Re-activation)
- The PLC Online change
- New Plc Downloads
In that case other access methods could be advantageous.
Another important point is that the data access is not type safe. The values are read or written to or from byte buffers and the proper marshalling/unmarshalling is the task of the application code.
Example
Access ProcessImage Data by IndexGroup/IndexOffset
using (TcAdsClient client = new TcAdsClient())
{
UInt32 valueToRead = 0;
UInt32 valueToWrite = 42;
client.Connect(AmsNetId.Local, 851);
// Write an UINT32 Value
AdsStream writeStream = new AdsStream(sizeof(uint));
AdsBinaryWriter writer = new AdsBinaryWriter(writeStream);
writer.Write(valueToWrite);
adsClient.Write(0x4020, 0x0, writeStream, 0, 4);
// Read an UINT32 Value
AdsStream readStream = new AdsStream(sizeof(uint));
adsClient.Read(0x4020, 0x0, readStream, 0, 4);
readStream.Position = 0;
AdsBinaryReader reader = new AdsBinaryReader(readStream);
valueToRead = reader.ReadUInt32();
}