using CliFx.Attributes; using CliFx.Infrastructure; using ZB.MOM.WW.OtOpcUa.Driver.Cli.Common; namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Cli.Commands; /// /// Probes a Fanuc CNC: opens a FOCAS session + reads one PMC address. No public /// simulator exists — this command only produces meaningful results against a real /// CNC with Fwlib32.dll present. Against a dev box it surfaces /// BadCommunicationError (DLL missing) which is still a useful signal that /// the CLI wire-up is correct. /// [Command("probe", Description = "Verify the CNC is reachable + a sample FOCAS read succeeds.")] public sealed class ProbeCommand : FocasCommandBase { [CommandOption("address", 'a', Description = "FOCAS address to probe (default R100 — PMC R-file register 100).")] public string Address { get; init; } = "R100"; [CommandOption("type", Description = "Data type (default Int16).")] public FocasDataType DataType { get; init; } = FocasDataType.Int16; public override async ValueTask ExecuteAsync(IConsole console) { ConfigureLogging(); var ct = console.RegisterCancellationHandler(); var probeTag = new FocasTagDefinition( Name: "__probe", DeviceHostAddress: HostAddress, Address: Address, DataType: DataType, Writable: false); var options = BuildOptions([probeTag]); await using var driver = new FocasDriver(options, DriverInstanceId); try { await driver.InitializeAsync("{}", ct); var snapshot = await driver.ReadAsync(["__probe"], ct); var health = driver.GetHealth(); await console.Output.WriteLineAsync($"CNC: {CncHost}:{CncPort}"); await console.Output.WriteLineAsync($"Series: {Series}"); 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); } } }