/// <summary> /// 写入数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param>; private async void btnWriteDataItem_Click(object sender, RoutedEventArgs e) { string message = null; if (!opcUaClientHelper.IsConnected) { message = DateTime.Now.ToString(dateString) + "请先连接服务器" + System.Environment.NewLine; asyncUpMessage(message); return; } OpcUaDataItem opcUaDataItem = null; OpcUaStatusCodes opcUaStatusCodes; if (Equals(null, opcUaClientHelper.OpcUaDataItems) || opcUaClientHelper.OpcUaDataItems.Count < 1) { message = DateTime.Now.ToString(dateString) + "没有数据点" + System.Environment.NewLine; } else { opcUaDataItem = opcUaClientHelper.OpcUaDataItems.FirstOrDefault().Clone() as OpcUaDataItem; //bool newValue = (DateTime.Now.Millisecond % 2) == 0 ? true : false; //bool newValue = !tmpValue; //tmpValue = newValue; //System.Diagnostics.Debug.Print(tmpValue.ToString()); opcUaStatusCodes = await opcUaClientHelper.Write(opcUaDataItem, 11); message = DateTime.Now.ToString(dateString) + "写入完成 " + opcUaStatusCodes + " " + (opcUaDataItem == null ? " " : opcUaDataItem.ToString()) + System.Environment.NewLine; } asyncUpMessage(message); }
//OpcDataItem tm = new OpcDataItem("test", 1000, "0", "0", OpcResult.Unknow); private void upOpcDataItem(OpcUaDataItem opcDataItem) { //this.txtb.Text = "(" + opcDataItem.Count(a => a.Quality == OpcResult.S_OK) + "/" + opcDataItem.Count() + ")"; //System.IO.File.AppendAllText("log.log", message); //gvOpcDataItems.ItemsSource = null; //gvOpcDataItems.ItemsSource = opcDataItem; //this.txtb.Text = "(" + opcDataItem.Count(a => a.Quality == OpcResult.S_OK) + "/" + opcDataItem.Count() + ")"; //this.Dispatcher.BeginInvoke ); this.Dispatcher.Invoke(new Action(() => { //dataGridDataSource //var v = dataGridDataSource.First(a => a.Name == opcDataItem.Name) ; // v = opcDataItem; //dataGridDataSource.Add(opcDataItem); //dataGridDataSource.Remove(opcDataItem); //var v = dataGridDataSource.FirstOrDefault(a => a.Name == opcDataItem.Name); //v = opcDataItem; //gvOpcDataItems.ItemsSource = null; //gvOpcDataItems.ItemsSource = dataGridDataSource; this.txtb.Text = "(" + dataGridDataSource.Count(a => a.OpcUaStatusCodes == OpcUaStatusCodes.Good) + "/" + dataGridDataSource.Count() + ")"; })); }