public static async Task <string> QueryValueAsync(AmsNetId target, string subKey, string valueName) { using (AdsClient client = new AdsClient()) { client.Connect(new AmsAddress(target, AmsPort.SystemService)); var readBuffer = new Memory <byte>(new byte[255]); var data = new List <byte>(); data.AddRange(System.Text.Encoding.UTF8.GetBytes(subKey)); data.Add(new byte()); // End delimiter data.AddRange(System.Text.Encoding.UTF8.GetBytes(valueName)); data.Add(new byte()); var writeBuffer = new ReadOnlyMemory <byte>(data.ToArray()); var result = await client.ReadWriteAsync(200, 0, readBuffer, writeBuffer, CancellationToken.None); result.ThrowOnError(); return(System.Text.Encoding.UTF8.GetString(readBuffer.ToArray(), 0, result.ReadBytes)); } }