/// <summary> /// Sets value of OPCUA node signal to corresponding VC signal /// </summary> private void UpdateValueToVcSignal(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 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; } }
/// <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; } }