Auto: twincat-3.1 — per-tag MaxDelay tuning

Closes #313
This commit is contained in:
Joseph Doherty
2026-04-26 01:45:12 -04:00
parent 621de94126
commit fb57717f6f
11 changed files with 261 additions and 9 deletions

View File

@@ -20,9 +20,18 @@ public sealed class SubscribeCommand : TwinCATCommandBase
"String / WString / Time / Date / DateTime / TimeOfDay (default DInt).")]
public TwinCATDataType DataType { get; init; } = TwinCATDataType.DInt;
[CommandOption("interval-ms", 'i', Description = "Publishing interval ms (default 1000).")]
[CommandOption("interval-ms", 'i', Description =
"Cycle time ms — minimum interval between change checks the PLC runtime applies " +
"(default 1000). Different from --max-delay-ms; see help for that flag.")]
public int IntervalMs { get; init; } = 1000;
[CommandOption("max-delay-ms", Description =
"Per-tag MaxDelay in ms (PR 3.1, issue #313) — upper bound on how long the runtime " +
"can buffer / coalesce change events before dispatch. 0 (default) = fire ASAP, no " +
"coalescing. Larger values (e.g. 500) reduce event rate on bursty signals so the " +
"OPC UA queue downstream doesn't flood. Distinct from --interval-ms (the cycle).")]
public int MaxDelayMs { get; init; } = 0;
public override async ValueTask ExecuteAsync(IConsole console)
{
ConfigureLogging();
@@ -34,7 +43,8 @@ public sealed class SubscribeCommand : TwinCATCommandBase
DeviceHostAddress: Gateway,
SymbolPath: SymbolPath,
DataType: DataType,
Writable: false);
Writable: false,
MaxDelayMs: MaxDelayMs > 0 ? MaxDelayMs : null);
var options = BuildOptions([tag]);
await using var driver = new TwinCATDriver(options, DriverInstanceId);
@@ -54,8 +64,9 @@ public sealed class SubscribeCommand : TwinCATCommandBase
handle = await driver.SubscribeAsync([tagName], TimeSpan.FromMilliseconds(IntervalMs), ct);
var mode = PollOnly ? "polling" : "ADS notification";
var coalesce = MaxDelayMs > 0 ? $", max-delay {MaxDelayMs}ms" : "";
await console.Output.WriteLineAsync(
$"Subscribed to {SymbolPath} @ {IntervalMs}ms ({mode}). Ctrl+C to stop.");
$"Subscribed to {SymbolPath} @ {IntervalMs}ms ({mode}{coalesce}). Ctrl+C to stop.");
try
{
await Task.Delay(System.Threading.Timeout.InfiniteTimeSpan, ct);