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>
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using CliFx;
|
|
using CliFx.Attributes;
|
|
using CliFx.Infrastructure;
|
|
using Opc.Ua;
|
|
using Opc.Ua.Client;
|
|
|
|
namespace OpcUaCli.Commands;
|
|
|
|
[Command("subscribe", Description = "Monitor a node for value changes")]
|
|
public class SubscribeCommand : 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 monitor", IsRequired = true)]
|
|
public string NodeId { get; init; } = default!;
|
|
|
|
[CommandOption("interval", 'i', Description = "Polling interval in milliseconds")]
|
|
public int Interval { get; init; } = 1000;
|
|
|
|
public async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
using var session = await OpcUaHelper.ConnectAsync(Url);
|
|
|
|
var subscription = new Subscription(session.DefaultSubscription)
|
|
{
|
|
PublishingInterval = Interval,
|
|
DisplayName = "CLI Subscription"
|
|
};
|
|
|
|
var item = new MonitoredItem(subscription.DefaultItem)
|
|
{
|
|
StartNodeId = new NodeId(NodeId),
|
|
DisplayName = NodeId,
|
|
SamplingInterval = Interval
|
|
};
|
|
|
|
item.Notification += (_, e) =>
|
|
{
|
|
if (e.NotificationValue is MonitoredItemNotification notification)
|
|
{
|
|
console.Output.WriteLine(
|
|
$"[{notification.Value.SourceTimestamp:O}] {NodeId} = {notification.Value.Value} ({notification.Value.StatusCode})");
|
|
}
|
|
};
|
|
|
|
subscription.AddItem(item);
|
|
session.AddSubscription(subscription);
|
|
await subscription.CreateAsync();
|
|
|
|
await console.Output.WriteLineAsync(
|
|
$"Subscribed to {NodeId} (interval: {Interval}ms). Press Ctrl+C to stop.");
|
|
|
|
var ct = console.RegisterCancellationHandler();
|
|
|
|
try { await Task.Delay(Timeout.Infinite, ct); }
|
|
catch (OperationCanceledException) { }
|
|
|
|
await console.Output.WriteLineAsync("Unsubscribed.");
|
|
}
|
|
}
|