fix(modbus): a failed read or write drops the WriteOnChangeOnly suppression for the tag
After a comms fault the device value is unknown, so re-asserting the same setpoint must reach the wire - the write-side twin of the value-only recovery dedup trap. Refs #741 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -215,6 +215,32 @@ public sealed class ModbusHealthContractTests
|
||||
drv.GetHealth().State.ShouldBe(DriverState.Healthy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_failed_read_invalidates_the_WriteOnChangeOnly_cache()
|
||||
{
|
||||
// Value-only suppression is the write-side twin of the #527 dedup trap: after a comms fault the
|
||||
// device's register is unknown (it may have rebooted), so re-asserting the same setpoint must reach it.
|
||||
var opts = new ModbusDriverOptions
|
||||
{
|
||||
Host = "f", RawTags = ModbusRawTags.Entries([Hr("A", 10)]), WriteOnChangeOnly = true,
|
||||
Probe = new ModbusProbeOptions { Enabled = false },
|
||||
};
|
||||
var (drv, t) = await StartAsync(opts);
|
||||
await using var _ = drv;
|
||||
int Fc06() => t.Sent.Count(s => s.Pdu[0] == 0x06);
|
||||
|
||||
await drv.WriteAsync([new WriteRequest("A", (short)5)], TestContext.Current.CancellationToken);
|
||||
await drv.WriteAsync([new WriteRequest("A", (short)5)], TestContext.Current.CancellationToken);
|
||||
Fc06().ShouldBe(1, "positive control: an identical re-write is suppressed while nothing failed");
|
||||
|
||||
t.Handler = (_, pdu, _) => pdu[0] == 0x03 ? Task.FromException<byte[]>(new IOException("dropped")) : null;
|
||||
await drv.ReadAsync(["A"], TestContext.Current.CancellationToken);
|
||||
t.Handler = null;
|
||||
|
||||
await drv.WriteAsync([new WriteRequest("A", (short)5)], TestContext.Current.CancellationToken);
|
||||
Fc06().ShouldBe(2, "after a failed read the device value is unknown; the write must go to the wire");
|
||||
}
|
||||
|
||||
// ---------------- lifecycle generation ----------------
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user