/// <summary> /// 根据传入类型自动检测类型 /// </summary> /// <param name="GroupName"></param> public TagGroup(string GroupName, PLCType pLCType) { plcType = pLCType; T t = default(T); this.GroupName = GroupName; Type type = t.GetType(); if (type == typeof(bool)) { this.dataType = TagDataType.Bool; } else if (type == typeof(short)) { this.dataType = TagDataType.Short; } else if (type == typeof(int)) { this.dataType = TagDataType.Int; } else if (type == typeof(float)) { this.dataType = TagDataType.Float; } else if (type == typeof(string)) { this.dataType = TagDataType.String; } }
public static DeviceEntity ImportFromXmlNode( ProductionLineEntity line, XmlNode node, PLCType plcType, PLCEntity plcEntity) { DeviceEntity rlt = null; if (node.Name.ToUpper() != "DEVICE") { return(rlt); } rlt = new DeviceEntity(line) { Name = XMLHelper.GetAttributeStringValue(node, "Name", ""), PLCType = plcType, DBType = (SiemensRegisterType)Enum.Parse( typeof(SiemensRegisterType), XMLHelper.GetAttributeStringValue(node, "DBType", "DB")), DBNumber = XMLHelper.GetAttributeIntValue(node, "DBNumber", 0), CycleReadMode = (CycleReadMode)Enum.Parse( typeof(CycleReadMode), XMLHelper.GetAttributeStringValue(node, "CycleReadBlock", "ControlBlock")), T133LeafID = XMLHelper.GetAttributeIntValue(node, "T133LeafID", 0), T216LeafID = XMLHelper.GetAttributeIntValue(node, "T216LeafID", 0), T107LeafID = XMLHelper.GetAttributeIntValue(node, "T107LeafID", 0), SplitterTime = XMLHelper.GetAttributeIntValue(node, "SplitterTime", 100), }; rlt.BelongPLC.IPAddress = plcEntity.IPAddress; rlt.BelongPLC.Rack = plcEntity.Rack; rlt.BelongPLC.Slot = plcEntity.Slot; XmlNode xmlGroup = node.FirstChild; while (xmlGroup != null) { GroupEntity group = GroupEntity.ImportFromXmlNode( rlt, xmlGroup); if (group != null) { rlt.Groups.Add(group); } xmlGroup = xmlGroup.NextSibling; } return(rlt); }
public VarInfo(int id_, uint address_, string name_, string units_, string opcname_, string type_) { this.id = id_; this.address = address_; this.name = name_; this.units = units_; this.opcname = opcname_; switch (type_) { case "Bool": this.type = PLCType.Bool; break; case "Int8": this.type = PLCType.Int8; break; case "Int16": this.type = PLCType.Int16; break; case "Int32": this.type = PLCType.Int32; break; case "Float": this.type = PLCType.Float; break; case "Word": this.type = PLCType.World; break; default: this.type = PLCType.Int16; break; } }
public XmlNode GenerateXmlNode() { XmlDocument xml = new XmlDocument(); XmlNode node = xml.CreateElement("Device"); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "Name", Name)); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T133LeafID", T133LeafID.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T216LeafID", T216LeafID.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "T107LeafID", T107LeafID.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "PLCType", PLCType.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBType", DBType.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "DBNumber", DBNumber.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "CycleReadMode", CycleReadMode.ToString())); node.Attributes.Append(XMLHelper.CreateAttribute(xml, "SplitterTime", SplitterTime.ToString())); node.AppendChild(xml.ImportNode(BelongPLC.GenerateXmlNode(), true)); foreach (GroupEntity group in Groups) { node.AppendChild(xml.ImportNode(group.GenerateXmlNode(), true)); } return(node); }
public List <DeviceEntity> ImportDevice(string path) { List <DeviceEntity> rlt = new List <DeviceEntity>(); if (path == "") { return(rlt); } XmlDocument xml = new XmlDocument(); try { xml.Load(path); } catch (Exception error) { throw new Exception( $"解析[{Path.GetFileName(path)}]时出错:[{error.Message}]"); } XmlNode root = xml.SelectSingleNode("root"); if (root == null) { throw new Exception("配置文件中没有 root 根节点"); } PLCType plcType = PLCType.SIEMENS; XmlNode plcNode = root.FirstChild; while (plcNode != null) { if (plcNode.Name.ToUpper() == "SIEMENSPLC") { plcType = PLCType.SIEMENS; PLCEntity plcEntity = new PLCEntity() { IPAddress = XMLHelper.GetAttributeStringValue(plcNode, "IPAddress", "127.0.0.1"), Rack = XMLHelper.GetAttributeIntValue(plcNode, "Rack", 0), Slot = XMLHelper.GetAttributeIntValue(plcNode, "Slot", 0), }; XmlNode deviceNode = plcNode.FirstChild; while (deviceNode != null) { DeviceEntity device = DeviceEntity.ImportFromXmlNode( this, deviceNode, plcType, plcEntity); if (device != null) { Devices.Add(device, _addToWholeEntityQueueHandler); rlt.Add(device); } deviceNode = deviceNode.NextSibling; } } plcNode = plcNode.NextSibling; } return(rlt); }
/// <summary> /// 标签地址连续性判断 /// </summary> /// <returns>地址连续返回True,否则返回False</returns> public static AddrOffset TagContinuousCheck <T>(Tag <T> previousTag, Tag <T> currentTag, PLCType plcType) { AddrOffset addrOffset = new AddrOffset(true, 1); switch (plcType) { case PLCType.Simens1200: case PLCType.Simens1500: case PLCType.Simens300: case PLCType.Simens200Smart: return(SimimensTagContinuousCheck(previousTag, currentTag)); case PLCType.Omron: case PLCType.Fx: return(OmronFxTagContinuousCheck(previousTag, currentTag)); case PLCType.Modbus: return(ModbusContinuousCheck(previousTag, currentTag)); } return(addrOffset); }