/// <summary>
        /// 默认的构造方法
        /// </summary>
        /// <param name="element"></param>
        public DeviceModbusTcpAlien(XElement element)
        {
            NodeModbusTcpAline modbusTcpAline = new NodeModbusTcpAline( );

            modbusTcpAline.LoadByXmlElement(element);

            LoadRequest(element);

            modbusTcp = new ModbusTcpNet(string.Empty, 502, modbusTcpAline.Station);
            modbusTcp.AddressStartWithZero = modbusTcpAline.IsAddressStartWithZero;
            modbusTcp.ConnectionId         = modbusTcpAline.DTU;


            ByteTransform = modbusTcp.ByteTransform;
            UniqueId      = modbusTcp.ConnectionId;

            TypeName = "Modbus-Tcp异形设备";
        }
示例#2
0
        /// <summary>
        /// 实例化一个异形的Modbus-tcp的设备对象,从配置信息创建
        /// </summary>
        /// <param name="element">配置信息</param>
        public DeviceModbusTcpAlien(XElement element)
        {
            NodeModbusTcpAline modbusTcpAline = new NodeModbusTcpAline( );

            modbusTcpAline.LoadByXmlElement(element);

            LoadRequest(element);

            modbusTcp = new ModbusTcpNet(string.Empty, 502, modbusTcpAline.Station);
            modbusTcp.AddressStartWithZero = modbusTcpAline.IsAddressStartWithZero;
            modbusTcp.ConnectionId         = modbusTcpAline.DTU;
            modbusTcp.DataFormat           = (HslCommunication.Core.DataFormat)modbusTcpAline.DataFormat;
            modbusTcp.IsStringReverse      = modbusTcpAline.IsStringReverse;


            ByteTransform   = modbusTcp.ByteTransform;
            ReadWriteDevice = modbusTcp;
            UniqueId        = modbusTcp.ConnectionId;

            TypeName = "Modbus-Tcp异形设备";
        }
示例#3
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);
            }
        }
示例#4
0
        private void TreeNodeRender(TreeNode treeNode, XElement element)
        {
            foreach (var item in element.Elements())
            {
                if (item.Name == "NodeClass")
                {
                    var node = new TreeNode(item.Attribute("Name").Value);
                    node.ImageKey         = "Class_489";
                    node.SelectedImageKey = "Class_489";

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

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

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

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

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

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

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

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

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

                    treeNode.Nodes.Add(deviceNode);
                    foreach (var request in item.Elements("DeviceRequest"))
                    {
                        var deviceRequest = new DeviceRequest();
                        deviceRequest.LoadByXmlElement(request);
                        var parseCode = deviceRequest.PraseRegularCode;
                        if (regularkeyValuePairs.ContainsKey(parseCode))
                        {
                            foreach (var regularNodeItem in regularkeyValuePairs[parseCode])
                            {
                                var treeNodeRegular = new TreeNode(regularNodeItem.Name);
                                treeNodeRegular.ImageKey         = "Operator_660";
                                treeNodeRegular.SelectedImageKey = "Operator_660";


                                treeNodeRegular.Tag = regularNodeItem;
                                deviceNode.Nodes.Add(treeNodeRegular);
                            }
                        }
                    }
                }
                else if (item.Name == "ServerNode")
                {
                    var type = int.Parse(item.Attribute("ServerType").Value);

                    if (type == ServerNode.ModbusServer)
                    {
                        var node = new TreeNode(item.Attribute("Name").Value);
                        node.ImageKey         = "server_Local_16xLG";
                        node.SelectedImageKey = "server_Local_16xLG";

                        var nodeClass = new NodeModbusServer();
                        nodeClass.LoadByXmlElement(item);
                        node.Tag = nodeClass;
                        treeNode.Nodes.Add(node);
                    }
                    else if (type == ServerNode.AlienServer)
                    {
                        var node = new TreeNode(item.Attribute("Name").Value);
                        node.ImageKey         = "server_Local_16xLG";
                        node.SelectedImageKey = "server_Local_16xLG";

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

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

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

                    foreach (var regularItemXml in item.Elements("RegularItemNode"))
                    {
                        var treeNodeRegular = new TreeNode(regularItemXml.Attribute("Name").Value);
                        treeNodeRegular.ImageKey         = "Operator_660";
                        treeNodeRegular.SelectedImageKey = "Operator_660";

                        var regularItemNode = new RegularItemNode();
                        regularItemNode.LoadByXmlElement(regularItemXml);
                        treeNodeRegular.Tag = regularItemNode;
                        node.Nodes.Add(treeNodeRegular);
                    }
                }
            }
        }
        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);
                }
            }
        }