Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Commit 53d5464

Browse files
No conversion to ExpandedNodeId for NodeId publishing requests via OPC
UA server methods.
1 parent 7cb875f commit 53d5464

File tree

4 files changed

+8
-33
lines changed

4 files changed

+8
-33
lines changed

src/OpcSession.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,8 @@ public async Task<bool> MonitorNodes(CancellationToken ct)
496496
NodeId currentNodeId = null;
497497
try
498498
{
499-
// update the namespace of the node if requested. there are two cases where this is requested:
500-
// 1) publishing requests via the OPC server method are raised using a NodeId format. for those
501-
// the NodeId format is converted into an ExpandedNodeId format
502-
// 2) ExpandedNodeId configuration file entries do not have at parsing time a session to get
503-
// the namespace index. this is set now.
499+
// update the namespace of the node if requested.this is required, because:
500+
// - ExpandedNodeId configuration file entries do not have at parsing time a session to get
504501
if (item.State == OpcMonitoredItemState.UnmonitoredNamespaceUpdateRequested)
505502
{
506503
if (item.ConfigType == OpcMonitoredItemConfigurationType.ExpandedNodeId)
@@ -515,19 +512,7 @@ public async Task<bool> MonitorNodes(CancellationToken ct)
515512
item.ConfigExpandedNodeId = new ExpandedNodeId(item.ConfigExpandedNodeId.Identifier, (ushort)namespaceIndex, item.ConfigExpandedNodeId?.NamespaceUri, 0);
516513
}
517514
}
518-
if (item.ConfigType == OpcMonitoredItemConfigurationType.NodeId)
519-
{
520-
string namespaceUri = GetNamespaceUri(item.ConfigNodeId.NamespaceIndex);
521-
if (string.IsNullOrEmpty(namespaceUri))
522-
{
523-
Trace($"The namespace index of node '{item.ConfigNodeId.ToString()}' is invalid and the node format could not be updated.");
524-
}
525-
else
526-
{
527-
item.ConfigExpandedNodeId = new ExpandedNodeId(item.ConfigNodeId.Identifier, item.ConfigNodeId.NamespaceIndex, namespaceUri, 0);
528-
item.ConfigType = OpcMonitoredItemConfigurationType.ExpandedNodeId;
529-
}
530-
}
515+
// for config type NodeId we do nothing
531516
item.State = OpcMonitoredItemState.Unmonitored;
532517
}
533518

@@ -885,7 +870,7 @@ public async Task AddNodeForMonitoring(NodeId nodeId, ExpandedNodeId expandedNod
885870
// add a new item to monitor
886871
if (expandedNodeId == null)
887872
{
888-
opcMonitoredItem = new OpcMonitoredItem(nodeId, EndpointUri, true);
873+
opcMonitoredItem = new OpcMonitoredItem(nodeId, EndpointUri);
889874
}
890875
else
891876
{

src/PublisherNodeConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public static async Task<List<PublisherConfigurationFileEntry>> GetPublisherConf
314314
}
315315
else
316316
{
317-
opcNodeOnEndpointUrl.ExpandedNodeId = monitoredItem.ConfigExpandedNodeId.ToString();
317+
opcNodeOnEndpointUrl.ExpandedNodeId = monitoredItem.ConfigExpandedNodeIdOriginal.ToString();
318318
opcNodeOnEndpointUrl.OpcPublishingInterval = (int)subscription.RequestedPublishingInterval;
319319
opcNodeOnEndpointUrl.OpcSamplingInterval = monitoredItem.RequestedSamplingInterval;
320320
if (publisherConfigurationFileEntry.OpcNodes == null)

src/PublisherNodeManager.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -467,32 +467,21 @@ private ServiceResult OnPublishNodeCall(ISystemContext context, MethodState meth
467467
// find the session we need to monitor the node
468468
OpcSession opcSession = null;
469469
opcSession = OpcSessions.FirstOrDefault(s => s.EndpointUri.AbsoluteUri.Equals(endpointUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase));
470-
string namespaceUri = null;
471-
ExpandedNodeId expandedNodeId = null;
472470

473-
// add a new session.
474471
if (opcSession == null)
475472
{
476-
// create new session info.
473+
// create new session
477474
opcSession = new OpcSession(endpointUri, OpcSessionCreationTimeout);
478475
OpcSessions.Add(opcSession);
479476
Trace($"PublishNode: No matching session found for endpoint '{endpointUri.OriginalString}'. Requested to create a new one.");
480477
}
481478
else
482479
{
483480
Trace($"PublishNode: Session found for endpoint '{endpointUri.OriginalString}'");
484-
485-
// check if node is already published
486-
namespaceUri = opcSession.GetNamespaceUri(nodeId.NamespaceIndex);
487-
if (string.IsNullOrEmpty(namespaceUri))
488-
{
489-
return ServiceResult.Create(StatusCodes.BadUnexpectedError, $"The namespace index of the node id is invalid.");
490-
}
491-
expandedNodeId = new ExpandedNodeId(nodeId.Identifier, nodeId.NamespaceIndex, namespaceUri, 0);
492481
}
493482

494483
// add the node info to the subscription with the default publishing interval, execute syncronously
495-
opcSession.AddNodeForMonitoring(nodeId, expandedNodeId, OpcPublishingInterval, OpcSamplingInterval, ShutdownTokenSource.Token).Wait();
484+
opcSession.AddNodeForMonitoring(nodeId, null, OpcPublishingInterval, OpcSamplingInterval, ShutdownTokenSource.Token).Wait();
496485
Trace($"PublishNode: Requested to monitor item with NodeId '{nodeId.ToString()}' (PublishingInterval: {OpcPublishingInterval}, SamplingInterval: {OpcSamplingInterval})");
497486
}
498487
catch (Exception e)

src/TraceWorkaround.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static void Trace(Exception e, string format, params object[] args)
5151
Utils.Trace(e, format, args);
5252
WriteLine(DateTime.Now.ToString() + ": " + e.Message.ToString());
5353
WriteLine(DateTime.Now.ToString() + ": " + format, args);
54+
WriteLine(DateTime.Now.ToString() + ": " + e.StackTrace);
5455
}
5556

5657
private static bool _verboseConsole = false;

0 commit comments

Comments
 (0)