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

Commit

Permalink
No conversion to ExpandedNodeId for NodeId publishing requests via OPC
Browse files Browse the repository at this point in the history
UA server methods.
  • Loading branch information
hansgschossmann committed Dec 19, 2017
1 parent 7cb875f commit 53d5464
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 33 deletions.
23 changes: 4 additions & 19 deletions src/OpcSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,8 @@ public async Task<bool> MonitorNodes(CancellationToken ct)
NodeId currentNodeId = null;
try
{
// update the namespace of the node if requested. there are two cases where this is requested:
// 1) publishing requests via the OPC server method are raised using a NodeId format. for those
// the NodeId format is converted into an ExpandedNodeId format
// 2) ExpandedNodeId configuration file entries do not have at parsing time a session to get
// the namespace index. this is set now.
// update the namespace of the node if requested.this is required, because:
// - ExpandedNodeId configuration file entries do not have at parsing time a session to get
if (item.State == OpcMonitoredItemState.UnmonitoredNamespaceUpdateRequested)
{
if (item.ConfigType == OpcMonitoredItemConfigurationType.ExpandedNodeId)
Expand All @@ -515,19 +512,7 @@ public async Task<bool> MonitorNodes(CancellationToken ct)
item.ConfigExpandedNodeId = new ExpandedNodeId(item.ConfigExpandedNodeId.Identifier, (ushort)namespaceIndex, item.ConfigExpandedNodeId?.NamespaceUri, 0);
}
}
if (item.ConfigType == OpcMonitoredItemConfigurationType.NodeId)
{
string namespaceUri = GetNamespaceUri(item.ConfigNodeId.NamespaceIndex);
if (string.IsNullOrEmpty(namespaceUri))
{
Trace($"The namespace index of node '{item.ConfigNodeId.ToString()}' is invalid and the node format could not be updated.");
}
else
{
item.ConfigExpandedNodeId = new ExpandedNodeId(item.ConfigNodeId.Identifier, item.ConfigNodeId.NamespaceIndex, namespaceUri, 0);
item.ConfigType = OpcMonitoredItemConfigurationType.ExpandedNodeId;
}
}
// for config type NodeId we do nothing
item.State = OpcMonitoredItemState.Unmonitored;
}

Expand Down Expand Up @@ -885,7 +870,7 @@ public async Task AddNodeForMonitoring(NodeId nodeId, ExpandedNodeId expandedNod
// add a new item to monitor
if (expandedNodeId == null)
{
opcMonitoredItem = new OpcMonitoredItem(nodeId, EndpointUri, true);
opcMonitoredItem = new OpcMonitoredItem(nodeId, EndpointUri);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/PublisherNodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static async Task<List<PublisherConfigurationFileEntry>> GetPublisherConf
}
else
{
opcNodeOnEndpointUrl.ExpandedNodeId = monitoredItem.ConfigExpandedNodeId.ToString();
opcNodeOnEndpointUrl.ExpandedNodeId = monitoredItem.ConfigExpandedNodeIdOriginal.ToString();
opcNodeOnEndpointUrl.OpcPublishingInterval = (int)subscription.RequestedPublishingInterval;
opcNodeOnEndpointUrl.OpcSamplingInterval = monitoredItem.RequestedSamplingInterval;
if (publisherConfigurationFileEntry.OpcNodes == null)
Expand Down
15 changes: 2 additions & 13 deletions src/PublisherNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,32 +467,21 @@ private ServiceResult OnPublishNodeCall(ISystemContext context, MethodState meth
// find the session we need to monitor the node
OpcSession opcSession = null;
opcSession = OpcSessions.FirstOrDefault(s => s.EndpointUri.AbsoluteUri.Equals(endpointUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase));
string namespaceUri = null;
ExpandedNodeId expandedNodeId = null;

// add a new session.
if (opcSession == null)
{
// create new session info.
// create new session
opcSession = new OpcSession(endpointUri, OpcSessionCreationTimeout);
OpcSessions.Add(opcSession);
Trace($"PublishNode: No matching session found for endpoint '{endpointUri.OriginalString}'. Requested to create a new one.");
}
else
{
Trace($"PublishNode: Session found for endpoint '{endpointUri.OriginalString}'");

// check if node is already published
namespaceUri = opcSession.GetNamespaceUri(nodeId.NamespaceIndex);
if (string.IsNullOrEmpty(namespaceUri))
{
return ServiceResult.Create(StatusCodes.BadUnexpectedError, $"The namespace index of the node id is invalid.");
}
expandedNodeId = new ExpandedNodeId(nodeId.Identifier, nodeId.NamespaceIndex, namespaceUri, 0);
}

// add the node info to the subscription with the default publishing interval, execute syncronously
opcSession.AddNodeForMonitoring(nodeId, expandedNodeId, OpcPublishingInterval, OpcSamplingInterval, ShutdownTokenSource.Token).Wait();
opcSession.AddNodeForMonitoring(nodeId, null, OpcPublishingInterval, OpcSamplingInterval, ShutdownTokenSource.Token).Wait();
Trace($"PublishNode: Requested to monitor item with NodeId '{nodeId.ToString()}' (PublishingInterval: {OpcPublishingInterval}, SamplingInterval: {OpcSamplingInterval})");
}
catch (Exception e)
Expand Down
1 change: 1 addition & 0 deletions src/TraceWorkaround.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static void Trace(Exception e, string format, params object[] args)
Utils.Trace(e, format, args);
WriteLine(DateTime.Now.ToString() + ": " + e.Message.ToString());
WriteLine(DateTime.Now.ToString() + ": " + format, args);
WriteLine(DateTime.Now.ToString() + ": " + e.StackTrace);
}

private static bool _verboseConsole = false;
Expand Down

0 comments on commit 53d5464

Please sign in to comment.