private async void Read_Click(object sender, RoutedEventArgs e) { if (EVBComboBox.SelectedItem == null || PdTypeComboBox.SelectedItem == null || TableSelectComboBox.SelectedItem == null) { await this.MsgBox("Please check EVB\\Product\\Table selected item."); return; } try { var instr = (InstrumentModel)EVBComboBox.SelectedItem; var tt = new EVB1_QsfpDD(instr); tt.Open(); //切表 tt.Write(0xA0, 0x7F, this.ConvertHexStringToBytes(((TableDefineModel)TableSelectComboBox.SelectedItem).TableIndex)); //读取数据 var data = tt.Read(0xa0, Convert.ToByte(((TableDefineModel)TableSelectComboBox.SelectedItem).StartAddress, 16), 128); for (var i = 0; i < data.Length; i++) { ItemList[i].Value = data[i].ToString("X2"); ItemList[i].CacheOldData(ItemList[i]); } tt.Close(); } catch (Exception exp) { await this.MsgBox(exp.Message); } }
private async void Write_Click(object sender, RoutedEventArgs e) { if (EVBComboBox.SelectedItem == null || PdTypeComboBox.SelectedItem == null || TableSelectComboBox.SelectedItem == null) { await this.MsgBox("Please check EVB\\Product\\Table selected item."); return; } var instr = (InstrumentModel)EVBComboBox.SelectedItem; var tt = new EVB1_QsfpDD(instr); tt.Open(); //切表 tt.Write(0xA0, 0x7F, this.ConvertHexStringToBytes(((TableDefineModel)TableSelectComboBox.SelectedItem).TableIndex)); var first = true; foreach (var item in ItemList) { byte addr = 0x00; var data = new List <byte>(); //如果是连续变更数据,可以一次性写入 //遇到非连续性数据,则把之前更改过的数据写入 if (item.IsChanged) { if (first) { addr = Convert.ToByte(item.Address, 16); } first = false; data.Add(Convert.ToByte(item.Value, 16)); } if (!item.IsChanged && data.Count > 0) { first = true; try { tt.Write(0xA0, addr, data.ToArray()); } catch (Exception exp) { await this.MsgBox(exp.Message); } } } tt.Close(); }