/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { base.CreateAddressSpace(externalReferences); // ensure trigger can be found via the server object. IList <IReference> references = null; if (!externalReferences.TryGetValue(Opc.Ua.ObjectIds.ObjectsFolder, out references)) { externalReferences[Opc.Ua.ObjectIds.ObjectsFolder] = references = new List <IReference>(); } FolderState root = CreateFolder(null, "CitiesNodes", "CitiesNodes"); root.AddReference(ReferenceTypes.Organizes, true, Opc.Ua.ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypes.Organizes, false, root.NodeId)); root.EventNotifier = EventNotifiers.SubscribeToEvents; root.Description = "A folder containing data sources"; AddRootNotifier(root); try { SetupNodes(); FolderState citiesNodes = CreateFolder(root, "Cities", "Cities"); citiesNodes.Description = "This folder contains nodes of the city stations"; WeatherMapVariableState catania = CreateVariable(citiesNodes, "Catania", "Catania", new NodeId(DataTypeIds.WeatherData.Identifier, DataTypeIds.WeatherData.NamespaceIndex), ValueRanks.Scalar); List <BaseVariableState> childCatania = CreateChild(catania); WeatherMapVariableState palermo = CreateVariable(citiesNodes, "Palermo", "Palermo", new NodeId(DataTypeIds.WeatherData.Identifier, DataTypeIds.WeatherData.NamespaceIndex), ValueRanks.Scalar); List <BaseVariableState> childPalermo = CreateChild(palermo); WeatherMapVariableState messina = CreateVariable(citiesNodes, "Messina", "Messina", new NodeId(DataTypeIds.WeatherData.Identifier, DataTypeIds.WeatherData.NamespaceIndex), ValueRanks.Scalar); List <BaseVariableState> childMessina = CreateChild(messina); variables.Add(palermo, childPalermo); variables.Add(messina, childMessina); variables.Add(catania, childCatania); } catch (Exception e) { Utils.Trace(e, "MyOPCServer: Error creating the address space."); } AddPredefinedNode(SystemContext, root); //variable.SetChildValue(SystemContext,BrowseNames.Temperature, variable.Value.Temperature, false); } }
private WeatherMapVariableState CreateVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank) { WeatherMapVariableState variable = new WeatherMapVariableState(parent); //variable.CityName.Value = "i"; variable.SymbolicName = name; variable.ReferenceTypeId = ReferenceTypes.Organizes; variable.TypeDefinitionId = new NodeId(VariableTypeIds.WeatherMapVariableType.Identifier, VariableTypeIds.WeatherMapVariableType.NamespaceIndex); variable.NodeId = new NodeId(path, NamespaceIndex); variable.BrowseName = new QualifiedName(path, NamespaceIndex); variable.DisplayName = new LocalizedText("en", name); variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description; variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description; variable.Description = new String("Information about weather for" + variable.SymbolicName.ToString()); //variable.ClearChangeMasks(SystemContext, true); variable.DataType = dataType; variable.ValueRank = valueRank; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentRead; variable.Historizing = true; variable.Value = GetNewValue(variable.SymbolicName.ToString()); if (variable.Value != null) { variable.StatusCode = StatusCodes.Good; } else { variable.StatusCode = StatusCodes.Bad; } variable.Timestamp = DateTime.UtcNow; if (valueRank == ValueRanks.OneDimension) { variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> { 0 }); } else if (valueRank == ValueRanks.TwoDimensions) { variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> { 0, 0 }); } if (parent != null) { parent.AddChild(variable); } return(variable); }
private List <BaseVariableState> CreateChild(WeatherMapVariableState variable) { List <BaseVariableState> child = new List <BaseVariableState>(); AnalogData info = new AnalogData(); info = variable.Value.Temperature; AnalogVariableState childTemperatura = (AnalogVariableState)CreateVariableChild(null, "Temperature", "Temperature", new NodeId(VariableTypeIds.WeatherMapVariableType.Identifier, VariableTypeIds.WeatherMapVariableType.NamespaceIndex), new NodeId(DataTypeIds.AnalogData.Identifier, DataTypeIds.AnalogData.NamespaceIndex), ValueRanks.Scalar, info, null); variable.AddChild(childTemperatura); child.Add(childTemperatura); //info = null; info = variable.Value.Pressure; AnalogVariableState childPressure = (AnalogVariableState)CreateVariableChild(null, "Pressure", "Pressure", new NodeId(VariableTypeIds.WeatherMapVariableType.Identifier, VariableTypeIds.WeatherMapVariableType.NamespaceIndex), new NodeId(DataTypeIds.AnalogData.Identifier, DataTypeIds.AnalogData.NamespaceIndex), ValueRanks.Scalar, info, null); variable.AddChild(childPressure); child.Add(childPressure); // info = null; info = variable.Value.MaxTemperature; AnalogVariableState childMaxTemp = (AnalogVariableState)CreateVariableChild(null, "MaxTemperature", "MaxTemperature", new NodeId(VariableTypeIds.WeatherMapVariableType.Identifier, VariableTypeIds.WeatherMapVariableType.NamespaceIndex), new NodeId(DataTypeIds.AnalogData.Identifier, DataTypeIds.AnalogData.NamespaceIndex), ValueRanks.Scalar, info, null); variable.AddChild(childMaxTemp); child.Add(childMaxTemp); info = variable.Value.MinTemperature; AnalogVariableState childMinTemp = (AnalogVariableState)CreateVariableChild(null, "MinTemperature", "MinTemperature", new NodeId(VariableTypeIds.WeatherMapVariableType.Identifier, VariableTypeIds.WeatherMapVariableType.NamespaceIndex), new NodeId(DataTypeIds.AnalogData.Identifier, DataTypeIds.AnalogData.NamespaceIndex), ValueRanks.Scalar, info, null); variable.AddChild(childMinTemp); child.Add(childMinTemp); BaseVariableState childCity = CreateVariableChild(null, "City", "City", Opc.Ua.VariableTypeIds.BaseVariableType, Opc.Ua.DataTypeIds.String, ValueRanks.Scalar, null, new String(variable.Value.CityName)); variable.AddChild(childCity); child.Add(childCity); return(child); }