/// <summary> /// Add properties from VC component to component OPCUA node /// </summary> private void AddPropertyNodes(ComponentState uaComponentNode, VcComponent vcComponent) { foreach (IProperty vcProperty in vcComponent.component.Properties) { try { // Add signal node BaseDataVariableState uaPropertyNode = CreateVariableNode(uaComponentNode.Properties, vcProperty.Name, VcProperty2OpcuaType[vcProperty.PropertyType]); uaComponentNode.Properties.AddChild(uaPropertyNode); // Store names in UaBrowseName2VcComponentName UaBrowseName2VcComponentName.Add(uaPropertyNode.BrowseName.Name, vcComponent.component.Name); uaPropertyNode.Value = vcProperty.Value; // Subscribe to property changed events vcProperty.PropertyChanged += vc_PropertyChanged; uaPropertyNode.StateChanged += ua_PropertyChanged; } catch (Exception ex) { logger.Warn("Error adding property", ex); } } }
/// <summary> /// Returns a node tree with a component and all its signals /// </summary> private ComponentState CreateNodeTree(ISimComponent simComponent) { ComponentState componentNode = CreateComponentNode(simComponent.Name); VcComponent vcComponent = new VcComponent(simComponent); AddSignalNodes(componentNode, vcComponent); AddPropertyNodes(componentNode, vcComponent); return(componentNode); }
/// <summary> /// Add signals from VC component to component OPCUA node /// </summary> private void AddSignalNodes(ComponentState uaComponentNode, VcComponent vcComponent) { foreach (ISignal vcSignal in vcComponent.GetSignals()) { // Add signal node BaseDataVariableState uaSignalNode = CreateVariableNode(uaComponentNode.Signals, vcSignal.Name, VcSignal2OpcuaType[vcSignal.Type]); uaComponentNode.Signals.AddChild(uaSignalNode); // Store names in UaBrowseName2VcComponentName UaBrowseName2VcComponentName.Add(uaSignalNode.BrowseName.Name, vcComponent.component.Name); // Subscribe to signal triggered events vcSignal.SignalTrigger += vc_SignalTriggered; uaSignalNode.StateChanged += ua_SignalTriggered; } }
private void World_ComponentRemoving(object sender, ComponentRemovingEventArgs e) { NodeId componentId = NodeId.Create(e.Component.Name, Namespaces.vc2opcua, uaServer.NamespaceUris); ComponentState componentNode = (ComponentState)nodeManager.FindPredefinedNode(componentId, typeof(ComponentState)); if (componentNode != null) { nodeManager.RemoveNode(nodeManager.baseFolder, componentNode, ReferenceTypeIds.Organizes); } // Remove signals from SignalComponents property VcComponent vcComponent = new VcComponent(e.Component); foreach (ISignal signal in vcComponent.GetSignals()) { string nodeNameParent = String.Format("{0}-{1}", signal.Name, vcComponent.component.Name); UaBrowseName2VcComponentName.Remove(nodeNameParent); } _vcUtils.VcWriteWarningMsg("Component removed: " + e.Component.Name); }