Ejemplo n.º 1
0
        private void userButton1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text.Length > 6)
            {
                MessageBox.Show("密码最大长度为6");
                return;
            }

            if (!int.TryParse(textBox4.Text, out int port))
            {
                MessageBox.Show("端口号输入失败!");
                return;
            }


            AlienNode = new AlienNode( )
            {
                Name        = textBox1.Text,
                Description = textBox2.Text,
                Password    = textBox3.Text,
                Port        = port
            };

            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 2
0
        private void AddNodeClass(NodeState parent, XElement nodeClass, IList <IReference> references)
        {
            foreach (var xmlNode in nodeClass.Elements())
            {
                if (xmlNode.Name == "NodeClass")
                {
                    Configuration.NodeClass nClass = new Configuration.NodeClass( );
                    nClass.LoadByXmlElement(xmlNode);

                    FolderState son;
                    if (parent == null)
                    {
                        son             = CreateFolder(null, nClass.Name);
                        son.Description = nClass.Description;
                        son.AddReference(ReferenceTypes.Organizes, true, ObjectIds.ObjectsFolder);
                        references.Add(new NodeStateReference(ReferenceTypes.Organizes, false, son.NodeId));
                        son.EventNotifier = EventNotifiers.SubscribeToEvents;
                        AddRootNotifier(son);


                        AddNodeClass(son, xmlNode, references);
                        AddPredefinedNode(SystemContext, son);
                    }
                    else
                    {
                        son = CreateFolder(parent, nClass.Name, nClass.Description);
                        AddNodeClass(son, xmlNode, references);
                    }
                }
                else if (xmlNode.Name == "DeviceNode")
                {
                    AddDeviceCore(parent, xmlNode);
                }
                else if (xmlNode.Name == "AlienNode")
                {
                    AlienNode alienNode = new AlienNode( );
                    alienNode.LoadByXmlElement(xmlNode);
                    AddNetworkAlien(alienNode);

                    FolderState son = CreateFolder(parent, alienNode.Name, alienNode.Description);
                    AddNodeClass(son, xmlNode, references);
                }
                else if (xmlNode.Name == "ModbusServer")
                {
                    NodeModbusServer serverNode = new NodeModbusServer( );
                    serverNode.LoadByXmlElement(xmlNode);
                    AddModbusTcpServer(serverNode);

                    FolderState son = CreateFolder(parent, serverNode.Name, serverNode.Description);
                    AddNodeClass(son, xmlNode, references);
                }
            }
        }
Ejemplo n.º 3
0
        private void AddNetworkAlien(AlienNode alienNode)
        {
            NetworkAlienClient networkAlien = new NetworkAlienClient( );

            networkAlien.LogNet = Util.LogNet;
            if (!string.IsNullOrEmpty(alienNode.Password))
            {
                networkAlien.SetPassword(Encoding.ASCII.GetBytes(alienNode.Password));
            }
            networkAlien.Port = alienNode.Port;
            networkAlien.OnClientConnected += NetworkAlien_OnClientConnected;
            this.networkAliens.Add(networkAlien);
        }
Ejemplo n.º 4
0
        public ModbusAlienCore(XElement element)
        {
            if (element.Name != "AlienNode")
            {
                return;
            }

            // 解析出服务器的属性配置
            AlienNode alienNode = new AlienNode( );

            alienNode.LoadByXmlElement(element);

            // 解析所有的客户端
            List <NodeModbusTcpAline> modbusTcpAlines = new List <NodeModbusTcpAline>( );

            foreach (var item in element.Elements())
            {
                NodeModbusTcpAline tcpAline = new NodeModbusTcpAline( );
                tcpAline.LoadByXmlElement(item);
                modbusTcpAlines.Add(tcpAline);
            }
        }
Ejemplo n.º 5
0
 public FormAlienNode(AlienNode alienNode = null)
 {
     InitializeComponent( );
     AlienNode = alienNode ?? new AlienNode();
     Icon      = Util.GetWinformICon( );
 }
