/// <summary> /// Displays the address space with the specified view /// </summary> public void Show(Session session, NodeId startId) { if (session == null) throw new ArgumentNullException("session"); if (m_session != null) { m_session.SessionClosing -= m_SessionClosing; } m_session = session; m_session.SessionClosing += m_SessionClosing; Browser browser = new Browser(session); browser.BrowseDirection = BrowseDirection.Both; browser.ContinueUntilDone = true; browser.ReferenceTypeId = ReferenceTypeIds.References; BrowseCTRL.Initialize(browser, startId); UpdateNavigationBar(); Show(); BringToFront(); }
/// <summary> /// Prompts the user to edit a value. /// </summary> public Variant ShowDialog(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; #region Task #B2 - Write Value // generate a default value based on the data type. m_value = Variant.Null; m_sourceType = GetExpectedType(session, nodeId); if (m_sourceType != null) { m_value = new Variant(TypeInfo.GetDefaultValue(m_sourceType.BuiltInType), m_sourceType); } // cast the value to a string. ValueTB.Text = (string)TypeInfo.Cast(m_value.Value, m_value.TypeInfo, BuiltInType.String); #endregion if (ShowDialog() != DialogResult.OK) { return Variant.Null; } return m_value; }
public static ReferenceDescriptionCollection Browse(Session session, BrowseDescription nodeToBrowse, bool throwOnError) { try { var descriptionCollection = new ReferenceDescriptionCollection(); var nodesToBrowse = new BrowseDescriptionCollection { nodeToBrowse }; BrowseResultCollection results; DiagnosticInfoCollection diagnosticInfos; session.Browse(null, null, 0U, nodesToBrowse, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); while (!StatusCode.IsBad(results[0].StatusCode)) { for (var index = 0; index < results[0].References.Count; ++index) descriptionCollection.Add(results[0].References[index]); if (results[0].References.Count == 0 || results[0].ContinuationPoint == null) return descriptionCollection; var continuationPoints = new ByteStringCollection(); continuationPoints.Add(results[0].ContinuationPoint); session.BrowseNext(null, false, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, continuationPoints); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints); } throw new ServiceResultException(results[0].StatusCode); } catch (Exception ex) { if (throwOnError) throw new ServiceResultException(ex, 2147549184U); return null; } }
/// <summary> /// Displays the dialog. /// </summary> public void Show(Session session, NodeId objectId, NodeId methodId) { if (session == null) throw new ArgumentNullException("session"); if (methodId == null) throw new ArgumentNullException("methodId"); if (m_session != null) { m_session.SessionClosing -= m_SessionClosing; } m_session = session; m_session.SessionClosing += m_SessionClosing; m_objectId = objectId; m_methodId = methodId; InputArgumentsCTRL.Update(session, methodId, true); OutputArgumentsCTRL.Update(session, methodId, false); Node target = session.NodeCache.Find(objectId) as Node; Node method = session.NodeCache.Find(methodId) as Node; if (target != null && method != null) { Text = String.Format("Call {0}.{1}", target, method); } Show(); BringToFront(); }
/// <summary> /// Prompts the user to specify the browse options. /// </summary> public bool ShowDialog(Session session, ReadValueId valueId) { if (session == null) throw new ArgumentNullException("session"); if (valueId == null) throw new ArgumentNullException("valueId"); NodeIdCTRL.Browser = new Browser(session); INode node = session.NodeCache.Find(valueId.NodeId); if (node != null) { DisplayNameTB.Text = node.ToString(); } NodeIdCTRL.Identifier = valueId.NodeId; AttributeIdCB.SelectedItem = Attributes.GetBrowseName(valueId.AttributeId); IndexRangeTB.Text = valueId.IndexRange; EncodingCB.Text = (valueId.DataEncoding != null)?valueId.DataEncoding.Name:null; if (ShowDialog() != DialogResult.OK) { return false; } valueId.NodeId = NodeIdCTRL.Identifier; valueId.AttributeId = Attributes.GetIdentifier((string)AttributeIdCB.SelectedItem); valueId.IndexRange = IndexRangeTB.Text; if (String.IsNullOrEmpty(EncodingCB.Text)) { valueId.DataEncoding = new QualifiedName(EncodingCB.Text); } return true; }
/// <summary> /// Sets the nodes in the control. /// </summary> public void Initialize(Session session, NodeIdCollection nodeIds, NodeClass nodeClassMask) { if (session == null) throw new ArgumentNullException("session"); Clear(); m_session = session; m_nodeIds = nodeIds; m_nodeClassMask = (nodeClassMask == 0)?(NodeClass)Byte.MaxValue:nodeClassMask; if (nodeIds == null) { return; } foreach (NodeId nodeId in nodeIds) { INode node = m_session.NodeCache.Find(nodeId); if (node != null && (m_nodeClassMask & node.NodeClass) != 0) { AddItem(node, "Property", -1); } } AdjustColumns(); }
/// <summary> /// Updates the list control. /// </summary> private void UpdateList(Session session, Argument[] arguments, string browseName) { for (int ii = 0; ii < arguments.Length; ii++) { Argument argument = arguments[ii]; Variant defaultValue = new Variant(TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank)); ListViewItem item = new ListViewItem(arguments[ii].Name); if (browseName == BrowseNames.InputArguments) { item.SubItems.Add("IN"); m_firstOutputArgument++; } else { item.SubItems.Add("OUT"); } string dataType = session.NodeCache.GetDisplayText(arguments[ii].DataType); if (arguments[ii].ValueRank >= 0) { dataType += "[]"; } item.SubItems.Add(defaultValue.ToString()); item.SubItems.Add(dataType); item.SubItems.Add(Utils.Format("{0}", arguments[ii].Description)); item.Tag = defaultValue; ArgumentsLV.Items.Add(item); } }
public void Show(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; Show(); }
/// <summary> /// Prompts the user to specify the browse options. /// </summary> public bool ShowDialog(Session session, WriteValue value) { if (session == null) throw new ArgumentNullException("session"); if (value == null) throw new ArgumentNullException("value"); NodeIdCTRL.Browser = new Browser(session); INode node = session.NodeCache.Find(value.NodeId); if (node != null) { DisplayNameTB.Text = node.ToString(); } NodeIdCTRL.Identifier = value.NodeId; AttributeIdCB.SelectedItem = Attributes.GetBrowseName(value.AttributeId); IndexRangeTB.Text = value.IndexRange; if (ShowDialog() != DialogResult.OK) { return false; } value.NodeId = NodeIdCTRL.Identifier; value.AttributeId = Attributes.GetIdentifier((string)AttributeIdCB.SelectedItem); value.IndexRange = IndexRangeTB.Text; return true; }
/// <summary> /// Sets the nodes in the control. /// </summary> public void Initialize(Session session, ExpandedNodeId nodeId) { if (session == null) throw new ArgumentNullException("session"); Clear(); if (nodeId == null) { return; } m_session = session; m_nodeId = (NodeId)nodeId; INode node = m_session.NodeCache.Find(m_nodeId); if (node != null && (node.NodeClass & (NodeClass.Variable | NodeClass.Object)) != 0) { AddReferences(ReferenceTypeIds.HasTypeDefinition, BrowseDirection.Forward); AddReferences(ReferenceTypeIds.HasModellingRule, BrowseDirection.Forward); } AddAttributes(); AddProperties(); }
/// <summary> /// Initializes the control with a root and a set of hierarchial reference types to follow. /// </summary> /// <param name="session">The session.</param> /// <param name="rootId">The root of the hierarchy to browse.</param> /// <param name="referenceTypeIds">The reference types to follow.</param> public void Initialize( Session session, NodeId rootId, params NodeId[] referenceTypeIds) { BrowseCTRL.Initialize(session, rootId, referenceTypeIds); }
/// <summary> /// Creates a new subscription. /// </summary> public Subscription New(Session session) { if (session == null) throw new ArgumentNullException("session"); Subscription subscription = new Subscription(session.DefaultSubscription); if (!new SubscriptionEditDlg().ShowDialog(subscription)) { return null; } session.AddSubscription(subscription); subscription.Create(); Subscription duplicateSubscription = session.Subscriptions.FirstOrDefault(s => s.Id != 0 && s.Id.Equals(subscription.Id) && s != subscription); if (duplicateSubscription != null) { Utils.Trace("Duplicate subscription was created with the id: {0}", duplicateSubscription.Id); DialogResult result = MessageBox.Show("Duplicate subscription was created with the id: " + duplicateSubscription.Id + ". Do you want to keep it?", "Warning", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { duplicateSubscription.Delete(false); session.RemoveSubscription(subscription); return null; } } Show(subscription); return subscription; }
/// <summary> /// Displays the available areas in a tree view. /// </summary> /// <param name="session">The session.</param> /// <returns></returns> public NodeId ShowDialog(Session session) { m_session = session; TreeNode root = new TreeNode(BrowseNames.Server); root.Nodes.Add(new TreeNode()); BrowseTV.Nodes.Add(root); root.Expand(); // display the dialog. if (ShowDialog() != DialogResult.OK) { return null; } // ensure selection is valid. if (BrowseTV.SelectedNode == null) { return null; } // get the selection. ReferenceDescription reference = (ReferenceDescription)BrowseTV.SelectedNode.Tag; if (reference == null) { return ObjectIds.Server; } // return the result. return (NodeId)reference.NodeId; }
/// <summary> /// Prompts the user to specify the browse options. /// </summary> public bool ShowDialog(Session session, MonitoredItem monitoredItem) { if (monitoredItem == null) throw new ArgumentNullException("monitoredItem"); DataChangeFilter filter = monitoredItem.Filter as DataChangeFilter; if (filter == null) { filter = new DataChangeFilter(); filter.Trigger = DataChangeTrigger.StatusValue; filter.DeadbandValue = 0; filter.DeadbandType = (uint)(int)DeadbandType.None; } TriggerCB.SelectedItem = filter.Trigger; DeadbandTypeCB.SelectedItem = (DeadbandType)(int)filter.DeadbandType; DeadbandNC.Value = (decimal)filter.DeadbandValue; if (ShowDialog() != DialogResult.OK) { return false; } filter.Trigger = (DataChangeTrigger)TriggerCB.SelectedItem; filter.DeadbandType = Convert.ToUInt32(DeadbandTypeCB.SelectedItem); filter.DeadbandValue = (double)DeadbandNC.Value; monitoredItem.Filter = filter; return true; }
internal static NodeId FindCurrentNode( string level, Opc.Ua.Client.Session session, ConfiguredEndpoint endpoint ) { NodeId curNode; if (string.IsNullOrEmpty(level)) { // Set the default root OPC node id to look at the objects curNode = Objects.ObjectsFolder; } else { // need to decode the level to get the NodeId string source; if (level.StartsWith(UAurlIdentifier + "=")) { source = getNSIStringfromNSURLString(level, session); } else { source = level; } //curNode = (NodeId)source; curNode = GetNodeId(source, false, session, endpoint); } return(curNode); }
/// <summary> /// Initializes the test with session, configuration and logger. /// </summary> public TestBase( string name, Session session, ServerTestConfiguration configuration, ReportMessageEventHandler reportMessage, ReportProgressEventHandler reportProgress, TestBase template) { m_name = name; m_session = session; m_configuration = configuration; m_reportMessage = reportMessage; m_reportProgress = reportProgress; if (template != null && Object.ReferenceEquals(session, template.m_session)) { m_blockSize = template.BlockSize; m_availableNodes = template.m_availableNodes; m_writeableVariables = template.m_writeableVariables; } else { m_blockSize = 1000; m_availableNodes = new NodeIdDictionary<Node>(); m_writeableVariables = new List<VariableNode>(); } }
/// <summary> /// Creates the monitored item based on the current definition. /// </summary> /// <param name="session">The session.</param> /// <returns>The monitored item.</returns> public MonitoredItem CreateMonitoredItem(Session session) { // choose the server object by default. if (AreaId == null) { AreaId = ObjectIds.Server; } // create the item with the filter. MonitoredItem monitoredItem = new MonitoredItem(); monitoredItem.DisplayName = null; monitoredItem.StartNodeId = AreaId; monitoredItem.RelativePath = null; monitoredItem.NodeClass = NodeClass.Object; monitoredItem.AttributeId = Attributes.EventNotifier; monitoredItem.IndexRange = null; monitoredItem.Encoding = null; monitoredItem.MonitoringMode = MonitoringMode.Reporting; monitoredItem.SamplingInterval = 0; monitoredItem.QueueSize = UInt32.MaxValue; monitoredItem.DiscardOldest = true; monitoredItem.Filter = ConstructFilter(session); // save the definition as the handle. monitoredItem.Handle = this; return monitoredItem; }
/// <summary> /// Updates the list of references. /// </summary> private void UpdateList(Session session, NodeId nodeId) { m_nodeId = nodeId; ReferencesLV.Items.Clear(); List<ReferenceDescription> references = Browse(session, nodeId); DisplayReferences(session, references); }
/// <summary> /// Prompts the user to view or edit the value. /// </summary> public object ShowDialog( Session session, NodeId nodeId, uint attributeId, string name, object value, bool readOnly, string caption) { if (!String.IsNullOrEmpty(caption)) { this.Text = caption; } OkBTN.Visible = !readOnly; ValueCTRL.ChangeSession(session); ValueCTRL.ShowValue(nodeId, attributeId, name, value, readOnly); if (base.ShowDialog() != DialogResult.OK) { return null; } return ValueCTRL.GetValue(); }
/// <summary> /// Initializes a new instance of the <see cref="AuditEventForm"/> class. /// </summary> /// <param name="session">The session.</param> /// <param name="subscription">The subscription.</param> public AuditEventForm(Session session, Subscription subscription) { InitializeComponent(); m_session = session; m_subscription = subscription; // a table used to track event types. m_eventTypeMappings = new Dictionary<NodeId, NodeId>(); // the filter to use. m_filter = new FilterDefinition(); m_filter.AreaId = ObjectIds.Server; m_filter.Severity = EventSeverity.Min; m_filter.IgnoreSuppressedOrShelved = true; m_filter.EventTypes = new NodeId[] { ObjectTypeIds.AuditUpdateMethodEventType }; // find the fields of interest. m_filter.SelectClauses = m_filter.ConstructSelectClauses(m_session, ObjectTypeIds.AuditUpdateMethodEventType); // declate callback. m_MonitoredItem_Notification = new MonitoredItemNotificationEventHandler(MonitoredItem_Notification); // create a monitored item based on the current filter settings. m_monitoredItem = m_filter.CreateMonitoredItem(m_session); // set up callback for notifications. m_monitoredItem.Notification += m_MonitoredItem_Notification; m_subscription.AddItem(m_monitoredItem); m_subscription.ApplyChanges(); }
/// <summary> /// Browses up. /// </summary> /// <param name="session">The session.</param> public void BrowseUp(Session session) { TraceState("BrowseUp"); // find the id of the current node. string itemId = null; lock (m_lock) { // check if already at root. if (m_browsePosition == null || String.IsNullOrEmpty(m_browsePosition.ItemId)) { throw ComUtils.CreateComException(ResultIds.E_FAIL); } itemId = m_browsePosition.ItemId; } // find the parent - revert to root if parent does not exist. ComDaBrowseElement parent = m_cache.FindParent(session, itemId); lock (m_lock) { m_browsePosition = parent; } }
/// <summary> /// Prompts the user to edit an annotation. /// </summary> public Annotation ShowDialog(Session session, Annotation annotation, string caption) { if (caption != null) { this.Text = caption; } m_session = session; if (annotation == null) { annotation = new Annotation(); annotation.AnnotationTime = DateTime.UtcNow; annotation.UserName = Environment.GetEnvironmentVariable("USERNAME"); annotation.Message = "<insert your message here>"; } AnnotationTimeDP.Value = annotation.AnnotationTime; UserNameTB.Text = annotation.UserName; CommentTB.Text = annotation.Message; if (ShowDialog() != DialogResult.OK) { return null; } annotation = new Annotation(); annotation.AnnotationTime = AnnotationTimeDP.Value; annotation.UserName = UserNameTB.Text; annotation.Message = CommentTB.Text; return annotation; }
/// <summary> /// Initializes the object with default values. /// </summary> public NodeCache(Session session) { if (session == null) throw new ArgumentNullException("session"); m_session = session; m_typeTree = new TypeTable(m_session.NamespaceUris); m_nodes = new NodeTable(m_session.NamespaceUris, m_session.ServerUris, m_typeTree); }
public void Show(Session session, NodeId objectId, NodeId methodId) { m_session = session; m_objectId = objectId; m_methodId = methodId; Show(); }
private void Session_Closing(object sender, EventArgs e) { if (Object.ReferenceEquals(sender, m_session)) { m_session.SessionClosing -= m_SessionClosing; m_session = null; } }
/// <summary> /// Creates the test object. /// </summary> public TranslatePathTest( Session session, ServerTestConfiguration configuration, ReportMessageEventHandler reportMessage, ReportProgressEventHandler reportProgress, TestBase template) : base("TranslatePath", session, configuration, reportMessage, reportProgress, template) { }
/// <summary> /// Sets the nodes in the control. /// </summary> public bool Update(Session session, NodeId methodId, bool inputArgs) { if (session == null) throw new ArgumentNullException("session"); if (methodId == null) throw new ArgumentNullException("methodId"); Clear(); m_session = session; // find the method. MethodNode method = session.NodeCache.Find(methodId) as MethodNode; if (method == null) { return false; } // select the property to find. QualifiedName browseName = null; if (inputArgs) { browseName = Opc.Ua.BrowseNames.InputArguments; } else { browseName = Opc.Ua.BrowseNames.OutputArguments; } // fetch the argument list. VariableNode argumentsNode = session.NodeCache.Find(methodId, ReferenceTypeIds.HasProperty, false, true, browseName) as VariableNode; if (argumentsNode == null) { return false; } // read the value from the server. DataValue value = m_session.ReadValue(argumentsNode.NodeId); ExtensionObject[] argumentsList = value.Value as ExtensionObject[]; if (argumentsList != null) { for (int ii = 0; ii < argumentsList.Length; ii++) { AddItem(argumentsList[ii].Body as Argument); } } AdjustColumns(); return ItemsLV.Items.Count > 0; }
/// <summary> /// Displays the dialog. /// </summary> public void Show(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; #region Task #B3 - Subscribe Data CreateSubscription(); #endregion Show(); }
//private ILocalNode m_selectedType; #endregion #region Public Interface /// <summary> /// Displays the dialog. /// </summary> public void Show( Session session, NodeId typeId) { if (session == null) throw new ArgumentNullException("session"); m_session = session; //TypeNavigatorCTRL.Initialize(m_session, typeId); //TypeHierarchyCTRL.Initialize(m_session, typeId); }
/// <summary> /// Displays a dialog that allows a use to edit a value. /// </summary> public static object EditValue(Session session, object value) { TypeInfo typeInfo = TypeInfo.Construct(value); if (typeInfo != null) { return EditValue(session, value, (uint)typeInfo.BuiltInType, typeInfo.ValueRank); } return null; }
/// <summary> /// Initializes the object with the default values /// </summary> /// <param name="server">The server associated with the browser</param> /// <param name="session">The session associated with the browser</param> public AreaBrowser(ComAeProxy server, Session session) { m_server = server; m_session = session; // ensure browse stack has been initialized. if (m_browseStack.Count == 0) { INode parent = m_session.NodeCache.Find(Objects.Server); m_browseStack.Push(parent); } }
internal static string getNSUrlStringfromNodeId(NodeId nodeId, Opc.Ua.Client.Session session) { if (nodeId == null || nodeId.IsNullNodeId) { return(string.Empty); } string[] idSeparatorArray = { getNSIshortCutfromIDType(nodeId.IdType) }; string nodeIDString = nodeId.ToString(); if (nodeId.NamespaceIndex != 0) { // Hack. Remvove 'ns' from the beginning of the string so there is no collision with the later search for "s=" // only needed for nodeId.idType == String nodeIDString = nodeIDString.Substring(2); } string[] idParts = nodeIDString.Split(idSeparatorArray, StringSplitOptions.RemoveEmptyEntries); string[] idParts2 = nodeIDString.Split(idSeparatorArray, StringSplitOptions.None); string result = String.Empty; // we expect one string in case ns=0, two otherwise // in case ns=0, empty identifier is not allowed, otherwise it is // learnt this at Opc IOP Nürnberg 201411 if (!((idParts.Length == 1 && nodeId.NamespaceIndex == 0) || idParts.Length == 2)) { if (idParts2.Length == idParts.Length || nodeId.NamespaceIndex == 0) { // OPC IOW 2014 // some parts of the nodeid string are empty. This is allowed (according to // personal communication with Randy Newman) if !ns==0 throw (new ApplicationException("invalid String Representation of UA node")); } result = UAurlIdentifier + "=" + session.NodeCache.NamespaceUris.GetString(nodeId.NamespaceIndex) + ";" + idSeparatorArray[0]; return(result); } result = UAurlIdentifier + "=" + session.NodeCache.NamespaceUris.GetString(nodeId.NamespaceIndex) + ";" + idSeparatorArray[0] + idParts[idParts.Length - 1]; return(result); }
private static async Task RunClient(string address) { var clientApp = new ApplicationInstance { ApplicationName = "OPC UA StackOverflow Example Client", ApplicationType = ApplicationType.Client, ConfigSectionName = "Opc.Client" }; // load the application configuration. var clientConfig = await clientApp.LoadApplicationConfiguration(true); var haveClientAppCertificate = await clientApp.CheckApplicationInstanceCertificate(true, 0); if (!haveClientAppCertificate) { throw new Exception("Application instance certificate invalid!"); } var endpointConfiguration = EndpointConfiguration.Create(clientConfig); var selectedEndpoint = CoreClientUtils.SelectEndpoint(address, true, 15000); var endpoint = new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration); using (var session = await Session.Create(clientConfig, endpoint, false, clientConfig.ApplicationName, 60000, new UserIdentity(new AnonymousIdentityToken()), null)) { Console.WriteLine("Client connected"); var rootFolders = await session.BrowseAsync(ObjectIds.ObjectsFolder); Console.WriteLine("Received root folders"); var childFolders = await Task.WhenAll( from root in rootFolders select session.BrowseAsync(ExpandedNodeId.ToNodeId(root.NodeId, session.NamespaceUris))); foreach (var childFolder in childFolders.SelectMany(x => x).OrderBy(c => c.BrowseName.Name)) { Console.WriteLine(childFolder.BrowseName.Name); } Console.WriteLine("Client disconnecting"); session.Close(); Console.WriteLine("Client disconnected"); } Console.WriteLine("Client disposed"); }
internal static string getNSIStringfromNSURLString(string nsurlString, Opc.Ua.Client.Session clientSession, Dictionary <int, string> nameSpaceIndexDict = null) { if (nsurlString == null || nsurlString.Equals(string.Empty)) { return(nsurlString); } string[] firstDecomposition = nsurlString.Split(UANodeIDFirstSeparatorSingle, 2); if (firstDecomposition.Length != 2 || !UAurlIdentifier.Equals(firstDecomposition[0])) { throw new ApplicationException("Invalid input when converting namespace URL to namespace index)"); } string[] secondDecomposition = firstDecomposition[1].Split(UANodeIDSecondSeparatorSingle, 2); if (secondDecomposition.Length != 2 || secondDecomposition[1].Length < 2) { throw new ApplicationException("Invalid input when converting namespace URL to namespace index)"); } // verify the last part begins with "i=", "s=", "g=" or "b=" string idTypeID = secondDecomposition[1].Trim().Substring(0, 2); if (!(UANodeIDIDidentifier.Any(s => idTypeID.Equals(s)))) { throw new ApplicationException("Invalid input when converting namespace URL to namespace index: no valid IdType detected)"); } if (nameSpaceIndexDict == null) { int nsindex = clientSession.NamespaceUris.GetIndex(secondDecomposition[0]); if (nsindex < 0) { throw new ApplicationException("Invalid input when converting namespace URL to namespace index: namespace index is negative)"); } return(UAnsIdentifier + "=" + nsindex.ToString() + ";" + secondDecomposition[1]); } else { // the index is unique or there is an error. int index = nameSpaceIndexDict.FirstOrDefault(x => x.Value.Equals(secondDecomposition[0])).Key; return(UAnsIdentifier + "=" + index.ToString() + ";" + secondDecomposition[1]); } }
public static Task <ReferenceDescriptionCollection> BrowseAsync(this Session session, NodeId nodeToBrowse) { return(Task.Factory.FromAsync( (callback, state) => session.BeginBrowse( null, null, nodeToBrowse, 0, BrowseDirection.Forward, ReferenceTypeIds.Organizes, false, (uint)NodeClass.Object, callback, state), result => { session.EndBrowse(result, out var continuationPoint, out var references); return references; },
private async Task <Opc.Ua.Client.Session> createSession(string url) { // select the best endpoint. EndpointDescription endpointDescription = CoreClientUtils.SelectEndpoint(url, true, 5000); EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(m_configuration); ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration); UserIdentity user = new UserIdentity(); Opc.Ua.Client.Session session = await Opc.Ua.Client.Session.Create( m_configuration, endpoint, false, false, "Collector Server", 60000, user, null); return(session); }
public static NodeId GetNodeId(string source, bool firstOnly, Opc.Ua.Client.Session session, ConfiguredEndpoint endpoint) { NodeId nodeId = null; try { // Determine Node Id // if the tag comes from a persisted cache element, it may start with "nsurl=" if (source.StartsWith(UAurlIdentifier + "=")) { source = getNSIStringfromNSURLString(source, session); } // in some cases we can shortcut: ns=ABC or i=2253 etc. or Channel1.Device1.Tag_1 are already Node Ids if (source.Contains(UaNodeIdHintEqual) || (source.Contains(UaNodeIdHintPeriod))) { nodeId = (NodeId)source; } } catch (ServiceResultException srex) { if ((srex.StatusCode == StatusCodes.BadCommunicationError) || (srex.StatusCode == StatusCodes.BadConnectionClosed)) { //ConfiguredEndpoint endpoint = (ConfiguredEndpoint)this.agentInstance.SourceChannel.Aspects[OpcUaAgent.SessionConfigurationAspectName] // .Properties[OpcUaAgent.SessionEndpointProperty].BinaryValue.Value; } } catch (Exception ex) { throw new ArgumentException("Unable to determine Node Id from source path ", source, ex); } return(nodeId); }
private async Task FindObjects(Opc.Ua.Client.Session session, NodeId nodeid) { if (session == null) { return; } try { ReferenceDescriptionCollection references; Byte[] continuationPoint; if (NodeIdsFromObjects.Contains(nodeid.ToString())) { return; } session.Browse( null, null, nodeid, 0u, BrowseDirection.Forward, ReferenceTypeIds.HierarchicalReferences, true, (uint)NodeClass.Variable | (uint)NodeClass.Object, out continuationPoint, out references); foreach (var rd in references) { Log(conn_name + " - " + rd.NodeId + ", " + rd.DisplayName + ", " + rd.BrowseName + ", " + rd.NodeClass); if (rd.NodeClass == NodeClass.Variable && !NodeIds.Contains(rd.NodeId.ToString())) { NodeIds.Add(rd.NodeId.ToString()); ListMon.Add( new MonitoredItem() { DisplayName = rd.DisplayName.ToString(), StartNodeId = rd.NodeId.ToString(), SamplingInterval = System.Convert.ToInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagSamplingInterval) * 1000), QueueSize = System.Convert.ToUInt32(OPCUA_conn.autoCreateTagQueueSize), MonitoringMode = MonitoringMode.Reporting, DiscardOldest = true, AttributeId = Attributes.Value }); } else if (rd.NodeClass == NodeClass.Object) { NodeIdsFromObjects.Add(nodeid.ToString()); await FindObjects(session, ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris)); Thread.Yield(); //Thread.Sleep(1); //await Task.Delay(1); } } } catch (Exception ex) { Log(conn_name + " - " + ex.Message); } }