fix(modbus): refusals are per-tag Bad, batch health, generation-stamped lifecycle, write status mapping

H4: exception 01/02/03 (and undecodable data) are device refusals - per-tag
Bad with a once-per-tag Warning, no Degraded, and they advance
LastSuccessfulRead (the device answered), so an all-refused driver no longer
trips the 90 s watchdog. 04/05/06 still degrade (answered); 0A/0B degrade
without advancing. Health is one worst-wins write per batch instead of
last-writer-wins per tag. A comms failure on one unit fails the rest of
that unit's batch fast; an unreachable endpoint fails the whole batch fast.
H7: write transport failures map to BadCommunicationError, value overflow and
array length mismatch to BadOutOfRange, conversion failures to
BadTypeMismatch; writes report write-side health (a good write or a refusal
clears a write-side Degraded; a good read does not).
Lifecycle: every health write and the transport/table publish carry a
generation; a superseded init releases its transport and publishes nothing,
a read straddling a re-init cannot degrade the new transport, and the
shutdown's final write cannot clobber a newer init. The tag table is
build-and-swapped (re-init no longer merges into the old table). Teardown
joins the probe/re-probe loops (bounded); a probe answer advances
LastSuccessfulRead and an exception PDU from the device counts as Running.
Transports latch dispose atomically and never reconnect after it.

Refs #741
Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
Joseph Doherty
2026-10-22 15:15:20 -04:00
parent ae20519e9d
commit 620ecc41dd
9 changed files with 939 additions and 149 deletions
@@ -0,0 +1,17 @@
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus;
/// <summary>
/// The device answered with well-framed data the tag's codec cannot represent (a non-BCD nibble in a
/// BCD register, for example). The device is reachable, so this is a per-tag
/// <c>BadDecodingError</c> with a once-per-tag Warning — never a comms fault, never a health write.
/// </summary>
public sealed class ModbusDecodeException : Exception
{
/// <summary>Initializes a new instance of the <see cref="ModbusDecodeException"/> class.</summary>
/// <param name="message">A human-readable description.</param>
/// <param name="inner">The codec's own exception.</param>
public ModbusDecodeException(string message, Exception? inner = null)
: base(message, inner)
{
}
}