Ejemplo n.º 6
0
        private void TreeNodeRender(TreeNode treeNode, XElement element)
        {
            foreach (XElement item in element.Elements( ))
            {
                if (item.Name == "NodeClass")
                {
                    TreeNode node = new TreeNode(item.Attribute("Name").Value);
                    node.ImageKey         = "Class_489";
                    node.SelectedImageKey = "Class_489";

                    NodeClass nodeClass = new NodeClass( );
                    nodeClass.LoadByXmlElement(item);
                    node.Tag = nodeClass;
                    treeNode.Nodes.Add(node);

                    TreeNodeRender(node, item);
                }
                else if (item.Name == "DeviceNode")
                {
                    int type = int.Parse(item.Attribute("DeviceType").Value);

                    TreeNode deviceNode = new TreeNode(item.Attribute("Name").Value);
                    if (type == DeviceNode.ModbusTcpClient)
                    {
                        deviceNode.ImageKey         = "Module_648";
                        deviceNode.SelectedImageKey = "Module_648";

                        NodeModbusTcpClient modbusNode = new NodeModbusTcpClient( );
                        modbusNode.LoadByXmlElement(item);
                        deviceNode.Tag = modbusNode;
                    }
                    else if (type == DeviceNode.ModbusTcpAlien)
                    {
                        deviceNode.ImageKey         = "Module_648";
                        deviceNode.SelectedImageKey = "Module_648";

                        NodeModbusTcpAline modbusAlien = new NodeModbusTcpAline( );
                        modbusAlien.LoadByXmlElement(item);
                        deviceNode.Tag = modbusAlien;
                    }
                    else if (type == DeviceNode.MelsecMcQna3E)
                    {
                        deviceNode.ImageKey         = "Enum_582";
                        deviceNode.SelectedImageKey = "Enum_582";

                        NodeMelsecMc node = new NodeMelsecMc( );
                        node.LoadByXmlElement(item);
                        deviceNode.Tag = node;
                    }
                    else if (type == DeviceNode.Siemens)
                    {
                        deviceNode.ImageKey         = "Event_594";
                        deviceNode.SelectedImageKey = "Event_594";

                        NodeSiemens node = new NodeSiemens( );
                        node.LoadByXmlElement(item);
                        deviceNode.Tag = node;
                    }
                    else if (type == DeviceNode.DeviceNone)
                    {
                        deviceNode.ImageKey         = "Method_636";
                        deviceNode.SelectedImageKey = "Method_636";

                        NodeEmpty node = new NodeEmpty( );
                        node.LoadByXmlElement(item);
                        deviceNode.Tag = node;
                    }
                    else if (type == DeviceNode.Omron)
                    {
                        deviceNode.ImageKey         = "HotSpot_10548_color";
                        deviceNode.SelectedImageKey = "HotSpot_10548_color";

                        NodeOmron node = new NodeOmron( );
                        node.LoadByXmlElement(item);
                        deviceNode.Tag = node;
                    }
                    else if (type == DeviceNode.SimplifyNet)
                    {
                        deviceNode.ImageKey         = "FlagRed_16x";
                        deviceNode.SelectedImageKey = "FlagRed_16x";

                        NodeSimplifyNet node = new NodeSimplifyNet( );
                        node.LoadByXmlElement(item);
                        deviceNode.Tag = node;
                    }


                    treeNode.Nodes.Add(deviceNode);
                    foreach (XElement request in item.Elements("DeviceRequest"))
                    {
                        TreeNode nodeRequest = new TreeNode(request.Attribute("Name").Value);
                        nodeRequest.ImageKey         = "usbcontroller";
                        nodeRequest.SelectedImageKey = "usbcontroller";

                        DeviceRequest deviceRequest = new DeviceRequest( );
                        deviceRequest.LoadByXmlElement(request);
                        nodeRequest.Tag = deviceRequest;
                        deviceNode.Nodes.Add(nodeRequest);
                    }
                }
                else if (item.Name == "AlienNode")
                {
                    TreeNode node = new TreeNode(item.Attribute("Name").Value);
                    node.ImageKey         = "server_Local_16xLG";
                    node.SelectedImageKey = "server_Local_16xLG";

                    AlienNode nodeClass = new AlienNode( );
                    nodeClass.LoadByXmlElement(item);
                    node.Tag = nodeClass;
                    treeNode.Nodes.Add(node);

                    TreeNodeRender(node, item);
                }
                else if (item.Name == "ModbusServer")
                {
                    TreeNode node = new TreeNode(item.Attribute("Name").Value);
                    node.ImageKey         = "server_Local_16xLG";
                    node.SelectedImageKey = "server_Local_16xLG";

                    NodeModbusServer nodeClass = new NodeModbusServer( );
                    nodeClass.LoadByXmlElement(item);
                    node.Tag = nodeClass;
                    treeNode.Nodes.Add(node);

                    TreeNodeRender(node, item);
                }
            }
        }