Ejemplo n.º 1
0
        /// <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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets value of OPCUA node property to corresponding VC property
        /// </summary>
        private void UpdateValueToVcProperty(NodeState node)
        {
            Debug.Assert(System.Threading.Thread.CurrentThread == System.Windows.Application.Current.Dispatcher.Thread);

            if (!UaBrowseName2VcComponentName.ContainsKey(node.BrowseName.Name))
            {
                _vcUtils.VcWriteWarningMsg(String.Format("Component with property {0} not found", node.BrowseName.Name));
                return;
            }

            // Cast property OPCUA node to BaseDataVariableState type
            BaseDataVariableState uaProperty = (BaseDataVariableState)node;

            // Get property component as VC object
            ISimComponent vcComponent = _vcUtils.GetComponent(UaBrowseName2VcComponentName[node.BrowseName.Name]);
            IProperty     vcProperty  = vcComponent.GetProperty(node.DisplayName.ToString());

            if (uaProperty.DataType == new NodeId(DataTypeIds.String))
            {
                if ((string)uaProperty.Value == (string)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (string)uaProperty.Value;
            }
            else if (uaProperty.DataType == new NodeId(DataTypeIds.Boolean))
            {
                if ((bool)uaProperty.Value == (bool)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (bool)uaProperty.Value;
            }
            else if (uaProperty.DataType == new NodeId(DataTypeIds.Double))
            {
                if ((double)uaProperty.Value == (double)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (double)uaProperty.Value;
            }
            else if (uaProperty.DataType == new NodeId(DataTypeIds.Integer))
            {
                if ((int)uaProperty.Value == (int)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (int)uaProperty.Value;
            }
            else
            {
                _vcUtils.VcWriteWarningMsg("OPCUA property type not supported" + uaProperty.DataType.ToString());
                return;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets value of OPCUA node property to corresponding VC property
        /// </summary>
        private void ua_PropertyChanged(ISystemContext context, NodeState node, NodeStateChangeMasks changes)
        {
            if (!UaBrowseName2VcComponentName.ContainsKey(node.BrowseName.Name))
            {
                _vcUtils.VcWriteWarningMsg(String.Format("Component with property {0} not found", node.BrowseName.Name));
                return;
            }

            // Cast property OPCUA node to BaseDataVariableState type
            BaseDataVariableState uaProperty = (BaseDataVariableState)node;

            // Get property component as VC object
            ISimComponent vcComponent = _vcUtils.GetComponent(UaBrowseName2VcComponentName[node.BrowseName.Name]);
            IProperty     vcProperty  = vcComponent.GetProperty(node.DisplayName.ToString());

            if (uaProperty.DataType == new NodeId(DataTypeIds.String))
            {
                if ((string)uaProperty.Value == (string)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (string)uaProperty.Value;
            }
            else if (uaProperty.DataType == new NodeId(DataTypeIds.Boolean))
            {
                if ((bool)uaProperty.Value == (bool)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (bool)uaProperty.Value;
            }
            else if (uaProperty.DataType == new NodeId(DataTypeIds.Double))
            {
                if ((double)uaProperty.Value == (double)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (double)uaProperty.Value;
            }
            else if (uaProperty.DataType == new NodeId(DataTypeIds.Integer))
            {
                if ((int)uaProperty.Value == (int)vcProperty.Value)
                {
                    return;
                }
                vcProperty.Value = (int)uaProperty.Value;
            }
            else
            {
                _vcUtils.VcWriteWarningMsg("OPCUA property type not supported" + uaProperty.DataType.ToString());
                return;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets value of OPCUA node signal to corresponding VC signal
        /// </summary>
        private void ua_SignalTriggered(ISystemContext context, NodeState node, NodeStateChangeMasks changes)
        {
            if (!UaBrowseName2VcComponentName.ContainsKey(node.BrowseName.Name))
            {
                _vcUtils.VcWriteWarningMsg(String.Format("Component with signal {0} not found", node.BrowseName.Name));
                return;
            }

            // Cast signal OPCUA node to BaseDataVariableState type
            BaseDataVariableState uaSignal = (BaseDataVariableState)node;

            // Get signal component as VC object
            ISimComponent vcComponent = _vcUtils.GetComponent(UaBrowseName2VcComponentName[node.BrowseName.Name]);
            ISignal       vcSignal    = (ISignal)vcComponent.FindBehavior(node.DisplayName.ToString());

            if (uaSignal.DataType == new NodeId(DataTypeIds.String))
            {
                if ((string)uaSignal.Value == (string)vcSignal.Value)
                {
                    return;
                }
                vcSignal.Value = (string)uaSignal.Value;
            }
            else if (uaSignal.DataType == new NodeId(DataTypeIds.Boolean))
            {
                if ((bool)uaSignal.Value == (bool)vcSignal.Value)
                {
                    return;
                }
                vcSignal.Value = (bool)uaSignal.Value;
            }
            else if (uaSignal.DataType == new NodeId(DataTypeIds.Double))
            {
                if ((double)uaSignal.Value == (double)vcSignal.Value)
                {
                    return;
                }
                vcSignal.Value = (double)uaSignal.Value;
            }
            else if (uaSignal.DataType == new NodeId(DataTypeIds.Integer))
            {
                if ((int)uaSignal.Value == (int)vcSignal.Value)
                {
                    return;
                }
                vcSignal.Value = (int)uaSignal.Value;
            }
            else
            {
                _vcUtils.VcWriteWarningMsg("OPCUA signal type not supported" + uaSignal.DataType.ToString());
                return;
            }
        }
Ejemplo n.º 5
0
        /// <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;
            }
        }
Ejemplo n.º 6
0
        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);
        }