Ejemplo n.º 1
0
        public static async Task SetLocalTimeAsync(AmsNetId target, DateTime time, CancellationToken cancel)
        {
            var buffer = new ReadOnlyMemory <byte>(BitConverter.GetBytes(time.Ticks));

            using (AdsClient client = new AdsClient())
            {
                client.Connect(new AmsAddress(target, AmsPort.SystemService));
                var result = await client.WriteAsync(400, 1, buffer, cancel);

                result.ThrowOnError();
            }
        }
        public static async Task SetValueAsync(AmsNetId target, string subKey, string valueName, RegistryValueType type, IEnumerable <byte> data)
        {
            using (AdsClient client = new AdsClient())
            {
                client.Connect(new AmsAddress(target, AmsPort.SystemService));

                var writeBuffer = new List <byte>();

                writeBuffer.AddRange(System.Text.Encoding.UTF8.GetBytes(subKey));
                writeBuffer.Add(new byte()); // End delimiter
                writeBuffer.AddRange(System.Text.Encoding.UTF8.GetBytes(valueName));
                writeBuffer.Add(new byte());
                writeBuffer.AddRange(data);

                var result = await client.WriteAsync(200, 0, new ReadOnlyMemory <byte>(writeBuffer.ToArray()), CancellationToken.None);

                result.ThrowOnError();
            }
        }
Ejemplo n.º 3
0
        public static async Task StartProcessAsync(AmsNetId target, string path, string directory, string args, CancellationToken cancel)
        {
            byte[] Data = new byte[777];

            BitConverter.GetBytes(path.Length).CopyTo(Data, 0);
            BitConverter.GetBytes(directory.Length).CopyTo(Data, 4);
            BitConverter.GetBytes(args.Length).CopyTo(Data, 8);

            System.Text.Encoding.ASCII.GetBytes(path).CopyTo(Data, 12);
            System.Text.Encoding.ASCII.GetBytes(directory).CopyTo(Data, 12 + path.Length + 1);
            System.Text.Encoding.ASCII.GetBytes(args).CopyTo(Data, 12 + path.Length + 1 + directory.Length + 1);

            ReadOnlyMemory <byte> buffer = new ReadOnlyMemory <byte>(Data);

            using (AdsClient client = new AdsClient())
            {
                client.Connect(new AmsAddress(target, AmsPort.SystemService));
                var res = await client.WriteAsync(500, 0, buffer, cancel);

                res.ThrowOnError();
            }
        }