64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public members surfaced by commentchecker — resolves 5,847 of 5,869 issues (99.6%) across three /fixdocs passes.
72 lines
3.0 KiB
C#
72 lines
3.0 KiB
C#
using CliFx.Attributes;
|
|
using CliFx.Infrastructure;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Cli.Common;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Commands;
|
|
|
|
/// <summary>
|
|
/// Read one Logix tag by symbolic path. Operator specifies <c>--tag</c> + <c>--type</c>;
|
|
/// the CLI synthesises a one-tag driver config, reads once, prints the snapshot, shuts
|
|
/// down. UDT / Structure reads are out of scope here — those need the member layout
|
|
/// declared, which belongs in a real driver config.
|
|
/// </summary>
|
|
[Command("read", Description = "Read a single Logix tag by symbolic path.")]
|
|
public sealed class ReadCommand : AbCipCommandBase
|
|
{
|
|
/// <summary>Gets the tag path to read.</summary>
|
|
[CommandOption("tag", 't', Description =
|
|
"Logix symbolic path. Controller scope: 'Motor01_Speed'. Program scope: " +
|
|
"'Program:Main.Motor01_Speed'. Array element: 'Recipe[3]'. UDT member: " +
|
|
"'Motor01.Speed'.", IsRequired = true)]
|
|
public string TagPath { get; init; } = default!;
|
|
|
|
/// <summary>Gets the data type to read as.</summary>
|
|
[CommandOption("type", Description =
|
|
"Bool / SInt / Int / DInt / LInt / USInt / UInt / UDInt / ULInt / Real / LReal / " +
|
|
"String / Dt / Structure (default DInt).")]
|
|
public AbCipDataType DataType { get; init; } = AbCipDataType.DInt;
|
|
|
|
/// <summary>Executes the read operation.</summary>
|
|
/// <param name="console">The console for output and cancellation handling.</param>
|
|
/// <inheritdoc />
|
|
public override async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
ConfigureLogging();
|
|
RejectStructure(DataType);
|
|
var ct = console.RegisterCancellationHandler();
|
|
|
|
var tagName = SynthesiseTagName(TagPath, DataType);
|
|
var tag = new AbCipTagDefinition(
|
|
Name: tagName,
|
|
DeviceHostAddress: Gateway,
|
|
TagPath: TagPath,
|
|
DataType: DataType,
|
|
Writable: false);
|
|
var options = BuildOptions([tag]);
|
|
|
|
await using var driver = new AbCipDriver(options, DriverInstanceId);
|
|
try
|
|
{
|
|
await driver.InitializeAsync("{}", ct);
|
|
var snapshot = await driver.ReadAsync([tagName], ct);
|
|
await console.Output.WriteLineAsync(SnapshotFormatter.Format(TagPath, snapshot[0]));
|
|
}
|
|
finally
|
|
{
|
|
await driver.ShutdownAsync(CancellationToken.None);
|
|
// Driver.AbCip.Cli-005 — flush Serilog before process exit so buffered log
|
|
// output emitted during driver shutdown is not lost.
|
|
FlushLogging();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tag-name key the driver uses internally. The path + type pair is already unique
|
|
/// so we use them verbatim — keeps tag-level diagnostics readable without mangling.
|
|
/// </summary>
|
|
/// <param name="tagPath">The symbolic tag path.</param>
|
|
/// <param name="type">The data type.</param>
|
|
internal static string SynthesiseTagName(string tagPath, AbCipDataType type)
|
|
=> $"{tagPath}:{type}";
|
|
}
|