using CliFx.Attributes; using ZB.MOM.WW.OtOpcUa.Driver.Cli.Common; using S7NetCpuType = global::S7.Net.CpuType; namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Cli; /// /// Base for every S7 CLI command. Carries the ISO-on-TCP endpoint options /// (host / port / CPU type / rack / slot) that S7.Net needs for its handshake + /// exposes so each command can synthesise an /// on demand. /// public abstract class S7CommandBase : DriverCommandBase { [CommandOption("host", 'h', Description = "PLC IP address or hostname.", IsRequired = true)] public string Host { get; init; } = default!; [CommandOption("port", 'p', Description = "ISO-on-TCP port (default 102).")] public int Port { get; init; } = 102; [CommandOption("cpu", 'c', Description = "S7 CPU family: S7200 / S7200Smart / S7300 / S7400 / S71200 / S71500 " + "(default S71500). Determines the ISO-TSAP slot byte.")] public S7NetCpuType CpuType { get; init; } = S7NetCpuType.S71500; [CommandOption("rack", Description = "Rack number (default 0 — single-rack).")] public short Rack { get; init; } = 0; [CommandOption("slot", Description = "CPU slot. S7-300 = 2, S7-400 = 2 or 3, S7-1200 / S7-1500 = 0 (default 0).")] public short Slot { get; init; } = 0; [CommandOption("timeout-ms", Description = "Per-operation timeout in ms (default 5000).")] public int TimeoutMs { get; init; } = 5000; /// public override TimeSpan Timeout { get => TimeSpan.FromMilliseconds(TimeoutMs); init { /* driven by TimeoutMs */ } } /// /// Build an with the endpoint fields this base /// collected + whatever the subclass declares. Probe /// disabled — CLI runs are one-shot. /// protected S7DriverOptions BuildOptions(IReadOnlyList tags) => new() { Host = Host, Port = Port, CpuType = CpuType, Rack = Rack, Slot = Slot, Timeout = Timeout, Tags = tags, Probe = new S7ProbeOptions { Enabled = false }, }; protected string DriverInstanceId => $"s7-cli-{Host}:{Port}"; }