namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip;
///
/// Thin wire-layer abstraction over a single CIP tag. The driver holds one instance per
/// (device, tag path) pair; the default implementation delegates to
/// . Tests swap in a fake via
/// so the driver's read / write / status-mapping logic can
/// be exercised without a running PLC or the native libplctag binary.
///
public interface IAbCipTagRuntime : IDisposable
{
/// Create the underlying native tag (equivalent to libplctag's plc_tag_create).
Task InitializeAsync(CancellationToken cancellationToken);
/// Issue a read; on completion the local buffer holds the current PLC value.
Task ReadAsync(CancellationToken cancellationToken);
/// Flush the local buffer to the PLC.
Task WriteAsync(CancellationToken cancellationToken);
///
/// Raw libplctag status code — mapped to an OPC UA StatusCode via
/// . Zero on success, negative on error.
///
int GetStatus();
///
/// Decode the local buffer into a boxed .NET value per the tag's configured type.
/// is non-null only for BOOL-within-DINT tags captured in
/// the .N syntax at parse time.
///
object? DecodeValue(AbCipDataType type, int? bitIndex);
///
/// Encode into the local buffer per the tag's type. Callers
/// pair this with .
///
void EncodeValue(AbCipDataType type, int? bitIndex, object? value);
}
///
/// Factory for per-tag runtime handles. Instantiated once per driver, consumed per
/// (device, tag path) pair at the first read/write.
///
public interface IAbCipTagFactory
{
IAbCipTagRuntime Create(AbCipTagCreateParams createParams);
}
/// Everything libplctag needs to materialise a tag handle.
/// Gateway IP / hostname parsed from .
/// EtherNet/IP TCP port — default 44818.
/// CIP route path, e.g. 1,0. Empty for Micro800.
/// libplctag plc=... attribute, per family profile.
/// Logix symbolic tag name as emitted by .
/// libplctag operation timeout (applies to Initialize / Read / Write).
public sealed record AbCipTagCreateParams(
string Gateway,
int Port,
string CipPath,
string LibplctagPlcAttribute,
string TagName,
TimeSpan Timeout);