Expand XML docs across bridge and test code

This commit is contained in:
Joseph Doherty
2026-03-25 11:45:12 -04:00
parent 3f813b3869
commit 4833765606
86 changed files with 2323 additions and 0 deletions

View File

@@ -9,18 +9,34 @@ namespace OpcUaCli.Commands;
[Command("browse", Description = "Browse the OPC UA address space")]
public class BrowseCommand : ICommand
{
/// <summary>
/// Gets the OPC UA endpoint URL to connect to before browsing.
/// </summary>
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
public string Url { get; init; } = default!;
/// <summary>
/// Gets the optional node identifier to browse from; defaults to the OPC UA Objects folder.
/// </summary>
[CommandOption("node", 'n', Description = "Node ID to browse (default: Objects folder)")]
public string? NodeId { get; init; }
/// <summary>
/// Gets the maximum browse depth when recursive traversal is enabled.
/// </summary>
[CommandOption("depth", 'd', Description = "Maximum browse depth")]
public int Depth { get; init; } = 1;
/// <summary>
/// Gets a value indicating whether browse recursion should continue into child objects.
/// </summary>
[CommandOption("recursive", 'r', Description = "Browse recursively (uses --depth as max depth)")]
public bool Recursive { get; init; }
/// <summary>
/// Connects to the OPC UA endpoint and writes the browse tree to the console.
/// </summary>
/// <param name="console">The console used to emit browse output.</param>
public async ValueTask ExecuteAsync(IConsole console)
{
using var session = await OpcUaHelper.ConnectAsync(Url);

View File

@@ -7,9 +7,16 @@ namespace OpcUaCli.Commands;
[Command("connect", Description = "Test connection to an OPC UA server")]
public class ConnectCommand : ICommand
{
/// <summary>
/// Gets the OPC UA endpoint URL to test.
/// </summary>
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
public string Url { get; init; } = default!;
/// <summary>
/// Connects to the OPC UA endpoint and prints the resolved server metadata.
/// </summary>
/// <param name="console">The console used to report connection results.</param>
public async ValueTask ExecuteAsync(IConsole console)
{
using var session = await OpcUaHelper.ConnectAsync(Url);

View File

@@ -9,12 +9,22 @@ namespace OpcUaCli.Commands;
[Command("read", Description = "Read a value from a node")]
public class ReadCommand : ICommand
{
/// <summary>
/// Gets the OPC UA endpoint URL to connect to before reading.
/// </summary>
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
public string Url { get; init; } = default!;
/// <summary>
/// Gets the node identifier whose value should be read.
/// </summary>
[CommandOption("node", 'n', Description = "Node ID (e.g. ns=2;s=MyNode)", IsRequired = true)]
public string NodeId { get; init; } = default!;
/// <summary>
/// Connects to the endpoint, reads the target node, and prints the returned value details.
/// </summary>
/// <param name="console">The console used to report the read result.</param>
public async ValueTask ExecuteAsync(IConsole console)
{
using var session = await OpcUaHelper.ConnectAsync(Url);

View File

@@ -9,15 +9,28 @@ namespace OpcUaCli.Commands;
[Command("subscribe", Description = "Monitor a node for value changes")]
public class SubscribeCommand : ICommand
{
/// <summary>
/// Gets the OPC UA endpoint URL to connect to before subscribing.
/// </summary>
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
public string Url { get; init; } = default!;
/// <summary>
/// Gets the node identifier to monitor for value changes.
/// </summary>
[CommandOption("node", 'n', Description = "Node ID to monitor", IsRequired = true)]
public string NodeId { get; init; } = default!;
/// <summary>
/// Gets the sampling and publishing interval, in milliseconds, for the monitored item.
/// </summary>
[CommandOption("interval", 'i', Description = "Polling interval in milliseconds")]
public int Interval { get; init; } = 1000;
/// <summary>
/// Connects to the OPC UA endpoint and streams monitored-item notifications until cancellation.
/// </summary>
/// <param name="console">The console used to display subscription updates.</param>
public async ValueTask ExecuteAsync(IConsole console)
{
using var session = await OpcUaHelper.ConnectAsync(Url);

View File

@@ -9,15 +9,28 @@ namespace OpcUaCli.Commands;
[Command("write", Description = "Write a value to a node")]
public class WriteCommand : ICommand
{
/// <summary>
/// Gets the OPC UA endpoint URL to connect to before issuing the write.
/// </summary>
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
public string Url { get; init; } = default!;
/// <summary>
/// Gets the node identifier that should receive the write.
/// </summary>
[CommandOption("node", 'n', Description = "Node ID (e.g. ns=2;s=MyNode)", IsRequired = true)]
public string NodeId { get; init; } = default!;
/// <summary>
/// Gets the textual value supplied on the command line before type conversion.
/// </summary>
[CommandOption("value", 'v', Description = "Value to write", IsRequired = true)]
public string Value { get; init; } = default!;
/// <summary>
/// Connects to the OPC UA endpoint, converts the supplied value, and writes it to the target node.
/// </summary>
/// <param name="console">The console used to report the write result.</param>
public async ValueTask ExecuteAsync(IConsole console)
{
using var session = await OpcUaHelper.ConnectAsync(Url);

View File

@@ -6,6 +6,11 @@ namespace OpcUaCli;
public static class OpcUaHelper
{
/// <summary>
/// Creates an OPC UA client session for the specified endpoint URL.
/// </summary>
/// <param name="endpointUrl">The OPC UA endpoint URL to connect to.</param>
/// <returns>An active OPC UA client session.</returns>
public static async Task<Session> ConnectAsync(string endpointUrl)
{
var config = new ApplicationConfiguration
@@ -61,6 +66,12 @@ public static class OpcUaHelper
#pragma warning restore CS0618
}
/// <summary>
/// Converts a raw command-line string into the runtime type expected by the target node.
/// </summary>
/// <param name="rawValue">The raw string supplied by the user.</param>
/// <param name="currentValue">The current node value used to infer the target type.</param>
/// <returns>A typed value suitable for an OPC UA write request.</returns>
public static object ConvertValue(string rawValue, object? currentValue)
{
return currentValue switch