review(Driver.Modbus.Addressing): fix misleading byte-order hint + drop dead overflow guard
Re-review at 7286d320. -010 (Low): TryParseByteOrder no longer lists REAL/DINT/UINT as type
codes (gave wrong 'field 2' advice -> second parse error); generic byte-order error instead.
-011 (Low): remove unreachable offsetWithinBank>ushort.MaxValue guard (DecodeOctalVAddress
caps at 0xFFFF). + TDD.
This commit is contained in:
@@ -117,11 +117,12 @@ public static class DirectLogicAddress
|
||||
|
||||
// System bank: the registers are contiguous from V40400, so the offset within the bank
|
||||
// is the plain decimal distance from the octal base, not another octal decode.
|
||||
var offsetWithinBank = octalValue - SystemVMemoryOctalBase;
|
||||
if (offsetWithinBank > ushort.MaxValue)
|
||||
throw new OverflowException(
|
||||
$"V-memory address '{vAddress}' is outside the addressable system bank");
|
||||
return SystemVMemoryToPdu((ushort)offsetWithinBank);
|
||||
// Driver.Modbus.Addressing-011: the subtraction result is provably <= 0xBEFF because
|
||||
// DecodeOctalVAddress already caps octalValue at 0xFFFF, so no overflow guard is needed
|
||||
// here. The real overflow guard (pdu > ushort.MaxValue) lives in SystemVMemoryToPdu and
|
||||
// is reachable only when that helper is called directly with a large explicit offset.
|
||||
var offsetWithinBank = (ushort)(octalValue - SystemVMemoryOctalBase);
|
||||
return SystemVMemoryToPdu(offsetWithinBank);
|
||||
}
|
||||
|
||||
// Bit-memory bases per DL260 user manual §I/O-configuration.
|
||||
|
||||
@@ -503,13 +503,18 @@ public static class ModbusAddressParser
|
||||
|
||||
if ((int)order == -1)
|
||||
{
|
||||
// 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)"
|
||||
// Driver.Modbus.Addressing-003: if the unknown token is a VALID type code in this
|
||||
// parser, direct the user to put it in field 2 instead. Only BOOL (4-letter) and
|
||||
// STR<n> are valid type codes that could appear here. "REAL", "DINT", "UINT" look
|
||||
// like type names from other tools (STEP 7 / RSLogix) but are NOT valid in this
|
||||
// parser's type table (Driver.Modbus.Addressing-010) — listing them here would give
|
||||
// advice that leads to a second error ("Unknown type code 'REAL'").
|
||||
var upper = text.ToUpperInvariant();
|
||||
var isActualTypeCode = upper is "BOOL"
|
||||
|| (text.Length > 3 && text.StartsWith("STR", StringComparison.OrdinalIgnoreCase)
|
||||
&& text[3..].All(char.IsDigit));
|
||||
error = isActualTypeCode
|
||||
? $"'{text}' looks like a type code; type belongs in field 2 (e.g. '40001:{upper}'), 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user