// Get all nodes excluding Server Node in the references Collection private void GetTanks() { BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = Opc.Ua.ObjectIds.ObjectsFolder; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences; nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.NodeClassMask = (uint)(NodeClass.Object); nodeToBrowse.ResultMask = (uint)(BrowseResultMask.All); ReferenceDescriptionCollection references = ClientUtils.Browse( m_session, nodeToBrowse, false); if (references != null) { for (int ii = 0; ii < references.Count; ii++) { // do not add Server node if (!references[ii].BrowseName.Name.Equals("Server")) { tanksRef.Add(references[ii]); } } } }
/// <summary> /// Updates the application after connecting to or disconnecting from the server. /// </summary> private void Server_ConnectComplete(object sender, EventArgs e) { try { m_session = ConnectServerCTRL.Session; // set a suitable initial state. if (m_session != null && !m_connectedOnce) { m_connectedOnce = true; BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = Opc.Ua.ObjectIds.ViewsFolder; nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences; nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.NodeClassMask = 0; nodeToBrowse.ResultMask = (uint)BrowseResultMask.All; ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, nodeToBrowse, false); ViewCB.Items.Clear(); ViewCB.Items.Add(new ReferenceDescription() { NodeId = ExpandedNodeId.Null, DisplayName = "None" }); if (references != null) { for (int ii = 0; ii < references.Count; ii++) { ViewCB.Items.Add(references[ii]); } } ViewCB.SelectedIndex = 0; } // browse the instances in the server. BrowseCTRL.Initialize(m_session, ObjectIds.ObjectsFolder, ReferenceTypeIds.Organizes, ReferenceTypeIds.Aggregates); } catch (Exception exception) { ClientUtils.HandleException(this.Text, exception); } }
private void GetTanks() { BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = Opc.Ua.ObjectIds.ObjectsFolder; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences; nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.NodeClassMask = (uint)(NodeClass.Object); nodeToBrowse.ResultMask = (uint)(BrowseResultMask.All); ReferenceDescriptionCollection references = ClientUtils.Browse( m_session, nodeToBrowse, false); ReferenceDescription tank = null; if (references != null) { for (int ii = 1; ii < references.Count; ii++) { //tanks.Add(references[ii]); tank = references[ii]; } } NamespaceTable wellKnownNamespaceUris = new NamespaceTable(); string[] browsePaths = new string[] { "1:Level", "2:Temperature" }; List <NodeId> nodes = ClientUtils.TranslateBrowsePaths( m_session, (NodeId)tank.NodeId, wellKnownNamespaceUris, browsePaths); }
/// <summary> /// Gets the boilers. /// </summary> private void GetBoilers() { BoilerCB.Items.Clear(); BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = Opc.Ua.ObjectIds.ObjectsFolder; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences; nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.NodeClassMask = (uint)(NodeClass.Object); nodeToBrowse.ResultMask = (uint)(BrowseResultMask.All); ReferenceDescriptionCollection references = ClientUtils.Browse( m_session, nodeToBrowse, false); if (references != null) { NodeId boilerTypeId = ExpandedNodeId.ToNodeId(ObjectTypeIds.BoilerType, m_session.NamespaceUris); for (int ii = 0; ii < references.Count; ii++) { if (boilerTypeId == references[ii].TypeDefinition) { BoilerCB.Items.Add(references[ii]); } } if (BoilerCB.Items.Count > 0) { BoilerCB.SelectedIndex = 0; } } }
private void subscribeToolStripMenuItem_Click(object sender, EventArgs e) { if ((NodeId)BrowseCTRL.SelectedNode.NodeId != null) { if (subscriptionOutputWindow == null) { subscriptionOutputWindow = new SubscriptionOutput(); } if (m_subscription == null) { m_subscription = new Subscription(m_session.DefaultSubscription); m_subscription.PublishingEnabled = true; m_subscription.PublishingInterval = 1000; m_session.AddSubscription(m_subscription); m_subscription.Create(); } if (monitoredItems.Count == 0) { if (BrowseCTRL.GetChildOfSelectedNode(0) != null) { BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = (NodeId)BrowseCTRL.SelectedNode.NodeId; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences; nodeToBrowse.IncludeSubtypes = true; //nodeToBrowse.NodeClassMask = (uint)(NodeClass.Object); nodeToBrowse.ResultMask = (uint)(BrowseResultMask.All); ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, nodeToBrowse, false); subscriptionOutputWindow.label1.Text = "You selected a folder: these are the child nodes:\n"; foreach (var item in references) { var mi = new MonitoredItem(m_subscription.DefaultItem); mi.StartNodeId = (NodeId)item.NodeId; mi.AttributeId = Attributes.DisplayName; mi.MonitoringMode = MonitoringMode.Reporting; mi.SamplingInterval = 1000; mi.QueueSize = 0; mi.DiscardOldest = true; mi.Notification += new MonitoredItemNotificationEventHandler(Mi_Notification); monitoredItems.Add(mi); } } else { var mi = new MonitoredItem(m_subscription.DefaultItem); mi.StartNodeId = (NodeId)BrowseCTRL.SelectedNode.NodeId; mi.AttributeId = Attributes.Value; mi.MonitoringMode = MonitoringMode.Reporting; mi.SamplingInterval = 1000; mi.QueueSize = 0; mi.DiscardOldest = true; mi.Notification += new MonitoredItemNotificationEventHandler(Mi_Notification); // define event handler for this item, and then add to subscription mi.Notification += new MonitoredItemNotificationEventHandler(monitoredItem_Notification); monitoredItems.Add(mi); } m_subscription.AddItems(monitoredItems); } subscriptionOutputWindow.Show(); subscriptionOutputWindow.FormClosed += OutputWindow_FormClosed; m_subscription.ApplyChanges(); } }
/// <summary> /// Updates the application after connecting to or disconnecting from the server. /// </summary> private void Server_ConnectComplete(object sender, EventArgs e) { try { m_session = ConnectServerCTRL.Session; if (m_session == null) { return; } // set a suitable initial state. if (m_session != null && !m_connectedOnce) { m_connectedOnce = true; EventsLV.IsSubscribed = false; EventsLV.DisplayConditions = true; EventsLV.ChangeArea(Opc.Ua.ObjectIds.Server, false); FilterDeclaration filter = new FilterDeclaration(); ushort namespaceIndex = (ushort)m_session.NamespaceUris.GetIndex(DsatsDemo.Namespaces.DsatsDemo); filter.EventTypeId = ExpandedNodeId.ToNodeId(DsatsDemo.ObjectTypeIds.LockConditionType, m_session.NamespaceUris); filter.AddSimpleField(String.Empty, BuiltInType.NodeId, false); filter.AddSimpleField(Opc.Ua.BrowseNames.EventId, BuiltInType.ByteString, false); filter.AddSimpleField(Opc.Ua.BrowseNames.EventType, BuiltInType.NodeId, false); filter.AddSimpleField(Opc.Ua.BrowseNames.ConditionName, BuiltInType.String, true); filter.AddSimpleField(new QualifiedName[] { new QualifiedName(DsatsDemo.BrowseNames.LockState, namespaceIndex), new QualifiedName(Opc.Ua.BrowseNames.CurrentState) }, BuiltInType.String, ValueRanks.Scalar, true); filter.AddSimpleField(new QualifiedName(DsatsDemo.BrowseNames.ClientUserId, namespaceIndex), BuiltInType.String, true); filter.AddSimpleField(new QualifiedName(DsatsDemo.BrowseNames.SubjectName, namespaceIndex), BuiltInType.String, true); filter.AddSimpleField(new QualifiedName(DsatsDemo.BrowseNames.SessionId, namespaceIndex), BuiltInType.NodeId, true); EventsLV.ChangeFilter(filter, true); m_filter = filter; PhaseCB.Items.Clear(); BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = new NodeId(DsatsDemo.Objects.Rig_Phases, namespaceIndex); nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences; nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.ResultMask = (uint)BrowseResultMask.All; DataValue value = m_session.ReadValue(new NodeId(DsatsDemo.Variables.Rig_CurrentPhase, namespaceIndex)); NodeId currentPhase = value.GetValue <NodeId>(null); ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, nodeToBrowse, false); if (references != null) { for (int ii = 0; ii < references.Count; ii++) { PhaseCB.Items.Add(references[ii]); if (currentPhase == references[ii].NodeId) { PhaseCB.SelectedIndex = ii; } } } m_connectedOnce = true; } EventsLV.IsSubscribed = true; EventsLV.ChangeSession(m_session, true); EventsLV.ConditionRefresh(); } catch (Exception exception) { MessageBox.Show(exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddSubscription() { try { if (m_session == null) { return; } if (m_subscription != null) { m_session.RemoveSubscription(m_subscription); m_subscription = null; } m_subscription = new Subscription(); m_subscription.PublishingEnabled = true; m_subscription.PublishingInterval = 5000; m_subscription.Priority = 1; m_subscription.KeepAliveCount = 10; m_subscription.LifetimeCount = 20; m_subscription.MaxNotificationsPerPublish = 5000; m_session.AddSubscription(m_subscription); m_subscription.Create(); for (int ii = 0; ii < tanksRef.Count; ii++) { // filter the node (should be the tank) if (tanksRef[ii].BrowseName.Name.Contains(TankDataTypes.tanks)) { BrowseDescription n = new BrowseDescription(); n.NodeId = (NodeId)tanksRef[ii].NodeId; n.BrowseDirection = BrowseDirection.Forward; n.IncludeSubtypes = true; n.NodeClassMask = (uint)(NodeClass.Variable); n.ResultMask = (uint)(BrowseResultMask.All); ReferenceDescriptionCollection props = ClientUtils.Browse( m_session, n, false); if (props.Count > 0) { for (int jj = 0; jj < props.Count; jj++) { // filter the Properties of the tank if (TankDataTypes.containsProp(props[jj].DisplayName.Text)) { MonitoredItem monitoredItem = new MonitoredItem(); monitoredItem.StartNodeId = (NodeId)props[jj].NodeId; monitoredItem.DisplayName = props[jj].BrowseName.Name; monitoredItem.AttributeId = Attributes.Value; monitoredItem.Notification += new MonitoredItemNotificationEventHandler(monitoredItem_Notification); m_subscription.AddItem(monitoredItem); } } } } } m_subscription.ApplyChanges(); } catch (Exception exception) { Console.WriteLine(exception); } }