diff --git a/docs/Client.CLI.md b/docs/Client.CLI.md index fa1e131f8..44e5bc4d0 100644 --- a/docs/Client.CLI.md +++ b/docs/Client.CLI.md @@ -262,6 +262,7 @@ continuation points up to `--max`. `--events` cannot be combined with `--modifie | `--at-time` | HistoryRead-AtTime at these comma-separated ISO 8601 UTC times; prints the status, the rows and each value's CLR type | | `--page-size` | Raw only: page by hand at this `NumValuesPerNode`, printing every page as `Page k: values= continuation=[ resumed]` (a refused page is printed, never thrown) | | `--pause-after-page` / `--resume-when-file` / `--pause-timeout` | With `--page-size`: after page k hold the session (and its continuation point) until the file exists, then resume | +| `--held-marker-file` | With `--page-size`: create this (empty) file when the read reaches its pause, abandon or release point | | `--fresh-after-failure` | With `--page-size`: after a refused resumed page, issue one fresh read of the same window (`Fresh: …`) | | `--abandon-after-page` | With `--page-size`: stop after page k WITHOUT releasing its continuation point — the disconnect (session close) releases it | | `--release-after-page` | With `--page-size`: send `releaseContinuationPoints` for page k's point and stop | diff --git a/src/Client/ZB.MOM.WW.OtOpcUa.Client.CLI/Commands/HistoryReadCommand.cs b/src/Client/ZB.MOM.WW.OtOpcUa.Client.CLI/Commands/HistoryReadCommand.cs index 804faa364..b25c99007 100644 --- a/src/Client/ZB.MOM.WW.OtOpcUa.Client.CLI/Commands/HistoryReadCommand.cs +++ b/src/Client/ZB.MOM.WW.OtOpcUa.Client.CLI/Commands/HistoryReadCommand.cs @@ -99,6 +99,10 @@ public class HistoryReadCommand : CommandBase [CommandOption("resume-when-file", Description = "With --pause-after-page: resume once this file exists (it is not read or deleted)")] public string? ResumeWhenFile { get; init; } + /// Written (empty) once the hand-paged read reaches its pause / abandon / release point, so a driver knows the page is held. + [CommandOption("held-marker-file", Description = "With --page-size: create this file when the read reaches its pause, abandon or release point")] + public string? HeldMarkerFile { get; init; } + /// How long a pause waits for --resume-when-file before giving up. [CommandOption("pause-timeout", Description = "With --pause-after-page: seconds to wait for --resume-when-file (default 300)")] public int PauseTimeoutSeconds { get; init; } = 300; @@ -203,6 +207,7 @@ public class HistoryReadCommand : CommandBase if (number == AbandonAfterPage) { await console.Output.WriteLineAsync($"Abandoned after page {number} (continuation not released; holding {HoldSeconds}s)"); + if (HeldMarkerFile is not null) await File.WriteAllTextAsync(HeldMarkerFile, "", ct); if (HoldSeconds > 0) await Task.Delay(TimeSpan.FromSeconds(HoldSeconds), ct); return; } @@ -210,12 +215,14 @@ public class HistoryReadCommand : CommandBase { var released = await service.HistoryReadPageAsync(details, nodeId, cp, true, ct); await console.Output.WriteLineAsync($"Released after page {number}: {Format(released.Status)}"); + if (HeldMarkerFile is not null) await File.WriteAllTextAsync(HeldMarkerFile, "", ct); if (HoldSeconds > 0) await Task.Delay(TimeSpan.FromSeconds(HoldSeconds), ct); return; } if (number == PauseAfterPage) { await console.Output.WriteLineAsync($"Paused after page {number}; waiting for {ResumeWhenFile}"); + if (HeldMarkerFile is not null) await File.WriteAllTextAsync(HeldMarkerFile, "", ct); var deadline = DateTime.UtcNow.AddSeconds(PauseTimeoutSeconds); while (!File.Exists(ResumeWhenFile)) { diff --git a/tests/Client/ZB.MOM.WW.OtOpcUa.Client.CLI.Tests/HistoryReadPagedCommandTests.cs b/tests/Client/ZB.MOM.WW.OtOpcUa.Client.CLI.Tests/HistoryReadPagedCommandTests.cs index b73402c6a..6b0d705a3 100644 --- a/tests/Client/ZB.MOM.WW.OtOpcUa.Client.CLI.Tests/HistoryReadPagedCommandTests.cs +++ b/tests/Client/ZB.MOM.WW.OtOpcUa.Client.CLI.Tests/HistoryReadPagedCommandTests.cs @@ -73,13 +73,16 @@ public class HistoryReadPagedCommandTests { var fake = new FakeOpcUaClientService(); fake.HistoryPages.Enqueue(new HistoryPage(StatusCodes.Good, [Value(1, 0)], [5])); + var held = Path.Combine(Path.GetTempPath(), "cli-held-" + Guid.NewGuid().ToString("N")); using var console = TestConsoleHelper.CreateConsole(); var command = new HistoryReadCommand(new FakeOpcUaClientServiceFactory(fake)) { Url = "opc.tcp://localhost:4840", NodeId = "ns=3;s=p1.x", PageSize = 1, - AbandonAfterPage = release ? 0 : 1, ReleaseAfterPage = release ? 1 : 0, + AbandonAfterPage = release ? 0 : 1, ReleaseAfterPage = release ? 1 : 0, HeldMarkerFile = held, }; await command.ExecuteAsync(console); + File.Exists(held).ShouldBeTrue("the held marker is written at the abandon / release point"); + File.Delete(held); var output = TestConsoleHelper.GetOutput(console); if (release) {