Exemplo n.º 1
0
 public PIDNodeView(stPIDNode node, ModMaster master)
 {
     InitializeComponent();
     _node = node;
     _node.setDriver(master);
     lblName.Text = _node.name;
 }
Exemplo n.º 2
0
        private void getNodeListByXml()
        {
            XmlDocument xmldoc = new XmlDocument();

            try
            {
                xmldoc.Load("nodeList.xml");
                XmlNode root      = xmldoc.FirstChild;
                XmlNode pidNodes  = null;
                XmlNode commNodes = null;
                foreach (XmlNode item in root.ChildNodes)
                {
                    switch (item.Name)
                    {
                    case "PIDNode":
                        pidNodes = item;
                        break;

                    case "CommNode":
                        commNodes = item;
                        break;
                    }
                }
                int i = 0;
                foreach (XmlNode item in commNodes.ChildNodes)
                {
                    //是否可用16进制表示
                    ushort address = Convert.ToUInt16(item.Attributes["add"].Value, 16);
                    string name    = $"{item.Attributes["name"].Value}:{item.Attributes["add"].Value}";
                    short.TryParse(item.Attributes["add"].Value, out short initValue);

                    stNode node = new stNode(address, name, initValue);
                    NodeViews.Add(new ModbusNodeView(node, _master));
                    NodeViews[i].Location = new System.Drawing.Point(30, 200 + i * 30);
                    this.Controls.Add(NodeViews[i]);
                    i++;
                }
                i = 0;
                foreach (XmlNode item in pidNodes.ChildNodes)
                {
                    //是否可用16进制表示
                    ushort address = Convert.ToUInt16(item.Attributes["add"].Value, 16);
                    string name    = $"{item.Attributes["name"].Value}:{item.Attributes["add"].Value}";
                    short.TryParse(item.Attributes["add"].Value, out short initValue);

                    stPIDNode node = new stPIDNode(address, name, initValue);
                    PIDViews.Add(new PIDNodeView(node, _master));
                    PIDViews[i].Location = new System.Drawing.Point(350, 200 + i * 30);
                    this.Controls.Add(PIDViews[i]);
                    i++;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }