void tbox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { detail.Visibility = Visibility.Visible; Control box = sender as Control; Node node = box.Tag as Node; Point p = box.TranslatePoint(new Point(), grid_content); Point p0 = box.TranslatePoint(new Point(), this); if (p0.Y <= this.Height / 2) { detail.Margin = new Thickness(0, p.Y + rowHeight * 0.8, 0, 0); detail.img_top.Margin = new Thickness(p.X + box.ActualWidth / 2 - detail.img_top.Width / 2, 0, 0, 0); detail.img_top.Visibility = Visibility.Visible; detail.img_bottom.Visibility = Visibility.Hidden; } else { detail.Margin = new Thickness(0, p.Y - detail.Height, 0, 0); detail.img_bottom.Margin = new Thickness(p.X + box.ActualWidth / 2 - detail.img_bottom.Width / 2, 0, 0, 0); detail.img_bottom.Visibility = Visibility.Visible; detail.img_top.Visibility = Visibility.Hidden; } if (node.ShowType == 11) { read(node.Address, int.Parse(node.Extra), true); } else if (node.ShowType == 13) { detail.showOutput(box as TextBox); } else { detail.showSwitch(node.Extra, Convert.ToInt32(AutoBox.getText(box), 16), box); } }
void box_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox cBox = sender as ComboBox; Node node = box.Tag as Node; List <string> items = node.Extra.Split('_').ToList(); int item = int.Parse(items[2 * cBox.SelectedIndex]); string selectedValue = Convert.ToChar(item).ToString(); string value = null; if (cBox.Name == "output1") { value = Convert.ToChar(item) + " " + AutoBox.getText(box)[2]; } else { value = AutoBox.getText(box)[0] + " " + Convert.ToChar(item); } AutoBox.setText(box, value); }
private void btn_write_Click(object sender, RoutedEventArgs e) { Control box = btn_write.Tag as Control; Node node = box.Tag as Node; byte[] snd = new byte[9]; snd[0] = comAddress; snd[1] = 0x10; snd[2] = (byte)(node.Address / 256); snd[3] = (byte)(node.Address % 256); snd[5] = 0x1; snd[6] = 0x2; byte[] data = (byte[])typeof(ComConverter).GetMethod("CvtW" + node.ShowType).Invoke(cvt, new object[] { AutoBox.getText(box), node.Extra }); if (data == null) { lbl_msg.Content = string.Format("修改:0x{0:X4} {1} 【失败】——格式出错", node.Address, node.Name); } else { data.CopyTo(snd, 7); byte[] rcv = com.Execute(snd); if (rcv == null || rcv.Length != 1) { lbl_msg.Content = string.Format("修改:0x{0:X4} {1} 【失败】{2}", node.Address, node.Name, DateTime.Now.ToLongTimeString()); } else { lbl_msg.Content = string.Format("修改:0x{0:X4} {1} 【成功】{2}", node.Address, node.Name, DateTime.Now.ToLongTimeString()); read(node.Address, 1); } } }
private void read(int address, int length, bool readArray = false, int offset = 0) { Task.Factory.StartNew(() => { lock (threadLock) { int realAddr = address + offset * length; byte[] snd = new byte[6]; snd[0] = comAddress; snd[1] = 0x3; snd[2] = (byte)(realAddr / 256); snd[3] = (byte)(realAddr % 256); snd[4] = (byte)(length / 256); snd[5] = (byte)(length % 256); byte[] rcv = com.Execute(snd); this.Dispatcher.Invoke(new Action(() => { if (rcv.Length == length * 2) { lbl_msg.Content = string.Format("读取:{0:X4},位数:{1}【成功】{2}", address, length, DateTime.Now.ToLongTimeString()); if (readArray) { Control tbox = Tools.GetChild <Control>(grid_content, "Box" + address); Node node = tbox.Tag as Node; int[] data = (int[])typeof(ComConverter).GetMethod("CvtR" + node.ShowType).Invoke(cvt, new object[] { rcv, node.Extra }); detail.showChart(data); } else { for (int i = 0; i < length; i++) { Control box = Tools.GetChild <Control>(grid_content, "Box" + (address + i)); byte[] source = new byte[] { rcv[2 * i], rcv[2 * i + 1] }; Node node = box.Tag as Node; int nResult = source[0] * 256 + source[1]; string result = typeof(ComConverter).GetMethod("CvtR" + node.ShowType).Invoke(cvt, new object[] { source, node.Extra }).ToString(); AutoBox.setText(box, result); if (node.Influences != null) { foreach (Influence inf in node.Influences) { inf.executeInfluence(grid_content, nResult, AutoBox.getText(box)); } } //处理一些没有规律特殊的节点 if (node.Address == 0x7007 || node.Address == 0x6007) { Control box0 = Tools.GetChild <Control>(grid_content, "Box" + (node.Address - 7)); if (AutoBox.getText(box0) == "相序") { AutoBox.setText(box, nResult == 0 ? "逆序" : "正序"); } } else if (node.Address == 0x8001) { Control box0x8000 = Tools.GetChild <Control>(grid_content, "Box" + (0x8000)); string value = AutoBox.getText(box0x8000); if (value == "存储器故障") { AutoBox.setText(box, string.Format("0x{0:X4}", nResult)); } else if (value == "相序") { AutoBox.setText(box, nResult == 0 ? "逆序" : "正序"); } } } } } else { lbl_msg.Content = string.Format("读取:{0:X4},位数:{1}【失败】{2}", address, length, DateTime.Now.ToLongTimeString()); } })); } }); }