Пример #1
0
        private async void UpdateSwitch_Click(object sender, RoutedEventArgs e)
        {
            PlcClient c = this.FirstPlcClient;

            if (c == null)
            {
                this.LogMessage("目前没有 PLC 连接。");
                return;
            }

            this.LogMessage("Sending UpdateSwitchRequest");
            this.SendingDocument.Blocks.Clear();
            this.ReceivingDocument.Blocks.Clear();
            try
            {
                Switch response = await c.UpdateSwitchAsync(
                    new UpdateSwitchRequest
                {
                    Switch = new Switch
                    {
                        HeaterAutoOn = true,
                    },
                    UpdateMask = FieldMask.FromString <Switch>("heater_auto_on"),
                },
                    deadline : DateTime.Now.AddSeconds(30))
                                  .ConfigureAwait(true);

                this.LogMessage("Received UpdateSwitchResponse " + response.ToString());
            }
            catch (RpcException ex)
            {
                this.LogMessage("Failed to receive UpdateSwitchResponse " + ex.ToString());
            }
        }