private void BtnOperate_Click(object sender, RoutedEventArgs e) { if (!_OpcClient.IsConnected) { Msg("请先连接服务器"); return; } string serverId = TbTagServerId.Text.Trim(); string writeValue = LbWriteValue.Text.Trim(); if (string.IsNullOrEmpty(serverId)) { Msg("请输入Tag ServerID"); TbTagServerId.Focus(); return; } Button btn = sender as Button; TagItem tagItem = new TagItem() { ServerId = serverId, ValueToWrite = writeValue, NameSpace = "2", CallBack = this.TagCallBack }; switch (btn?.Tag?.ToString()) { case "1": //同步读 TagItem item = _OpcClient.Read(tagItem); LbReadValue.Content = item.Value; break; case "2": //异步读 _OpcClient.AsyncRead(tagItem); break; case "3": //同步写 _OpcClient.Write(tagItem); break; case "4": //异步写 _OpcClient.AsyncWrite(tagItem); break; case "5": //添加订阅 _OpcClient.AddSubscription(tagItem); break; } }