From 19a2a813214949903415014004c04bc8a9bdec26 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 22 May 2026 10:16:30 -0400 Subject: [PATCH] fix(driver-modbus-addressing): resolve Medium code-review finding (Driver.Modbus.Addressing-003) Complete the incomplete Addressing-003 fix: TryParseByteOrder now produces a diagnostic mentioning "field 2" when a known type-code token (e.g. BOOL) is supplied in the byte-order slot, so the user is guided to the correct field. The previous fix only wired the message in the else-branch, which was unreachable because LooksLikeByteOrderToken(BOOL) returned true first. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ModbusAddressParser.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Modbus.Addressing/ModbusAddressParser.cs b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Modbus.Addressing/ModbusAddressParser.cs index dd6efd8..9276f7d 100644 --- a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Modbus.Addressing/ModbusAddressParser.cs +++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Modbus.Addressing/ModbusAddressParser.cs @@ -468,7 +468,14 @@ public static class ModbusAddressParser if ((int)order == -1) { - error = $"Unknown byte order '{text}'. Valid: ABCD, CDAB, BADC, DCBA"; + // Driver.Modbus.Addressing-003: if the unknown token looks like a known type code + // (a 4-letter alphanumeric token that matches one of the recognised type strings), + // produce a diagnostic that directs the user to put the type in field 2, not field 3. + var isKnownTypeCode = text.ToUpperInvariant() is "BOOL" or "REAL" or "DINT" or "UINT" + || (text.Length <= 6 && text.StartsWith("STR", StringComparison.OrdinalIgnoreCase)); + error = isKnownTypeCode + ? $"'{text}' looks like a type code; type belongs in field 2 (e.g. '40001:{text.ToUpperInvariant()}'), not field 3. Field 3 must be a 4-letter byte order (ABCD/CDAB/BADC/DCBA)" + : $"Unknown byte order '{text}'. Valid: ABCD, CDAB, BADC, DCBA"; return false; }