review(Driver.AbLegacy): fix Bit write 1-byte/2-byte encode-decode mismatch (Medium)

Re-review at 7286d320. -014 (Medium): Bit EncodeValue (no bitIndex) wrote SetInt8 while
DecodeValue read GetInt16 on a 16-bit B-file element, so a false write could round-trip
as true (stale high byte). Fix: SetInt16 + TDD. -015: tests pass CancellationToken.
This commit is contained in:
Joseph Doherty
2026-06-19 11:47:11 -04:00
parent be272d960f
commit 91e2609560
4 changed files with 131 additions and 7 deletions
@@ -142,7 +142,11 @@ internal sealed class LibplctagLegacyTagRuntime : IAbLegacyTagRuntime
// silently clobbering the whole word.
throw new NotSupportedException(
"Bit-with-bitIndex writes must go through AbLegacyDriver.WriteBitInWordAsync.");
_tag.SetInt8(0, Convert.ToBoolean(value) ? (sbyte)1 : (sbyte)0);
// Driver.AbLegacy-014 — use SetInt16 to match DecodeValue's GetInt16(0) decode.
// A PCCC B-file element is a 16-bit word; SetInt8 only writes 1 byte, leaving
// bits 8-15 from the previous read in the tag buffer and creating a
// decode/encode asymmetry. SetInt16(0, 0/1) writes the full 16-bit word.
_tag.SetInt16(0, Convert.ToBoolean(value) ? (short)1 : (short)0);
break;
case AbLegacyDataType.Int:
case AbLegacyDataType.AnalogInt: