Auto: focas-f2b — multi-path/multi-channel CNC

Adds optional `@N` path suffix to FocasAddress (PARAM:1815@2, R100@3.0,
MACRO:500@2, DIAG:280@2/1) with PathId defaulting to 1 for back-compat.
Per-device PathCount is discovered via cnc_rdpathnum at first connect and
cached on DeviceState; reads with PathId>PathCount return BadOutOfRange.
The driver issues cnc_setpath before each non-default-path read and
tracks LastSetPath so repeat reads on the same path skip the wire call.

Closes #264
This commit is contained in:
Joseph Doherty
2026-04-25 19:42:58 -04:00
parent 3b82f4f5fb
commit 2f3eeecd17
7 changed files with 478 additions and 17 deletions

View File

@@ -139,6 +139,26 @@ internal sealed class FwlibFocasClient : IFocasClient
}
}
public Task<int> GetPathCountAsync(CancellationToken cancellationToken)
{
if (!_connected) return Task.FromResult(1);
var buf = new FwlibNative.ODBPATH();
var ret = FwlibNative.RdPathNum(_handle, ref buf);
// EW_FUNC / EW_NOOPT on single-path controllers — fall back to 1 rather than failing.
if (ret != 0 || buf.MaxPath < 1) return Task.FromResult(1);
return Task.FromResult((int)buf.MaxPath);
}
public Task SetPathAsync(int pathId, CancellationToken cancellationToken)
{
if (!_connected) return Task.CompletedTask;
var ret = FwlibNative.SetPath(_handle, (short)pathId);
if (ret != 0)
throw new InvalidOperationException(
$"FWLIB cnc_setpath failed with EW_{ret} switching to path {pathId}.");
return Task.CompletedTask;
}
public Task<bool> ProbeAsync(CancellationToken cancellationToken)
{
if (!_connected) return Task.FromResult(false);