/// <summary> /// Creates a new readonly variable. /// </summary> private BaseDataVariableState <T> CreateReadonlyVariable <T>(NodeState parent, string name, NodeId dataType, int valueRank, T defaultValue) { BaseDataVariableState <T> variableState = CreateVariable(parent, name, dataType, valueRank, defaultValue); variableState.AccessLevel = AccessLevels.CurrentRead; return(variableState); }
/// <summary> /// 客户端写入值时触发(绑定到节点的写入事件上) /// </summary> /// <param name="context"></param> /// <param name="node"></param> /// <param name="indexRange"></param> /// <param name="dataEncoding"></param> /// <param name="value"></param> /// <param name="statusCode"></param> /// <param name="timestamp"></param> /// <returns></returns> private ServiceResult OnWriteDataValue(ISystemContext context, NodeState node, NumericRange indexRange, QualifiedName dataEncoding, ref object value, ref StatusCode statusCode, ref DateTime timestamp) { BaseDataVariableState variable = node as BaseDataVariableState; try { //验证数据类型 TypeInfo typeInfo = TypeInfo.IsInstanceOfDataType( value, variable.DataType, variable.ValueRank, context.NamespaceUris, context.TypeTable); if (typeInfo == null || typeInfo == TypeInfo.Unknown) { return(StatusCodes.BadTypeMismatch); } if (typeInfo.BuiltInType == BuiltInType.Double) { double number = Convert.ToDouble(value); value = TypeInfo.Cast(number, typeInfo.BuiltInType); } return(ServiceResult.Good); } catch (Exception) { return(StatusCodes.BadTypeMismatch); } }
public static BaseDataVariableState GetRegisterVariable(MemoryRegister register, int index, ushort namespaceIndex) { if (index < 0 || index >= register.Size) { return(null); } var variable = new BaseDataVariableState <int>(null) { NodeId = GetRegisterVariableId(register, index, namespaceIndex), BrowseName = new QualifiedName(Utils.Format("{0:000000}", index), namespaceIndex) }; variable.DisplayName = variable.BrowseName.Name; variable.Value = register.Read(index); variable.DataType = DataTypeIds.Int32; variable.ValueRank = ValueRanks.Scalar; variable.MinimumSamplingInterval = 100; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; variable.Handle = register; variable.NumericId = (uint)index; return(variable); }
/// <summary> /// Creates a new variable. /// </summary> private BaseDataVariableState CreateVariable(NodeState parent, string path, string name, string displayName, NodeId dataType, bool isArray, object defaultValue) { BaseDataVariableState variable = new BaseDataVariableState(parent) { SymbolicName = name, ReferenceTypeId = ReferenceTypes.Organizes, TypeDefinitionId = VariableTypeIds.BaseDataVariableType, NodeId = new NodeId(path, NamespaceIndex), BrowseName = new QualifiedName(path, NamespaceIndex), DisplayName = new LocalizedText(displayName), WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description, UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description, DataType = dataType, ValueRank = isArray ? ValueRanks.OneDimension : ValueRanks.Scalar, AccessLevel = AccessLevels.CurrentReadOrWrite, UserAccessLevel = AccessLevels.CurrentReadOrWrite, Historizing = false, Value = defaultValue, StatusCode = StatusCodes.Bad, Timestamp = DateTime.UtcNow }; if (isArray) { variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> { 0 }); } parent?.AddChild(variable); return(variable); }
/// <summary> /// Returns true if the system must be scanning to provide updates for the monitored item. /// </summary> private bool SystemScanRequired(MonitoredNode2 monitoredNode, IDataChangeMonitoredItem2 monitoredItem) { // ingore other types of monitored items. if (monitoredItem == null) { return(false); } // only care about variables. BaseDataVariableState source = monitoredNode.Node as BaseDataVariableState; if (source == null) { return(false); } // check for variables that need to be scanned. if (monitoredItem.AttributeId == Attributes.Value) { TestDataObjectState test = source.Parent as TestDataObjectState; if (test != null && test.SimulationActive.Value) { return(true); } } return(false); }
//creating cariable dynamicly( changing value of the variable dynamicly) private BaseDataVariableState CreateDynamicVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank) { BaseDataVariableState variable = CreateVariable(parent, path, name, dataType, valueRank); m_dynamicNodes.Add(variable); return(variable); }
private void CreateNodes(List <OpcuaNode> nodes, FolderState parent, string parentPath) { var list = nodes.Where(d => d.ParentPath == parentPath); foreach (var node in list) { try { if (!node.IsTerminal) { FolderState folderState = CreateFolder(parent, node.ParentPath, node.NodeName); _folderDic.Add(node.NodePath, folderState); CreateNodes(nodes, folderState, node.NodePath); } else { BaseDataVariableState variable = CreateVariable(parent, node.NodePath, node.NodeName, DataTypeIds.Double, ValueRanks.Scalar); //此处需要注意 目录字典是以目录路径作为KEY 而 测点字典是以测点ID作为KEY 为了方便更新实时数据 _nodeDic.Add(node.NodeId.ToString(), variable); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("创建OPC-UA子节点触发异常:" + ex.Message); Console.ResetColor(); } } }
private void UpdateVariableValue() { Task.Run(() => { while (true) { try { int count = 0; if (count > 0 && count != cfgCount) { cfgCount = count; List <OpcuaNode> nodes = new List <OpcuaNode>(); UpdateNodesAttribute(nodes); } BaseDataVariableState node = null; foreach (var item in _nodeDic) { node = item.Value; node.Value = RandomLibrary.GetRandomInt(0, 99); node.Timestamp = DateTime.Now; node.ClearChangeMasks(SystemContext, false); } Thread.Sleep(1000 * 1); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("更新OPC-UA节点数据触发异常:" + ex.Message); Console.ResetColor(); } } }); }
/// <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> /// Creates a new variable. /// </summary> private BaseDataVariableState CreateVariable(NodeState parent, string name, NodeId dataType, int valueRank, object defaultValue, ushort NamespaceIndex) { BaseDataVariableState variable = new BaseDataVariableState(parent); variable.SymbolicName = name; variable.ReferenceTypeId = ReferenceTypes.Organizes; variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType; if (parent == null) { variable.NodeId = new NodeId(name, NamespaceIndex); } else { variable.NodeId = new NodeId(parent.NodeId.ToString() + "/" + name); } variable.BrowseName = new QualifiedName(name, NamespaceIndex); variable.DisplayName = new LocalizedText(name); variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description; variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description; variable.DataType = dataType; variable.ValueRank = valueRank; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; variable.Historizing = false; variable.Value = defaultValue; variable.StatusCode = StatusCodes.Good; variable.Timestamp = DateTime.Now; if (parent != null) { parent.AddChild(variable); } return(variable); }
/// <summary> /// Creates a new variable according to the device tag. /// </summary> private BaseDataVariableState CreateVariable(NodeState parent, string pathPrefix, DeviceTag deviceTag) { NodeId opcDataType = DataTypeIds.Double; object defaultValue = 0.0; bool isArray = deviceTag.IsArray; switch (deviceTag.DataType) { case TagDataType.Double: defaultValue = isArray ? (object)new double[deviceTag.DataLength] : 0.0; break; case TagDataType.Int64: opcDataType = DataTypeIds.Int64; defaultValue = isArray ? (object)new long[deviceTag.DataLength] : (long)0; break; case TagDataType.ASCII: case TagDataType.Unicode: opcDataType = DataTypeIds.String; defaultValue = ""; break; } BaseDataVariableState variable = CreateVariable(parent, pathPrefix + deviceTag.Code, deviceTag.Code, deviceTag.Name, opcDataType, isArray, defaultValue); return(variable); }
/// <summary> /// Sets value of VC property to OPCUA node /// </summary> private void vc_PropertyChanged(object sender, PropertyChangedEventArgs e) { IProperty vcProperty = (IProperty)sender; // Get OPCUA node that will get its value updated string nodeNameParent = String.Format("{0}-{1}", vcProperty.Name, vcProperty.Container); NodeId nodeId = NodeId.Create(nodeNameParent, Namespaces.vc2opcua, uaServer.NamespaceUris); BaseDataVariableState uaProperty = (BaseDataVariableState)nodeManager.FindPredefinedNode(nodeId, typeof(BaseDataVariableState)); if (uaProperty == null) { // Unsubscribe to events vcProperty.PropertyChanged -= vc_PropertyChanged; return; } if (vcProperty.PropertyType == typeof(String)) { if ((string)uaProperty.Value == (string)vcProperty.Value) { return; } uaProperty.Value = (string)vcProperty.Value; } else if (vcProperty.PropertyType == typeof(Boolean)) { if ((bool)uaProperty.Value == (bool)vcProperty.Value) { return; } uaProperty.Value = (bool)vcProperty.Value; } else if (vcProperty.PropertyType == typeof(Double)) { if ((double)uaProperty.Value == (double)vcProperty.Value) { return; } uaProperty.Value = (double)vcProperty.Value; } else if (vcProperty.PropertyType == typeof(Int32)) { if ((int)uaProperty.Value == (int)vcProperty.Value) { return; } uaProperty.Value = (int)vcProperty.Value; } else { _vcUtils.VcWriteWarningMsg("VC property type not supported" + vcProperty.PropertyType.ToString()); return; } uaProperty.Timestamp = DateTime.UtcNow; uaProperty.ClearChangeMasks(nodeManager.context, true); }
/// <summary> /// Returns a unique handle for the node. /// </summary> protected override NodeHandle GetManagerHandle(ServerSystemContext context, NodeId nodeId, IDictionary <NodeId, NodeState> cache) { lock (Lock) { // quickly exclude nodes that are not in the namespace. if (!IsNodeIdInNamespace(nodeId)) { return(null); } NodeHandle handle = new NodeHandle(); handle.NodeId = nodeId; handle.Validated = true; uint id = (uint)nodeId.Identifier; // find register int registerId = (int)((id & 0xFF000000) >> 24); int index = (int)(id & 0x00FFFFFF); if (registerId == 0) { MemoryRegister register = m_system.GetRegister(index); if (register == null) { return(null); } handle.Node = ModelUtils.GetRegister(register, NamespaceIndex); } // find register variable. else { MemoryRegister register = m_system.GetRegister(registerId); if (register == null) { return(null); } // find register variable. BaseDataVariableState variable = ModelUtils.GetRegisterVariable(register, index, NamespaceIndex); if (variable == null) { return(null); } handle.Node = variable; } return(handle); } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <summary> /// 实时更新节点数据 /// </summary> public void UpdateVariableValue() { Task.Run(() => { while (true) { try { /* * 此处仅作示例代码 所以不修改节点树 故将UpdateNodesAttribute()方法跳过 * 在实际业务中 请根据自身的业务需求决定何时修改节点菜单树 */ int count = 0; //配置发生更改时,重新生成节点树 if (count > 0 && count != cfgCount) { cfgCount = count; List <OpcuaNode> nodes = new List <OpcuaNode>(); /* * 此处有想过删除整个菜单树,然后重建 保证各个NodeId仍与原来的一直 * 但是 后来发现这样会导致原来的客户端订阅信息丢失 无法获取订阅数据 * 所以 只能一级级的检查节点 然后修改属性 */ UpdateNodesAttribute(nodes); } //模拟获取实时数据 BaseDataVariableState node = null; /* * 在实际业务中应该是根据对应的标识来更新固定节点的数据 * 这里 我偷个懒 全部测点都更新为一个新的随机数 */ foreach (var item in _nodeDic) { node = item.Value; node.Value = RandomLibrary.GetRandomInt(0, 99); node.Timestamp = DateTime.Now; //变更标识 只有执行了这一步,订阅的客户端才会收到新的数据 node.ClearChangeMasks(SystemContext, false); } //1秒更新一次 Thread.Sleep(1000 * 1); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("更新OPC-UA节点数据触发异常:" + ex.Message); Console.ResetColor(); } } }); }
public AlarmController(BaseDataVariableState variable, int interval, bool isBoolean) { m_variable = variable; m_interval = interval; m_isBoolean = isBoolean; m_increment = true; m_value = m_midpoint; m_stopTime = m_stopTime.AddYears(5); m_allowChanges = false; }
private void addSelectedNodeAsChild(BaseInstanceState parentNode) { ReferenceDescription selectedNode = this.BrowseCTRL.SelectedNode; if (selectedNode.NodeClass == NodeClass.Variable) { ReadValueId nodeToRead = new ReadValueId(); nodeToRead.NodeId = (NodeId)selectedNode.NodeId; nodeToRead.AttributeId = Attributes.Value; nodeToRead.Handle = selectedNode; ReadValueIdCollection nodesToRead = new ReadValueIdCollection(); nodesToRead.Add(nodeToRead); DataValueCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; this.connectServerCtrl1.Session.Read(null, 0, TimestampsToReturn.Neither, nodesToRead, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToRead); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead); TypeInfo varInfo = TypeInfo.Construct(results[0].Value); BaseVariableState varNode = new BaseDataVariableState(parentNode); varNode.ValueRank = varInfo.ValueRank; varNode.WrappedValue = results[0].WrappedValue; varNode.NodeId = (NodeId)selectedNode.NodeId; varNode.BrowseName = new QualifiedName(selectedNode.DisplayName.Text, (ushort)m_server.getNamespaceIndex(this.connectServerCtrl1.Session.NamespaceUris.GetString(selectedNode.BrowseName.NamespaceIndex))); varNode.DisplayName = varNode.BrowseName.Name; m_server.addNode(varNode, parentNode.NodeId); m_server.addVariableConnection(varNode, selectedNode, this.connectServerCtrl1.ServerUrl); } else { BaseObjectState child = new BaseObjectState(parentNode); uint nodeid_ident; if (UInt32.TryParse(selectedNode.NodeId.Identifier.ToString(), out nodeid_ident)) { child.NodeId = new NodeId(nodeid_ident); } else { child.NodeId = new NodeId(selectedNode.NodeId.Identifier.ToString()); } child.BrowseName = selectedNode.BrowseName; child.DisplayName = child.BrowseName.Name; this.m_server.addNode(child, parentNode.NodeId); } }
/// <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 UpdateTimerCallback(object state) { #region Update Tetris Simulation Nodes foreach (NodeState nodestate in PredefinedNodes.Values) { if (nodestate.SymbolicName == "Tetris_Simulation") { //When the Tetris_Simulation Node is found, get it's children: List <BaseInstanceState> children = new List <BaseInstanceState>(); nodestate.GetChildren(SystemContext, children); //Iterate through the children and update the necessary nodes: foreach (BaseInstanceState child in children) { BaseDataVariableState childvariable = child as BaseDataVariableState; if (childvariable != null) { switch (childvariable.BrowseName.Name) { case "simulated_Score": childvariable.Value = m_TetrisSimulation.Score; break; case "simulated_GameOver": childvariable.Value = m_TetrisSimulation.GameOver; break; case "simulated_Paused": if (childvariable.Value != null) { m_TetrisSimulation.Paused = (bool)childvariable.Value; } break; default: break; } } } // make known that this nodes and it's child nodes have changed: nodestate.ClearChangeMasks(SystemContext, true); // Tetris node found, no further need to iterate: break; } } #endregion }
public CodeGenVariableTypeBase CreateVariable(Dictionary <CodeGenNodeID, CodeGenNodeID> childrenIDMap, NodeState parent, string fileNoExtension, string name, string typeId, ushort typeNamespaceIndex, IdType typeNodeIdType, string nodeId, ushort namespaceIndex, IdType nodeIdType, string parentNodeId, ushort parentNamespaceIndex, IdType parentNodeIdType, int valueRank) { BaseDataVariableState variable = new BaseDataVariableState(parent); variable.SymbolicName = name; variable.TypeDefinitionId = Helper.CreateID(typeId, typeNamespaceIndex, typeNodeIdType); variable.NodeId = Helper.CreateID(childrenIDMap, this, nodeId, namespaceIndex, nodeIdType); //variable.BrowseName = new QualifiedName(name, NamespaceIndex); variable.ValueRank = valueRank; variable.ArrayDimensions = null; //TODO: More code for different types 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); } CodeGenVariableTypeBase newNode = CodeGenNodeFactory.CreateVariable(name, fileNoExtension, typeId, typeNamespaceIndex, typeNodeIdType, nodeId, namespaceIndex, nodeIdType, parentNodeId, parentNamespaceIndex, parentNodeIdType); newNode.SetNode(variable); newNode.Initialize(childrenIDMap, this); return(newNode); }
/// <summary> /// Sets the variable value. /// </summary> private void SetVariable(VarItem varItem, CnlData[] cnlData, int dataIndex, DateTime timestamp) { try { DeviceTag deviceTag = varItem.DeviceTag; int dataLength = deviceTag.DataLength; object value = 0.0; switch (deviceTag.DataType) { case TagDataType.Double: value = deviceTag.IsArray ? (object)CnlDataConverter.GetDoubleArray(cnlData, dataIndex, dataLength) : CnlDataConverter.GetDouble(cnlData, dataIndex); break; case TagDataType.Int64: value = deviceTag.IsArray ? (object)CnlDataConverter.GetInt64Array(cnlData, dataIndex, dataLength) : CnlDataConverter.GetInt64(cnlData, dataIndex); break; case TagDataType.ASCII: value = CnlDataConverter.GetAscii(cnlData, dataIndex, dataLength); break; case TagDataType.Unicode: value = CnlDataConverter.GetUnicode(cnlData, dataIndex, dataLength); break; } BaseDataVariableState variable = varItem.Variable; variable.Value = value; variable.StatusCode = CnlDataConverter.GetStatus(cnlData, dataIndex, dataLength) > CnlStatusID.Undefined ? StatusCodes.Good : StatusCodes.Bad; variable.Timestamp = timestamp; variable.ClearChangeMasks(SystemContext, false); } catch (Exception ex) { log.WriteException(ex, Locale.IsRussian ? "Ошибка при установке значения переменной {0}" : "Error setting the variable {0}", varItem.Variable.NodeId); } }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return(null); } BaseInstanceState instance = null; switch (browseName.Name) { case BoilerModel.BrowseNames.BoilerStatus: { if (createOrReplace) { if (BoilerStatus == null) { if (replacement == null) { BoilerStatus = new BaseDataVariableState <BoilerDataType>(this); } else { BoilerStatus = (BaseDataVariableState <BoilerDataType>)replacement; } } } instance = BoilerStatus; break; } } if (instance != null) { return(instance); } return(base.FindChild(context, browseName, createOrReplace, replacement)); }
/// <summary> /// Converts a ReferenceDescription to an IReference. /// </summary> private IReference ToReference(ReferenceDescription reference) { if (reference.NodeId.IsAbsolute || reference.TypeDefinition.IsAbsolute) { return(new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, reference.NodeId)); } if (m_source != null && (reference.NodeId == ObjectIds.ObjectsFolder || reference.NodeId == ObjectIds.Server)) { return(new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, m_rootId)); } NodeState target = null; switch (reference.NodeClass) { case NodeClass.DataType: { target = new DataTypeState(); break; } case NodeClass.Method: { target = new MethodState(null); break; } case NodeClass.Object: { target = new BaseObjectState(null); break; } case NodeClass.ObjectType: { target = new BaseObjectTypeState(); break; } case NodeClass.ReferenceType: { target = new ReferenceTypeState(); break; } case NodeClass.Variable: { target = new BaseDataVariableState(null); break; } case NodeClass.VariableType: { target = new BaseDataVariableTypeState(); break; } case NodeClass.View: { target = new ViewState(); break; } } target.NodeId = m_mapper.ToLocalId((NodeId)reference.NodeId); target.BrowseName = m_mapper.ToLocalName(reference.BrowseName); target.DisplayName = reference.DisplayName; if (target is BaseInstanceState) { ((BaseInstanceState)target).TypeDefinitionId = m_mapper.ToLocalId((NodeId)reference.TypeDefinition); } return(new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, target)); }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return(null); } BaseInstanceState instance = null; switch (browseName.Name) { case CAS.UA.Server.DataSource.Isotherm.Model.BrowseNames.ArrayVariableInstanceDeclaration: { if (createOrReplace) { if (ArrayVariableInstanceDeclaration == null) { if (replacement == null) { ArrayVariableInstanceDeclaration = new BaseDataVariableState <StructureExample[]>(this); } else { ArrayVariableInstanceDeclaration = (BaseDataVariableState <StructureExample[]>)replacement; } } } instance = ArrayVariableInstanceDeclaration; break; } } if (instance != null) { return(instance); } return(base.FindChild(context, browseName, createOrReplace, replacement)); }
public ServiceResult OnWrite( ISystemContext context, NodeState node, NumericRange indexRange, QualifiedName dataEncoding, ref object value, ref StatusCode statusCode, ref DateTime timestamp) { BaseDataVariableState variable = node as BaseDataVariableState; // verify data type. Opc.Ua.TypeInfo typeInfo = Opc.Ua.TypeInfo.IsInstanceOfDataType( value, variable.DataType, variable.ValueRank, context.NamespaceUris, context.TypeTable); if (typeInfo == null || typeInfo == Opc.Ua.TypeInfo.Unknown) { return StatusCodes.BadTypeMismatch; } // check index range. if (variable.ValueRank >= 0) { if (indexRange != NumericRange.Empty) { object target = variable.Value; ServiceResult result = indexRange.UpdateRange(ref target, value); if (ServiceResult.IsBad(result)) { return result; } value = target; } } return ServiceResult.Good; }
/// <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); BaseDataVariableState dictionary = (BaseDataVariableState)FindPredefinedNode( ExpandedNodeId.ToNodeId(Quickstarts.DataTypes.Types.VariableIds.DataTypes_BinarySchema, Server.NamespaceUris), typeof(BaseDataVariableState)); dictionary.Value = LoadSchemaFromResource("Quickstarts.DataTypes.Types.Quickstarts.DataTypes.Types.Types.bsd", typeof(Quickstarts.DataTypes.Types.VehicleType).Assembly); dictionary = (BaseDataVariableState)FindPredefinedNode( ExpandedNodeId.ToNodeId(Quickstarts.DataTypes.Types.VariableIds.DataTypes_XmlSchema, Server.NamespaceUris), typeof(BaseDataVariableState)); dictionary.Value = LoadSchemaFromResource("Quickstarts.DataTypes.Types.Quickstarts.DataTypes.Types.Types.xsd", typeof(Quickstarts.DataTypes.Types.VehicleType).Assembly); } }
/// <summary> /// Create a mechanism to create a Variable /// </summary> public static BaseDataVariableState CreateVariable(NodeState parent, ushort nameSpaceIndex, string path, string name, uint dataTypeIdentifier) { BaseDataVariableState variable = new BaseDataVariableState(parent); variable.SymbolicName = name; variable.ReferenceTypeId = ReferenceTypes.Organizes; variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType; variable.NodeId = new NodeId(path, nameSpaceIndex); variable.BrowseName = new QualifiedName(name, nameSpaceIndex); variable.DisplayName = new LocalizedText("en", name); variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description; variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description; switch (dataTypeIdentifier) { case Opc.Ua.DataTypes.Boolean: variable.DataType = DataTypeIds.Boolean; variable.Value = false; break; case Opc.Ua.DataTypes.Int32: variable.DataType = DataTypeIds.Int32; variable.Value = AlarmDefines.NORMAL_START_VALUE; break; case Opc.Ua.DataTypes.Double: variable.DataType = DataTypeIds.Double; variable.Value = (double)AlarmDefines.NORMAL_START_VALUE; break; } variable.ValueRank = ValueRanks.Scalar; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; variable.Historizing = false; variable.StatusCode = StatusCodes.Good; variable.Timestamp = DateTime.UtcNow; if (parent != null) { parent.AddChild(variable); } return(variable); }
/// <summary> /// Creates a new variable. /// </summary> private BaseDataVariableState CreateVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank) { BaseDataVariableState variable = new BaseDataVariableState(parent); variable.SymbolicName = name; variable.ReferenceTypeId = ReferenceTypes.Organizes; variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType; 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.DataType = dataType; variable.ValueRank = valueRank; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; variable.Historizing = false; variable.Value = GetNewValue(variable); variable.StatusCode = StatusCodes.Good; 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); }
public static BaseDataVariableState GetRegisterVariable(MemoryRegister register, int index, ushort namespaceIndex) { if (index < 0 || index >= register.Size) { return null; } BaseDataVariableState<int> variable = new BaseDataVariableState<int>(null); variable.NodeId = GetRegisterVariableId(register, index, namespaceIndex); variable.BrowseName = new QualifiedName(Utils.Format("{0:000000}", index), namespaceIndex); variable.DisplayName = variable.BrowseName.Name; variable.Value = register.Read(index); variable.DataType = DataTypeIds.Int32; variable.ValueRank = ValueRanks.Scalar; variable.MinimumSamplingInterval = 100; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; variable.Handle = register; variable.NumericId = (uint)index; return variable; }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return null; } BaseInstanceState instance = null; switch (browseName.Name) { case TutorialModel.BrowseNames.FlowTransmitter: { if (createOrReplace) { if (FlowTransmitter == null) { if (replacement == null) { FlowTransmitter = new GenericSensorState(this); } else { FlowTransmitter = (GenericSensorState)replacement; } } } instance = FlowTransmitter; break; } case TutorialModel.BrowseNames.Valve: { if (createOrReplace) { if (Valve == null) { if (replacement == null) { Valve = new GenericActuatorState(this); } else { Valve = (GenericActuatorState)replacement; } } } instance = Valve; break; } case TutorialModel.BrowseNames.Calibration: { if (createOrReplace) { if (Calibration == null) { if (replacement == null) { Calibration = new BaseDataVariableState<CalibrationDataType>(this); } else { Calibration = (BaseDataVariableState<CalibrationDataType>)replacement; } } } instance = Calibration; break; } } if (instance != null) { return instance; } return base.FindChild(context, browseName, createOrReplace, replacement); }
/// <summary> /// Imports a node from the set. /// </summary> private NodeState Import(ISystemContext context, UANode node) { NodeState importedNode = null; NodeClass nodeClass = NodeClass.Unspecified; if (node is UAObject) nodeClass = NodeClass.Object; else if (node is UAVariable) nodeClass = NodeClass.Variable; else if (node is UAMethod) nodeClass = NodeClass.Method; else if (node is UAObjectType) nodeClass = NodeClass.ObjectType; else if (node is UAVariableType) nodeClass = NodeClass.VariableType; else if (node is UADataType) nodeClass = NodeClass.DataType; else if (node is UAReferenceType) nodeClass = NodeClass.ReferenceType; else if (node is UAView) nodeClass = NodeClass.View; switch (nodeClass) { case NodeClass.Object: { UAObject o = (UAObject)node; BaseObjectState value = new BaseObjectState(null); value.EventNotifier = o.EventNotifier; importedNode = value; break; } case NodeClass.Variable: { UAVariable o = (UAVariable)node; NodeId typeDefinitionId = null; if (node.References != null) { for (int ii = 0; ii < node.References.Length; ii++) { Opc.Ua.NodeId referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true); bool isInverse = !node.References[ii].IsForward; Opc.Ua.ExpandedNodeId targetId = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris); if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse) { typeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); break; } } } BaseVariableState value = null; if (typeDefinitionId == Opc.Ua.VariableTypeIds.PropertyType) { value = new PropertyState(null); } else { value = new BaseDataVariableState(null); } value.DataType = ImportNodeId(o.DataType, context.NamespaceUris, true); value.ValueRank = o.ValueRank; value.ArrayDimensions = ImportArrayDimensions(o.ArrayDimensions); value.AccessLevel = o.AccessLevel; value.UserAccessLevel = o.UserAccessLevel; value.MinimumSamplingInterval = o.MinimumSamplingInterval; value.Historizing = o.Historizing; if (o.Value != null) { XmlDecoder decoder = CreateDecoder(context, o.Value); TypeInfo typeInfo = null; value.Value = decoder.ReadVariantContents(out typeInfo); decoder.Close(); } importedNode = value; break; } case NodeClass.Method: { UAMethod o = (UAMethod)node; MethodState value = new MethodState(null); value.Executable = o.Executable; value.UserExecutable = o.UserExecutable; importedNode = value; break; } case NodeClass.View: { UAView o = (UAView)node; ViewState value = new ViewState(); value.ContainsNoLoops = o.ContainsNoLoops; importedNode = value; break; } case NodeClass.ObjectType: { UAObjectType o = (UAObjectType)node; BaseObjectTypeState value = new BaseObjectTypeState(); value.IsAbstract = o.IsAbstract; importedNode = value; break; } case NodeClass.VariableType: { UAVariableType o = (UAVariableType)node; BaseVariableTypeState value = new BaseDataVariableTypeState(); value.IsAbstract = o.IsAbstract; value.DataType = ImportNodeId(o.DataType, context.NamespaceUris, true); value.ValueRank = o.ValueRank; value.ArrayDimensions = ImportArrayDimensions(o.ArrayDimensions); if (o.Value != null) { XmlDecoder decoder = CreateDecoder(context, o.Value); TypeInfo typeInfo = null; value.Value = decoder.ReadVariantContents(out typeInfo); decoder.Close(); } importedNode = value; break; } case NodeClass.DataType: { UADataType o = (UADataType)node; DataTypeState value = new DataTypeState(); value.IsAbstract = o.IsAbstract; value.Definition = Import(o.Definition, context.NamespaceUris); importedNode = value; break; } case NodeClass.ReferenceType: { UAReferenceType o = (UAReferenceType)node; ReferenceTypeState value = new ReferenceTypeState(); value.IsAbstract = o.IsAbstract; value.InverseName = Import(o.InverseName); value.Symmetric = o.Symmetric; importedNode = value; break; } } importedNode.NodeId = ImportNodeId(node.NodeId, context.NamespaceUris, false); importedNode.BrowseName = ImportQualifiedName(node.BrowseName, context.NamespaceUris); importedNode.DisplayName = Import(node.DisplayName); importedNode.Description = Import(node.Description); importedNode.WriteMask = (AttributeWriteMask)node.WriteMask; importedNode.UserWriteMask = (AttributeWriteMask)node.UserWriteMask; if (!String.IsNullOrEmpty(node.SymbolicName)) { importedNode.SymbolicName = node.SymbolicName; } if (node.References != null) { BaseInstanceState instance = importedNode as BaseInstanceState; BaseTypeState type = importedNode as BaseTypeState; for (int ii = 0; ii < node.References.Length; ii++) { Opc.Ua.NodeId referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true); bool isInverse = !node.References[ii].IsForward; Opc.Ua.ExpandedNodeId targetId = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris); if (instance != null) { if (referenceTypeId == ReferenceTypeIds.HasModellingRule && !isInverse) { instance.ModellingRuleId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); continue; } if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse) { instance.TypeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); continue; } } if (type != null) { if (referenceTypeId == ReferenceTypeIds.HasSubtype && isInverse) { type.SuperTypeId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); continue; } } importedNode.AddReference(referenceTypeId, isInverse, targetId); } } return importedNode; }
/// <summary> /// Creates a new variable. /// </summary> private BaseDataVariableState CreateVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank) { BaseDataVariableState variable = new BaseDataVariableState(parent); variable.SymbolicName = name; variable.ReferenceTypeId = ReferenceTypes.Organizes; variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType; 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.DataType = dataType; variable.ValueRank = valueRank; variable.AccessLevel = AccessLevels.CurrentReadOrWrite; variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite; variable.Historizing = false; variable.Value = GetNewValue(variable); variable.StatusCode = StatusCodes.Good; variable.Timestamp = DateTime.UtcNow; if (parent != null) { parent.AddChild(variable); } return variable; }
/// <summary> /// Initializes the instance from an event notification. /// </summary> /// <param name="context">The context.</param> /// <param name="fields">The fields selected for the event notification.</param> /// <param name="e">The event notification.</param> /// <remarks> /// This method creates components based on the browse paths in the event field and sets /// the NodeId or Value based on values in the event notification. /// </remarks> public void Update( ISystemContext context, SimpleAttributeOperandCollection fields, EventFieldList e) { for (int ii = 0; ii < fields.Count; ii++) { SimpleAttributeOperand field = fields[ii]; object value = e.EventFields[ii].Value; // check if value provided. if (value == null) { continue; } // extract the NodeId for the event. if (field.BrowsePath.Count == 0) { if (field.AttributeId == Attributes.NodeId) { this.NodeId = value as NodeId; continue; } } // extract the type definition for the event. if (field.BrowsePath.Count == 1) { if (field.AttributeId == Attributes.Value) { if (field.BrowsePath[0] == BrowseNames.EventType) { m_typeDefinitionId = value as NodeId; continue; } } } // save value for child node. NodeState parent = this; for (int jj = 0; jj < field.BrowsePath.Count; jj++) { // find a predefined child identified by the browse name. BaseInstanceState child = parent.CreateChild(context, field.BrowsePath[jj]); // create a placeholder for unknown children. if (child == null) { if (field.AttributeId == Attributes.Value) { child = new BaseDataVariableState(parent); } else { child = new BaseObjectState(parent); } parent.AddChild(child); } // ensure the browse name is set. if (QualifiedName.IsNull(child.BrowseName)) { child.BrowseName = field.BrowsePath[jj]; } // ensure the display name is set. if (LocalizedText.IsNullOrEmpty(child.DisplayName)) { child.DisplayName = child.BrowseName.Name; } // process next element in path. if (jj < field.BrowsePath.Count-1) { parent = child; continue; } // save the variable value. if (field.AttributeId == Attributes.Value) { BaseVariableState variable = child as BaseVariableState; if (variable != null && field.AttributeId == Attributes.Value) { try { variable.WrappedValue = e.EventFields[ii]; } catch (Exception) { variable.Value = null; } } break; } // save the node id. child.NodeId = value as NodeId; } } }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return null; } BaseInstanceState instance = null; switch (browseName.Name) { case DsatsDemo.BrowseNames.ChangePhase: { if (createOrReplace) { if (ChangePhase == null) { if (replacement == null) { ChangePhase = new ChangePhaseMethodState(this); } else { ChangePhase = (ChangePhaseMethodState)replacement; } } } instance = ChangePhase; break; } case DsatsDemo.BrowseNames.ChangePhaseWithString: { if (createOrReplace) { if (ChangePhaseWithString == null) { if (replacement == null) { ChangePhaseWithString = new PropertyState<string>(this); } else { ChangePhaseWithString = (PropertyState<string>)replacement; } } } instance = ChangePhaseWithString; break; } case DsatsDemo.BrowseNames.CurrentPhase: { if (createOrReplace) { if (CurrentPhase == null) { if (replacement == null) { CurrentPhase = new BaseDataVariableState<NodeId>(this); } else { CurrentPhase = (BaseDataVariableState<NodeId>)replacement; } } } instance = CurrentPhase; break; } case DsatsDemo.BrowseNames.Phases: { if (createOrReplace) { if (Phases == null) { if (replacement == null) { Phases = new FolderState(this); } else { Phases = (FolderState)replacement; } } } instance = Phases; break; } case DsatsDemo.BrowseNames.Locks: { if (createOrReplace) { if (Locks == null) { if (replacement == null) { Locks = new FolderState(this); } else { Locks = (FolderState)replacement; } } } instance = Locks; break; } case DsatsDemo.BrowseNames.TopDrive: { if (createOrReplace) { if (TopDrive == null) { if (replacement == null) { TopDrive = new TopDriveState(this); } else { TopDrive = (TopDriveState)replacement; } } } instance = TopDrive; break; } case DsatsDemo.BrowseNames.MudPumps: { if (createOrReplace) { if (MudPumps == null) { if (replacement == null) { MudPumps = new FolderState(this); } else { MudPumps = (FolderState)replacement; } } } instance = MudPumps; break; } } if (instance != null) { return instance; } return base.FindChild(context, browseName, createOrReplace, replacement); }
/// <summary> /// Converts a ReferenceDescription to an IReference. /// </summary> private IReference ToReference(ReferenceDescription reference) { if (reference.NodeId.IsAbsolute || reference.TypeDefinition.IsAbsolute) { return new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, reference.NodeId); } if (m_source != null && (reference.NodeId == ObjectIds.ObjectsFolder || reference.NodeId == ObjectIds.Server)) { return new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, m_rootId); } NodeState target = null; switch (reference.NodeClass) { case NodeClass.DataType: { target = new DataTypeState(); break; } case NodeClass.Method: { target = new MethodState(null); break; } case NodeClass.Object: { target = new BaseObjectState(null); break; } case NodeClass.ObjectType: { target = new BaseObjectTypeState(); break; } case NodeClass.ReferenceType: { target = new ReferenceTypeState(); break; } case NodeClass.Variable: { target = new BaseDataVariableState(null); break; } case NodeClass.VariableType: { target = new BaseDataVariableTypeState(); break; } case NodeClass.View: { target = new ViewState(); break; } } target.NodeId = m_mapper.ToLocalId((NodeId)reference.NodeId); target.BrowseName = m_mapper.ToLocalName(reference.BrowseName); target.DisplayName = reference.DisplayName; if (target is BaseInstanceState) { ((BaseInstanceState)target).TypeDefinitionId = m_mapper.ToLocalId((NodeId)reference.TypeDefinition); } return new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, target); }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return null; } BaseInstanceState instance = null; switch (browseName.Name) { case Opc.Ua.Plc.BrowseNames.Body: { if (createOrReplace) { if (Body == null) { if (replacement == null) { Body = new BaseDataVariableState<XmlElement>(this); } else { Body = (BaseDataVariableState<XmlElement>)replacement; } } } instance = Body; break; } } if (instance != null) { return instance; } return base.FindChild(context, browseName, createOrReplace, replacement); }
/// <summary> /// Verifies that the specified node exists. /// </summary> protected override NodeState ValidateNode( ServerSystemContext context, NodeHandle handle, IDictionary<NodeId, NodeState> cache) { // not valid if no root. if (handle == null) { return null; } // check if previously validated. if (handle.Validated) { return handle.Node; } // lookup in operation cache. NodeState target = FindNodeInCache(context, handle, cache); if (target != null) { handle.Node = target; handle.Validated = true; return handle.Node; } try { Opc.Ua.Client.Session client = GetClientSession(context); // get remote node. NodeId targetId = m_mapper.ToRemoteId(handle.NodeId); ILocalNode node = client.ReadNode(targetId) as ILocalNode; if (node == null) { return null; } // map remote node to local object. switch (node.NodeClass) { case NodeClass.ObjectType: { BaseObjectTypeState value = new BaseObjectTypeState(); value.IsAbstract = ((IObjectType)node).IsAbstract; target = value; break; } case NodeClass.VariableType: { BaseVariableTypeState value = new BaseDataVariableTypeState(); value.IsAbstract = ((IVariableType)node).IsAbstract; value.Value = m_mapper.ToLocalValue(((IVariableType)node).Value); value.DataType = m_mapper.ToLocalId(((IVariableType)node).DataType); value.ValueRank = ((IVariableType)node).ValueRank; value.ArrayDimensions = new ReadOnlyList<uint>(((IVariableType)node).ArrayDimensions); target = value; break; } case NodeClass.DataType: { DataTypeState value = new DataTypeState(); value.IsAbstract = ((IDataType)node).IsAbstract; target = value; break; } case NodeClass.ReferenceType: { ReferenceTypeState value = new ReferenceTypeState(); value.IsAbstract = ((IReferenceType)node).IsAbstract; value.InverseName = ((IReferenceType)node).InverseName; value.Symmetric = ((IReferenceType)node).Symmetric; target = value; break; } case NodeClass.Object: { BaseObjectState value = new BaseObjectState(null); value.EventNotifier = ((IObject)node).EventNotifier; target = value; break; } case NodeClass.Variable: { BaseDataVariableState value = new BaseDataVariableState(null); value.Value = m_mapper.ToLocalValue(((IVariable)node).Value); value.DataType = m_mapper.ToLocalId(((IVariable)node).DataType); value.ValueRank = ((IVariable)node).ValueRank; value.ArrayDimensions = new ReadOnlyList<uint>(((IVariable)node).ArrayDimensions); value.AccessLevel = ((IVariable)node).AccessLevel; value.UserAccessLevel = ((IVariable)node).UserAccessLevel; value.Historizing = ((IVariable)node).Historizing; value.MinimumSamplingInterval = ((IVariable)node).MinimumSamplingInterval; target = value; break; } case NodeClass.Method: { MethodState value = new MethodState(null); value.Executable = ((IMethod)node).Executable; value.UserExecutable = ((IMethod)node).UserExecutable; target = value; break; } case NodeClass.View: { ViewState value = new ViewState(); value.ContainsNoLoops = ((IView)node).ContainsNoLoops; target = value; break; } } target.NodeId = handle.NodeId; target.BrowseName = m_mapper.ToLocalName(node.BrowseName); target.DisplayName = node.DisplayName; target.Description = node.Description; target.WriteMask = node.WriteMask; target.UserWriteMask = node.UserWriteMask; target.Handle = node; target.OnCreateBrowser = OnCreateBrowser; } // ignore errors. catch { return null; } // put root into operation cache. if (cache != null) { cache[handle.NodeId] = target; } handle.Node = target; handle.Validated = true; return handle.Node; }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return null; } BaseInstanceState instance = null; switch (browseName.Name) { case FileSystem.BrowseNames.Temperature: { if (createOrReplace) { if (Temperature == null) { if (replacement == null) { Temperature = new AnalogItemState<double>(this); } else { Temperature = (AnalogItemState<double>)replacement; } } } instance = Temperature; break; } case FileSystem.BrowseNames.TemperatureSetPoint: { if (createOrReplace) { if (TemperatureSetPoint == null) { if (replacement == null) { TemperatureSetPoint = new AnalogItemState<double>(this); } else { TemperatureSetPoint = (AnalogItemState<double>)replacement; } } } instance = TemperatureSetPoint; break; } case FileSystem.BrowseNames.State: { if (createOrReplace) { if (State == null) { if (replacement == null) { State = new BaseDataVariableState<int>(this); } else { State = (BaseDataVariableState<int>)replacement; } } } instance = State; break; } case FileSystem.BrowseNames.PowerConsumption: { if (createOrReplace) { if (PowerConsumption == null) { if (replacement == null) { PowerConsumption = new DataItemState<double>(this); } else { PowerConsumption = (DataItemState<double>)replacement; } } } instance = PowerConsumption; break; } case FileSystem.BrowseNames.Start: { if (createOrReplace) { if (Start == null) { if (replacement == null) { Start = new MethodState(this); } else { Start = (MethodState)replacement; } } } instance = Start; break; } case FileSystem.BrowseNames.Stop: { if (createOrReplace) { if (Stop == null) { if (replacement == null) { Stop = new MethodState(this); } else { Stop = (MethodState)replacement; } } } instance = Stop; break; } } if (instance != null) { return instance; } return base.FindChild(context, browseName, createOrReplace, replacement); }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return null; } BaseInstanceState instance = null; switch (browseName.Name) { case TestData.BrowseNames.BooleanValue: { if (createOrReplace) { if (BooleanValue == null) { if (replacement == null) { BooleanValue = new BaseDataVariableState<bool>(this); } else { BooleanValue = (BaseDataVariableState<bool>)replacement; } } } instance = BooleanValue; break; } case TestData.BrowseNames.SByteValue: { if (createOrReplace) { if (SByteValue == null) { if (replacement == null) { SByteValue = new BaseDataVariableState<sbyte>(this); } else { SByteValue = (BaseDataVariableState<sbyte>)replacement; } } } instance = SByteValue; break; } case TestData.BrowseNames.ByteValue: { if (createOrReplace) { if (ByteValue == null) { if (replacement == null) { ByteValue = new BaseDataVariableState<byte>(this); } else { ByteValue = (BaseDataVariableState<byte>)replacement; } } } instance = ByteValue; break; } case TestData.BrowseNames.Int16Value: { if (createOrReplace) { if (Int16Value == null) { if (replacement == null) { Int16Value = new BaseDataVariableState<short>(this); } else { Int16Value = (BaseDataVariableState<short>)replacement; } } } instance = Int16Value; break; } case TestData.BrowseNames.UInt16Value: { if (createOrReplace) { if (UInt16Value == null) { if (replacement == null) { UInt16Value = new BaseDataVariableState<ushort>(this); } else { UInt16Value = (BaseDataVariableState<ushort>)replacement; } } } instance = UInt16Value; break; } case TestData.BrowseNames.Int32Value: { if (createOrReplace) { if (Int32Value == null) { if (replacement == null) { Int32Value = new BaseDataVariableState<int>(this); } else { Int32Value = (BaseDataVariableState<int>)replacement; } } } instance = Int32Value; break; } case TestData.BrowseNames.UInt32Value: { if (createOrReplace) { if (UInt32Value == null) { if (replacement == null) { UInt32Value = new BaseDataVariableState<uint>(this); } else { UInt32Value = (BaseDataVariableState<uint>)replacement; } } } instance = UInt32Value; break; } case TestData.BrowseNames.Int64Value: { if (createOrReplace) { if (Int64Value == null) { if (replacement == null) { Int64Value = new BaseDataVariableState<long>(this); } else { Int64Value = (BaseDataVariableState<long>)replacement; } } } instance = Int64Value; break; } case TestData.BrowseNames.UInt64Value: { if (createOrReplace) { if (UInt64Value == null) { if (replacement == null) { UInt64Value = new BaseDataVariableState<ulong>(this); } else { UInt64Value = (BaseDataVariableState<ulong>)replacement; } } } instance = UInt64Value; break; } case TestData.BrowseNames.FloatValue: { if (createOrReplace) { if (FloatValue == null) { if (replacement == null) { FloatValue = new BaseDataVariableState<float>(this); } else { FloatValue = (BaseDataVariableState<float>)replacement; } } } instance = FloatValue; break; } case TestData.BrowseNames.DoubleValue: { if (createOrReplace) { if (DoubleValue == null) { if (replacement == null) { DoubleValue = new BaseDataVariableState<double>(this); } else { DoubleValue = (BaseDataVariableState<double>)replacement; } } } instance = DoubleValue; break; } case TestData.BrowseNames.StringValue: { if (createOrReplace) { if (StringValue == null) { if (replacement == null) { StringValue = new BaseDataVariableState<string>(this); } else { StringValue = (BaseDataVariableState<string>)replacement; } } } instance = StringValue; break; } case TestData.BrowseNames.DateTimeValue: { if (createOrReplace) { if (DateTimeValue == null) { if (replacement == null) { DateTimeValue = new BaseDataVariableState<DateTime>(this); } else { DateTimeValue = (BaseDataVariableState<DateTime>)replacement; } } } instance = DateTimeValue; break; } case TestData.BrowseNames.GuidValue: { if (createOrReplace) { if (GuidValue == null) { if (replacement == null) { GuidValue = new BaseDataVariableState<Guid>(this); } else { GuidValue = (BaseDataVariableState<Guid>)replacement; } } } instance = GuidValue; break; } case TestData.BrowseNames.ByteStringValue: { if (createOrReplace) { if (ByteStringValue == null) { if (replacement == null) { ByteStringValue = new BaseDataVariableState<byte[]>(this); } else { ByteStringValue = (BaseDataVariableState<byte[]>)replacement; } } } instance = ByteStringValue; break; } case TestData.BrowseNames.XmlElementValue: { if (createOrReplace) { if (XmlElementValue == null) { if (replacement == null) { XmlElementValue = new BaseDataVariableState<XmlElement>(this); } else { XmlElementValue = (BaseDataVariableState<XmlElement>)replacement; } } } instance = XmlElementValue; break; } case TestData.BrowseNames.NodeIdValue: { if (createOrReplace) { if (NodeIdValue == null) { if (replacement == null) { NodeIdValue = new BaseDataVariableState<NodeId>(this); } else { NodeIdValue = (BaseDataVariableState<NodeId>)replacement; } } } instance = NodeIdValue; break; } case TestData.BrowseNames.ExpandedNodeIdValue: { if (createOrReplace) { if (ExpandedNodeIdValue == null) { if (replacement == null) { ExpandedNodeIdValue = new BaseDataVariableState<ExpandedNodeId>(this); } else { ExpandedNodeIdValue = (BaseDataVariableState<ExpandedNodeId>)replacement; } } } instance = ExpandedNodeIdValue; break; } case TestData.BrowseNames.QualifiedNameValue: { if (createOrReplace) { if (QualifiedNameValue == null) { if (replacement == null) { QualifiedNameValue = new BaseDataVariableState<QualifiedName>(this); } else { QualifiedNameValue = (BaseDataVariableState<QualifiedName>)replacement; } } } instance = QualifiedNameValue; break; } case TestData.BrowseNames.LocalizedTextValue: { if (createOrReplace) { if (LocalizedTextValue == null) { if (replacement == null) { LocalizedTextValue = new BaseDataVariableState<LocalizedText>(this); } else { LocalizedTextValue = (BaseDataVariableState<LocalizedText>)replacement; } } } instance = LocalizedTextValue; break; } case TestData.BrowseNames.StatusCodeValue: { if (createOrReplace) { if (StatusCodeValue == null) { if (replacement == null) { StatusCodeValue = new BaseDataVariableState<StatusCode>(this); } else { StatusCodeValue = (BaseDataVariableState<StatusCode>)replacement; } } } instance = StatusCodeValue; break; } case TestData.BrowseNames.VariantValue: { if (createOrReplace) { if (VariantValue == null) { if (replacement == null) { VariantValue = new BaseDataVariableState(this); } else { VariantValue = (BaseDataVariableState)replacement; } } } instance = VariantValue; break; } case TestData.BrowseNames.EnumerationValue: { if (createOrReplace) { if (EnumerationValue == null) { if (replacement == null) { EnumerationValue = new BaseDataVariableState<int>(this); } else { EnumerationValue = (BaseDataVariableState<int>)replacement; } } } instance = EnumerationValue; break; } case TestData.BrowseNames.StructureValue: { if (createOrReplace) { if (StructureValue == null) { if (replacement == null) { StructureValue = new BaseDataVariableState<ExtensionObject>(this); } else { StructureValue = (BaseDataVariableState<ExtensionObject>)replacement; } } } instance = StructureValue; break; } case TestData.BrowseNames.NumberValue: { if (createOrReplace) { if (NumberValue == null) { if (replacement == null) { NumberValue = new BaseDataVariableState(this); } else { NumberValue = (BaseDataVariableState)replacement; } } } instance = NumberValue; break; } case TestData.BrowseNames.IntegerValue: { if (createOrReplace) { if (IntegerValue == null) { if (replacement == null) { IntegerValue = new BaseDataVariableState(this); } else { IntegerValue = (BaseDataVariableState)replacement; } } } instance = IntegerValue; break; } case TestData.BrowseNames.UIntegerValue: { if (createOrReplace) { if (UIntegerValue == null) { if (replacement == null) { UIntegerValue = new BaseDataVariableState(this); } else { UIntegerValue = (BaseDataVariableState)replacement; } } } instance = UIntegerValue; break; } } if (instance != null) { return instance; } return base.FindChild(context, browseName, createOrReplace, replacement); }