fix(modbus): #981 review — MELSEC no longer claims the generic DI<n> discrete-input mnemonic
The S-8 gate (no generic mnemonic fallback once a family grammar claimed the address) made the MELSEC D-register grammar, which claimed every D prefix, reject DI100 as a malformed D-register. MELSEC has no DI device, so DI... is no longer claimed; every other D... stays native and DL205's non-octal C rejection is untouched.
This commit is contained in:
+31
@@ -202,6 +202,37 @@ public sealed class ModbusFamilyParserTests
|
||||
generic.Offset.ShouldBe((ushort)17);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #981 review: the S-8 gate stopped the generic mnemonic table whenever the family grammar CLAIMED an address,
|
||||
/// and the MELSEC grammar claims every <c>D</c> prefix (D-registers) — so <c>DI100</c>, the generic
|
||||
/// discrete-input mnemonic, stopped parsing under MELSEC (it failed as a malformed D-register). MELSEC has no
|
||||
/// <c>DI</c> device, so the grammar must not claim it.
|
||||
/// </summary>
|
||||
/// <param name="addr">A generic discrete-input mnemonic.</param>
|
||||
/// <param name="expectedOffset">Its zero-based offset.</param>
|
||||
[Theory]
|
||||
[InlineData("DI100", 99)]
|
||||
[InlineData("di1", 0)]
|
||||
public void MELSEC_Generic_DiscreteInput_Mnemonic_Still_Parses(string addr, int expectedOffset)
|
||||
{
|
||||
ModbusAddressParser.TryParse(addr, ModbusFamily.MELSEC, MelsecFamily.Q_L_iQR, out var result, out var error)
|
||||
.ShouldBeTrue(error);
|
||||
result!.Region.ShouldBe(ModbusRegion.DiscreteInputs);
|
||||
result.Offset.ShouldBe((ushort)expectedOffset);
|
||||
}
|
||||
|
||||
/// <summary>Controls for the narrow MELSEC fix: a D-register still resolves natively, and a malformed one still errors.</summary>
|
||||
[Fact]
|
||||
public void MELSEC_D_Register_Still_Native_And_Malformed_Still_Errors()
|
||||
{
|
||||
var d = ModbusAddressParser.Parse("D100", ModbusFamily.MELSEC);
|
||||
d.Region.ShouldBe(ModbusRegion.HoldingRegisters);
|
||||
d.Offset.ShouldBe((ushort)100);
|
||||
|
||||
ModbusAddressParser.TryParse("DX12", ModbusFamily.MELSEC, MelsecFamily.Q_L_iQR, out _, out var error).ShouldBeFalse();
|
||||
error.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>Verifies suffix grammar composes correctly with native addresses.</summary>
|
||||
[Fact]
|
||||
public void Suffix_Grammar_Composes_With_Native_Address()
|
||||
|
||||
Reference in New Issue
Block a user