Implement LmxOpcUa server — all 6 phases complete
Full OPC UA server on .NET Framework 4.8 (x86) exposing AVEVA System Platform Galaxy tags via MXAccess. Mirrors Galaxy object hierarchy as OPC UA address space, translating contained-name browse paths to tag-name runtime references. Components implemented: - Configuration: AppConfiguration with 4 sections, validator - Domain: ConnectionState, Quality, Vtq, MxDataTypeMapper, error codes - MxAccess: StaComThread, MxAccessClient (partial classes), MxProxyAdapter using strongly-typed ArchestrA.MxAccess COM interop - Galaxy Repository: SQL queries (hierarchy, attributes, change detection), ChangeDetectionService with auto-rebuild on deploy - OPC UA Server: LmxNodeManager (CustomNodeManager2), LmxOpcUaServer, OpcUaServerHost with programmatic config, SecurityPolicy None - Status Dashboard: HTTP server with HTML/JSON/health endpoints - Integration: Full 14-step startup, graceful shutdown, component wiring 175 tests (174 unit + 1 integration), all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
92
tools/opcuacli-dotnet/Commands/BrowseCommand.cs
Normal file
92
tools/opcuacli-dotnet/Commands/BrowseCommand.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using Opc.Ua;
|
||||
using Opc.Ua.Client;
|
||||
|
||||
namespace OpcUaCli.Commands;
|
||||
|
||||
[Command("browse", Description = "Browse the OPC UA address space")]
|
||||
public class BrowseCommand : ICommand
|
||||
{
|
||||
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
|
||||
public string Url { get; init; } = default!;
|
||||
|
||||
[CommandOption("node", 'n', Description = "Node ID to browse (default: Objects folder)")]
|
||||
public string? NodeId { get; init; }
|
||||
|
||||
[CommandOption("depth", 'd', Description = "Maximum browse depth")]
|
||||
public int Depth { get; init; } = 1;
|
||||
|
||||
[CommandOption("recursive", 'r', Description = "Browse recursively (uses --depth as max depth)")]
|
||||
public bool Recursive { get; init; }
|
||||
|
||||
public async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
using var session = await OpcUaHelper.ConnectAsync(Url);
|
||||
|
||||
var startNode = string.IsNullOrEmpty(NodeId)
|
||||
? ObjectIds.ObjectsFolder
|
||||
: new NodeId(NodeId);
|
||||
|
||||
var maxDepth = Recursive ? Depth : 1;
|
||||
await BrowseNodeAsync(session, console, startNode, maxDepth, 0);
|
||||
}
|
||||
|
||||
private static async Task BrowseNodeAsync(
|
||||
ISession session, IConsole console, NodeId nodeId, int maxDepth, int currentDepth)
|
||||
{
|
||||
var indent = new string(' ', currentDepth * 2);
|
||||
|
||||
var (_, continuationPoint, references) = await session.BrowseAsync(
|
||||
null,
|
||||
null,
|
||||
nodeId,
|
||||
0u,
|
||||
BrowseDirection.Forward,
|
||||
ReferenceTypeIds.HierarchicalReferences,
|
||||
true,
|
||||
(uint)NodeClass.Object | (uint)NodeClass.Variable | (uint)NodeClass.Method);
|
||||
|
||||
if (references == null) return;
|
||||
|
||||
// Handle continuation points for large result sets
|
||||
while (references.Count > 0)
|
||||
{
|
||||
foreach (var reference in references)
|
||||
{
|
||||
var nodeClass = reference.NodeClass;
|
||||
var marker = nodeClass switch
|
||||
{
|
||||
NodeClass.Object => "[Object]",
|
||||
NodeClass.Variable => "[Variable]",
|
||||
NodeClass.Method => "[Method]",
|
||||
_ => $"[{nodeClass}]"
|
||||
};
|
||||
|
||||
await console.Output.WriteLineAsync(
|
||||
$"{indent}{marker} {reference.DisplayName} (NodeId: {reference.NodeId})");
|
||||
|
||||
if (currentDepth + 1 < maxDepth && nodeClass == NodeClass.Object)
|
||||
{
|
||||
var childNodeId = ExpandedNodeId.ToNodeId(
|
||||
reference.NodeId, session.NamespaceUris);
|
||||
await BrowseNodeAsync(session, console, childNodeId, maxDepth, currentDepth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Follow continuation point if present
|
||||
if (continuationPoint != null && continuationPoint.Length > 0)
|
||||
{
|
||||
var (_, nextCp, nextRefs) = await session.BrowseNextAsync(
|
||||
null, false, continuationPoint);
|
||||
continuationPoint = nextCp;
|
||||
references = nextRefs;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user