feat(modbus): wire Family / MelsecSubFamily / DisableFC23, and the form's timing keys

U1: a tag's addressString (Modicon / mnemonic / DL205 V-memory / MELSEC
D-X-Y grammar) now resolves through ModbusAddressParser with the DRIVER's
Family and MelsecSubFamily at every initialize and is authoritative; the
family-unaware gates (deploy Inspect, AdminUI parse consult) accept what
some family resolves. The tag editor gets an address-text field that
resolves with the owning driver's family and persists both the string and
the resolved region/offset/type fields; a hand edit drops the string.
DisableFC23 now gates FC23: by default a 2..121-register holding write is
one FC23 write + read-back (a unit answering exception 01, or failing FC23 at
the transport, moves to FC16 for the rest of the generation); RTU framing
deframes the FC23 reply. Live-checked: the pymodbus fixture implements FC23.
Also: the AdminUI driver form serialises ModbusDriverOptions (TimeSpan
strings), which the factory DTO never read - every timing field on the form
was dead. The DTO now accepts both shapes (*Ms keys win).

Refs #741
Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
Joseph Doherty
2026-10-22 15:35:58 -04:00
parent 1adc9d65e1
commit 4a3d7a9361
13 changed files with 656 additions and 58 deletions
@@ -30,6 +30,74 @@ public sealed class ModbusTagConfigModel
/// key stays absent.</summary>
public bool? Writable { get; set; }
/// <summary>
/// The address in the parser grammar (<c>40001:F:CDAB</c>, DL205 <c>V2000</c>, MELSEC <c>D100</c>) when
/// the tag was authored that way; <c>null</c> for a tag authored by region + numeric address. When
/// present the driver re-resolves it with ITS family at runtime, so it is authoritative — editing any
/// resolved field by hand clears it (<see cref="ClearAddressString"/>).
/// </summary>
public string? AddressString { get; set; }
/// <summary>
/// Resolves an address string through <see cref="ModbusAddressParser"/> with the owning driver's
/// family and copies the result into the region / offset / type / bit / string-length / byte-order /
/// array fields — the "persist the resolved region/offset" half of the family wiring, so the blob is
/// readable on its own and the editor shows what the driver will poll.
/// </summary>
/// <param name="text">The address text the operator typed.</param>
/// <param name="family">The driver's PLC family.</param>
/// <param name="melsecSubFamily">The driver's MELSEC sub-family.</param>
/// <returns><c>null</c> on success, else the parser's error.</returns>
public string? ResolveAddress(string? text, ModbusFamily family, MelsecFamily melsecSubFamily)
{
if (!ModbusAddressParser.TryParse(text, family, melsecSubFamily, out var parsed, out var error) || parsed is null)
return error ?? "Address did not parse.";
AddressString = text!.Trim();
Region = parsed.Region;
Address = parsed.Offset;
DataType = parsed.DataType;
ByteOrder = parsed.ByteOrder;
BitIndex = parsed.Bit ?? 0;
StringLength = parsed.StringLength;
if (parsed.ArrayCount is { } count)
{
TagConfigJson.Set(_bag, "isArray", true);
TagConfigJson.Set(_bag, "arrayLength", count);
}
else
{
_bag.Remove("isArray");
_bag.Remove("arrayLength");
}
return null;
}
/// <summary>Drops the address string so the hand-edited region / address fields are what the driver reads.</summary>
public void ClearAddressString() => AddressString = null;
/// <summary>
/// Reads the owning driver's <c>family</c> / <c>melsecSubFamily</c> from its DriverConfig JSON (keys
/// matched case-insensitively, like the driver's DTO binding); Generic / Q_L_iQR when absent or unknown.
/// </summary>
/// <param name="driverConfigJson">The driver's DriverConfig JSON.</param>
/// <returns>The family pair the driver will resolve address strings with.</returns>
public static (ModbusFamily Family, MelsecFamily MelsecSubFamily) ReadFamily(string? driverConfigJson)
{
var family = ModbusFamily.Generic;
var sub = MelsecFamily.Q_L_iQR;
var o = TagConfigJson.ParseOrNew(driverConfigJson);
foreach (var (key, node) in o)
{
var text = node is JsonValue v && v.TryGetValue<string>(out var str) ? str : null;
if (text is null) continue;
if (string.Equals(key, "family", StringComparison.OrdinalIgnoreCase)
&& Enum.TryParse<ModbusFamily>(text, ignoreCase: true, out var f)) family = f;
else if (string.Equals(key, "melsecSubFamily", StringComparison.OrdinalIgnoreCase)
&& Enum.TryParse<MelsecFamily>(text, ignoreCase: true, out var m)) sub = m;
}
return (family, sub);
}
/// <summary>
/// Changes the region and keeps the data type compatible with it (the driver refuses a bit region
/// with a non-Bool type, and a register region with Bool): switching to Coils / DiscreteInputs selects
@@ -69,6 +137,8 @@ public sealed class ModbusTagConfigModel
BitIndex = TagConfigJson.GetInt(o, "bitIndex"),
StringLength = TagConfigJson.GetInt(o, "stringLength"),
Writable = TagConfigJson.GetBoolNullable(o, "writable"),
AddressString = string.IsNullOrWhiteSpace(TagConfigJson.GetString(o, "addressString"))
? null : TagConfigJson.GetString(o, "addressString"),
_bag = o,
};
}
@@ -85,6 +155,7 @@ public sealed class ModbusTagConfigModel
TagConfigJson.Set(_bag, "bitIndex", BitIndex);
TagConfigJson.Set(_bag, "stringLength", StringLength);
TagConfigJson.Set(_bag, "writable", Writable);
TagConfigJson.Set(_bag, "addressString", AddressString);
return TagConfigJson.Serialize(_bag);
}
@@ -124,7 +195,7 @@ public sealed class ModbusTagConfigModel
?? TagConfigJson.DescribeInvalidEnum<ModbusStringByteOrder>(_bag, "stringByteOrder")
?? TagConfigParseGate.Describe(
_source,
j => ModbusTagDefinitionFactory.FromTagConfig(j, TagConfigParseGate.AuthoringRawPath, out _),
j => ModbusTagDefinitionFactory.FromTagConfigAnyFamily(j, TagConfigParseGate.AuthoringRawPath, out _),
ModbusTagDefinitionFactory.Inspect,
"Modbus");
}