Second + third of the four driver test clients. Both follow the same shape as otopcua-modbus-cli (#249) and consume Driver.Cli.Common for DriverCommandBase + SnapshotFormatter. New projects: - src/ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli/ — otopcua-abcip-cli. AbCipCommandBase carries gateway (ab://host[:port]/cip-path) + family (ControlLogix/CompactLogix/Micro800/GuardLogix) + timeout. Commands: probe, read, write, subscribe. Value parser covers every AbCipDataType atomic type (Bool, SInt..LInt, USInt..ULInt, Real, LReal, String, Dt); Structure writes refused as out-of-scope for the CLI. - src/ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli/ — otopcua-ablegacy-cli. AbLegacyCommandBase carries gateway + plc-type (Slc500/MicroLogix/Plc5/ LogixPccc) + timeout. Commands: probe (default address N7:0), read, write, subscribe. Value parser covers Bit, Int, Long, Float, AnalogInt, String, and the three sub-element types (TimerElement / CounterElement / ControlElement all land on int32 at the wire). Tests (35 new, 73 cumulative across the driver CLI family): - AB CIP: 17 tests — ParseValue happy-paths for every Logix atomic type, failure cases (non-numeric / bool garbage), tag-name synthesis. - AB Legacy: 18 tests — ParseValue coverage (Bit / Int / AnalogInt / Long / Float / String / sub-elements), PCCC address round-trip in tag names including bit-within-word + sub-element syntax. Docs: - docs/Driver.AbCip.Cli.md — family ↔ CIP-path cheat sheet + examples per command + typical workflows. - docs/Driver.AbLegacy.Cli.md — PCCC address primer (file letters → CLI --type) + known ab_server upstream gap cross-ref to #224 close-out. Wiring: - ZB.MOM.WW.OtOpcUa.slnx grew 4 entries (2 src + 2 tests). Full-solution build clean. `otopcua-abcip-cli --help` + `otopcua-ablegacy-cli --help` verified end-to-end. Next up (#251): S7 + TwinCAT CLIs, same pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
using CliFx.Attributes;
|
|
using CliFx.Infrastructure;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Cli.Common;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.Commands;
|
|
|
|
/// <summary>
|
|
/// Probes an AB Legacy (PCCC) endpoint: reads one N-file word + reports driver health.
|
|
/// Default probe address <c>N7:0</c> matches the integration-fixture seed so operators
|
|
/// can point the CLI at the ab_server Docker container + real hardware interchangeably.
|
|
/// </summary>
|
|
[Command("probe", Description = "Verify the AB Legacy endpoint is reachable and a sample PCCC read succeeds.")]
|
|
public sealed class ProbeCommand : AbLegacyCommandBase
|
|
{
|
|
[CommandOption("address", 'a', Description =
|
|
"PCCC address to probe (default N7:0). Use S:0 for the status file when you want " +
|
|
"the pre-populated register every SLC / MicroLogix / PLC-5 ships with.")]
|
|
public string Address { get; init; } = "N7:0";
|
|
|
|
[CommandOption("type", Description =
|
|
"PCCC data type of the probe address (default Int — matches N files).")]
|
|
public AbLegacyDataType DataType { get; init; } = AbLegacyDataType.Int;
|
|
|
|
public override async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
ConfigureLogging();
|
|
var ct = console.RegisterCancellationHandler();
|
|
|
|
var probeTag = new AbLegacyTagDefinition(
|
|
Name: "__probe",
|
|
DeviceHostAddress: Gateway,
|
|
Address: Address,
|
|
DataType: DataType,
|
|
Writable: false);
|
|
var options = BuildOptions([probeTag]);
|
|
|
|
await using var driver = new AbLegacyDriver(options, DriverInstanceId);
|
|
try
|
|
{
|
|
await driver.InitializeAsync("{}", ct);
|
|
var snapshot = await driver.ReadAsync(["__probe"], ct);
|
|
var health = driver.GetHealth();
|
|
|
|
await console.Output.WriteLineAsync($"Gateway: {Gateway}");
|
|
await console.Output.WriteLineAsync($"PLC type: {PlcType}");
|
|
await console.Output.WriteLineAsync($"Health: {health.State}");
|
|
if (health.LastError is { } err)
|
|
await console.Output.WriteLineAsync($"Last error: {err}");
|
|
await console.Output.WriteLineAsync();
|
|
await console.Output.WriteLineAsync(SnapshotFormatter.Format(Address, snapshot[0]));
|
|
}
|
|
finally
|
|
{
|
|
await driver.ShutdownAsync(CancellationToken.None);
|
|
}
|
|
}
|
|
}
|