858f300a61
Two new Blazor components surface every Modbus knob added by #136-#144 so users can configure the driver without hand-editing DriverConfig JSON. ModbusAddressEditor.razor (live address-string parser preview): - Bound to a string AddressString + a Family / MelsecSubFamily hint. - On every input keystroke, runs ModbusAddressParser.TryParse and surfaces the resolved breakdown (Region, Offset, DataType, Bit, ByteOrder, ArrayCount, StringLength) inline as a green badge. - On parse error, shows the parser's diagnostic in red. - Re-uses the SAME parser the wire driver uses — grammar drift is impossible by construction. ModbusOptionsEditor.razor (driver-instance options panel): - Connection group (Host / Port / UnitId). - Family group (#144) with conditional MelsecSubFamily dropdown. - Keep-alive group (#139): Enabled / Time / Interval / RetryCount. - Reconnect group (#139): InitialDelay / MaxDelay / BackoffMultiplier. - Protocol group (#140): MaxRegistersPerRead / Write / Coils / ReadGap. - Behaviour toggles (#140 + #141): UseFC15 / UseFC16 / WriteOnChangeOnly. - Bound to ModbusOptionsViewModel — defaults match ModbusDriverOptions defaults so unedited rows produce the historical wire output verbatim. Architecture: - Admin project gains a ProjectReference to Driver.Modbus.Addressing (the shared parser assembly extracted in #136). Admin does NOT take a dep on Driver.Modbus itself — the addressing concerns are cleanly separated from the wire driver. - Same-namespace shared assembly means components reference ModbusAddressParser / ModbusFamily / etc. without prefix gymnastics. Tests: - ModbusOptionsViewModelTests (1 test) — pins every default in the view model against the corresponding ModbusDriverOptions default. A regression that flips an unedited row to a non-default value gets caught here. (Test references both Admin and Driver.Modbus to make the cross-assembly comparison.) - Live Blazor component testing requires bUnit, which isn't currently in the test setup; the parser logic the component wraps is fully covered by the 91 ModbusAddressParser tests in the addressing project, so the glue layer's behaviour is verifiable end-to-end already. Caveat: the wiring into the existing DriverInstance edit page lives in DriversTab.razor — that integration is left as a follow-up because it touches the cluster-edit workflow specifically and the components in this commit are framework-agnostic enough to drop in. The components build clean against the existing Admin project; no behavioural change to other tabs.
170 lines
6.7 KiB
Plaintext
170 lines
6.7 KiB
Plaintext
@using ZB.MOM.WW.OtOpcUa.Driver.Modbus
|
|
|
|
@*
|
|
#145 — Driver-instance options panel for the Modbus driver. Surfaces every option group
|
|
added by #136-#144 so users can configure the driver via the UI rather than hand-editing
|
|
DriverConfig JSON. Bound to a ModbusOptionsViewModel; the parent page round-trips that
|
|
model to the DriverConfig.json column on save.
|
|
*@
|
|
|
|
<div class="modbus-options-editor">
|
|
|
|
<h5>Connection</h5>
|
|
<div class="row mb-3">
|
|
<div class="col-sm-6">
|
|
<label class="form-label">Host</label>
|
|
<input class="form-control" @bind="Model.Host"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Port</label>
|
|
<input type="number" class="form-control" @bind="Model.Port"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Default UnitId</label>
|
|
<input type="number" class="form-control" @bind="Model.UnitId"/>
|
|
</div>
|
|
</div>
|
|
|
|
<h5>Family (#144)</h5>
|
|
<div class="row mb-3">
|
|
<div class="col-sm-6">
|
|
<label class="form-label">PLC family</label>
|
|
<select class="form-select" @bind="Model.Family">
|
|
@foreach (var f in Enum.GetValues<ModbusFamily>())
|
|
{
|
|
<option value="@f">@f</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
@if (Model.Family == ModbusFamily.MELSEC)
|
|
{
|
|
<div class="col-sm-6">
|
|
<label class="form-label">MELSEC sub-family</label>
|
|
<select class="form-select" @bind="Model.MelsecSubFamily">
|
|
@foreach (var f in Enum.GetValues<MelsecFamily>())
|
|
{
|
|
<option value="@f">@f</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<h5>Keep-alive (#139)</h5>
|
|
<div class="row mb-3">
|
|
<div class="col-sm-3">
|
|
<div class="form-check mt-4">
|
|
<input type="checkbox" class="form-check-input" @bind="Model.KeepAliveEnabled"/>
|
|
<label class="form-check-label">Enabled</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Time (s)</label>
|
|
<input type="number" class="form-control" @bind="Model.KeepAliveTimeSec"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Interval (s)</label>
|
|
<input type="number" class="form-control" @bind="Model.KeepAliveIntervalSec"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Retry count</label>
|
|
<input type="number" class="form-control" @bind="Model.KeepAliveRetryCount"/>
|
|
</div>
|
|
</div>
|
|
|
|
<h5>Reconnect (#139)</h5>
|
|
<div class="row mb-3">
|
|
<div class="col-sm-4">
|
|
<label class="form-label">Initial delay (ms)</label>
|
|
<input type="number" class="form-control" @bind="Model.ReconnectInitialDelayMs"/>
|
|
</div>
|
|
<div class="col-sm-4">
|
|
<label class="form-label">Max delay (ms)</label>
|
|
<input type="number" class="form-control" @bind="Model.ReconnectMaxDelayMs"/>
|
|
</div>
|
|
<div class="col-sm-4">
|
|
<label class="form-label">Backoff multiplier</label>
|
|
<input type="number" step="0.1" class="form-control" @bind="Model.ReconnectBackoffMultiplier"/>
|
|
</div>
|
|
</div>
|
|
|
|
<h5>Protocol (#140)</h5>
|
|
<div class="row mb-3">
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Max regs / read</label>
|
|
<input type="number" class="form-control" @bind="Model.MaxRegistersPerRead"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Max regs / write</label>
|
|
<input type="number" class="form-control" @bind="Model.MaxRegistersPerWrite"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Max coils / read</label>
|
|
<input type="number" class="form-control" @bind="Model.MaxCoilsPerRead"/>
|
|
</div>
|
|
<div class="col-sm-3">
|
|
<label class="form-label">Max read gap (#143)</label>
|
|
<input type="number" class="form-control" @bind="Model.MaxReadGap"/>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col-sm-4">
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input" @bind="Model.UseFC15ForSingleCoilWrites"/>
|
|
<label class="form-check-label">Use FC15 for single coil</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-4">
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input" @bind="Model.UseFC16ForSingleRegisterWrites"/>
|
|
<label class="form-check-label">Use FC16 for single reg</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-4">
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input" @bind="Model.WriteOnChangeOnly"/>
|
|
<label class="form-check-label">Write-on-change only (#141)</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter, EditorRequired] public ModbusOptionsViewModel Model { get; set; } = default!;
|
|
|
|
/// <summary>
|
|
/// UI binding model. Maps 1:1 onto the JSON DTO the driver factory accepts; serialised
|
|
/// to DriverConfig.json by the calling save handler. Defaults match
|
|
/// <c>ModbusDriverOptions</c> defaults so unedited rows produce the historical wire
|
|
/// output verbatim.
|
|
/// </summary>
|
|
public sealed class ModbusOptionsViewModel
|
|
{
|
|
public string Host { get; set; } = "127.0.0.1";
|
|
public int Port { get; set; } = 502;
|
|
public byte UnitId { get; set; } = 1;
|
|
public ModbusFamily Family { get; set; } = ModbusFamily.Generic;
|
|
public MelsecFamily MelsecSubFamily { get; set; } = MelsecFamily.Q_L_iQR;
|
|
|
|
public bool KeepAliveEnabled { get; set; } = true;
|
|
public int KeepAliveTimeSec { get; set; } = 30;
|
|
public int KeepAliveIntervalSec { get; set; } = 10;
|
|
public int KeepAliveRetryCount { get; set; } = 3;
|
|
|
|
public int ReconnectInitialDelayMs { get; set; } = 0;
|
|
public int ReconnectMaxDelayMs { get; set; } = 30000;
|
|
public double ReconnectBackoffMultiplier { get; set; } = 2.0;
|
|
|
|
public int MaxRegistersPerRead { get; set; } = 125;
|
|
public int MaxRegistersPerWrite { get; set; } = 123;
|
|
public int MaxCoilsPerRead { get; set; } = 2000;
|
|
public int MaxReadGap { get; set; } = 0;
|
|
|
|
public bool UseFC15ForSingleCoilWrites { get; set; } = false;
|
|
public bool UseFC16ForSingleRegisterWrites { get; set; } = false;
|
|
public bool WriteOnChangeOnly { get; set; } = false;
|
|
}
|
|
}
|