private static void GetACCESSRIGHTS(OpcUaModelCompiler.VariableDesign var, Opc.Da.ItemProperty itemProperty) { if ((itemProperty == null) || (itemProperty.Value == null)) { return; } var.AccessLevelSpecified = true; switch (((Opc.Da.accessRights)itemProperty.Value)) { case Opc.Da.accessRights.readWritable: var.AccessLevel = OpcUaModelCompiler.AccessLevel.ReadWrite; break; case Opc.Da.accessRights.readable: var.AccessLevel = OpcUaModelCompiler.AccessLevel.Read; break; case Opc.Da.accessRights.writable: var.AccessLevel = OpcUaModelCompiler.AccessLevel.Write; break; default: var.AccessLevelSpecified = false; break; } }
private static void GetEUTYPE(OpcUaModelCompiler.VariableDesign var, SortedDictionary <int, Opc.Da.ItemProperty> prprts) { if (!prprts.ContainsKey(Opc.Da.Property.EUTYPE.Code)) { return; } Opc.Da.ItemProperty eut = prprts[Opc.Da.Property.EUTYPE.Code]; if (eut.Value == null) { return; } switch ((Opc.Da.euType)eut.Value) { case Opc.Da.euType.analog: { var.TypeDefinition = GetAnalogItemType(); Opc.Da.ItemProperty higheu = null; Opc.Da.ItemProperty loweu = null; if (prprts.ContainsKey(Opc.Da.Property.HIGHEU.Code)) { higheu = prprts[Opc.Da.Property.HIGHEU.Code]; } if (prprts.ContainsKey(Opc.Da.Property.LOWEU.Code)) { loweu = prprts[Opc.Da.Property.LOWEU.Code]; } if (higheu != null && loweu != null) { OpcUaModelCompiler.PropertyDesign prop = new OpcUaModelCompiler.PropertyDesign() { SymbolicName = CreateXmlQualifiedName(BrowseNames.EURange), DataType = CreateXmlQualifiedName(BrowseNames.Range), DefaultValue = CAS.UA.Common.Types.Range.CreateRange(higheu, loweu).XmlElement, ValueRank = OpcUaModelCompiler.ValueRank.Scalar, AccessLevel = OpcUaModelCompiler.AccessLevel.Read }; var.Children = new OpcUaModelCompiler.ListOfChildren() { Items = new OpcUaModelCompiler.InstanceDesign[] { prop } }; } break; } case Opc.Da.euType.enumerated: var.TypeDefinition = GetMultiStateDiscreteType(); break; case Opc.Da.euType.noEnum: var.TypeDefinition = GetTwoStateDiscreteType(); break; default: break; } }
private static void GetDATATYPE(OpcUaModelCompiler.VariableDesign var, Opc.Da.ItemProperty prprty) { if (prprty == null || prprty.Value == null) { return; } Type vt = (Type)prprty.Value; NodeId id = Opc.Ua.TypeInfo.GetDataTypeId(vt); if (id == null) { return; } Debug.Assert(id.IdType == IdType.Numeric); BuiltInType bit = TypeInfo.GetBuiltInType(id); switch (bit) { case BuiltInType.Boolean: case BuiltInType.Byte: case BuiltInType.ByteString: case BuiltInType.DataValue: case BuiltInType.DateTime: case BuiltInType.Double: case BuiltInType.Float: case BuiltInType.Int16: case BuiltInType.Int32: case BuiltInType.Int64: case BuiltInType.SByte: case BuiltInType.String: case BuiltInType.UInt16: case BuiltInType.UInt32: case BuiltInType.UInt64: { string sn = Enum.GetName(typeof(BuiltInType), TypeInfo.GetBuiltInType(id)); var.DataType = CreateXmlQualifiedName(sn); break; } case BuiltInType.UInteger: case BuiltInType.Integer: case BuiltInType.LocalizedText: case BuiltInType.Enumeration: case BuiltInType.ExpandedNodeId: case BuiltInType.ExtensionObject: case BuiltInType.Guid: case BuiltInType.NodeId: case BuiltInType.Null: case BuiltInType.Number: case BuiltInType.QualifiedName: case BuiltInType.StatusCode: case BuiltInType.Variant: case BuiltInType.XmlElement: case BuiltInType.DiagnosticInfo: default: break; } if (vt.IsArray) { var.ValueRank = OpcUaModelCompiler.ValueRank.OneOrMoreDimensions; } }
private static void ImportTag ( CASLibOPCAddressSpace.AddressSpaceDataBase.TagsTableRow parentItem, string targetNamespace, UniqueName uniqueName, XmlQualifiedName parentObject, List <OpcUaModelCompiler.NodeDesign> nodes, List <OpcUaModelCompiler.InstanceDesign> parentChildren ) { Opc.Da.BrowseElement pbe = parentItem.GetBrowseElement(); if (pbe.IsItem) { OpcUaModelCompiler.VariableDesign var = new OpcUaModelCompiler.VariableDesign() { SymbolicName = new XmlQualifiedName(uniqueName.GetUniqueName(pbe.Name), targetNamespace), DisplayName = new OpcUaModelCompiler.LocalizedText() { Value = pbe.Name }, DataType = GetBaseDataType(), TypeDefinition = GetBaseDataVariableType(), Description = new OpcUaModelCompiler.LocalizedText() { Value = pbe.ItemName }, AccessLevel = OpcUaModelCompiler.AccessLevel.ReadWrite, AccessLevelSpecified = true, ValueRank = OpcUaModelCompiler.ValueRank.Scalar, ValueRankSpecified = true, WriteAccess = 0 }; parentChildren.Add(var); SortedDictionary <int, Opc.Da.ItemProperty> prprts = new SortedDictionary <int, Opc.Da.ItemProperty>(); foreach (Opc.Da.ItemProperty item in pbe.Properties) { prprts.Add(item.ID.Code, item); } if (prprts.ContainsKey(Opc.Da.Property.DATATYPE.Code)) { GetDATATYPE(var, prprts[Opc.Da.Property.DATATYPE.Code]); } GetEUTYPE(var, prprts); if (prprts.ContainsKey(Opc.Da.Property.ACCESSRIGHTS.Code)) { GetACCESSRIGHTS(var, prprts[Opc.Da.Property.ACCESSRIGHTS.Code]); } } else { OpcUaModelCompiler.ObjectDesign sf = CreateFolder(new XmlQualifiedName(uniqueName.GetUniqueName(pbe.Name), targetNamespace), pbe.ItemName, pbe.Name); nodes.Add(sf); List <OpcUaModelCompiler.InstanceDesign> myChildren = new List <OpcUaModelCompiler.InstanceDesign>(); foreach (CASLibOPCAddressSpace.AddressSpaceDataBase.TagsTableRow item in parentItem.GetTagsTableRows()) { ImportTag(item, targetNamespace, uniqueName, sf.SymbolicName, nodes, myChildren); } sf.Children = new OpcUaModelCompiler.ListOfChildren() { Items = myChildren.ToArray() }; sf.References = new OpcUaModelCompiler.Reference[] { new OpcUaModelCompiler.Reference() { IsInverse = true, ReferenceType = CreateXmlQualifiedName(Opc.Ua.BrowseNames.Organizes), TargetId = parentObject } }; } }