Пример #1
0
        void toggleSwitch_Click(object sender, RoutedEventArgs e)
        {
            WPFSpark.ToggleSwitch ts = sender as WPFSpark.ToggleSwitch;
            int index = int.Parse(ts.Tag.ToString());
            int bit   = ts.IsChecked == true ? 0 : 1;

            switchData = Tools.SetBit(switchData, index, bit);
            AutoBox.setText(box, string.Format("0x{0:X4}", switchData));
        }
Пример #2
0
        private void addBox(string name, char value, string extra, int column)
        {
            var    items = extra.Split('_').ToList();
            string item  = Convert.ToInt32(value).ToString();
            int    index = items.IndexOf(item);

            item = index < 0 ? string.Empty : items[index + 1];
            ComboBox box = new ComboBox();

            box.Name              = name;
            box.SelectionChanged += box_SelectionChanged;
            box.ItemsSource       = items.Where((t, i) => i % 2 == 1).ToList();
            AutoBox.setText(box, item);
            box.Height = rowHeight;
            System.Windows.Controls.Grid.SetColumn(box, column);
            System.Windows.Controls.Grid.SetColumnSpan(box, 2);
            mySwitch.Children.Add(box);
        }
Пример #3
0
        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);
        }
Пример #4
0
 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());
                 }
             }));
         }
     });
 }