Ejemplo n.º 1
0
        public static async Task <DateTime> GetTimeAsync(AmsNetId target, CancellationToken cancel)
        {
            var buffer = new Memory <byte>(new byte[16]);

            using (AdsClient client = new AdsClient())
            {
                await client.ConnectAsync(new AmsAddress(target, AmsPort.SystemService), cancel);

                var result = await client.ReadAsync(400, 1, buffer, cancel);

                result.ThrowOnError();
            }

            return(DateTime.FromBinary(BitConverter.ToInt64(buffer.ToArray(), 0)));
        }