using libplctag; namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip; /// /// libplctag-backed . Opens the @udt/{templateId} /// pseudo-tag libplctag exposes for Template Object reads, issues a Read Template /// internally via a normal read call, + returns the raw byte buffer so /// can decode it. /// internal sealed class LibplctagTemplateReader : IAbCipTemplateReader { private Tag? _tag; public async Task ReadAsync( AbCipTagCreateParams deviceParams, uint templateInstanceId, CancellationToken cancellationToken) { _tag?.Dispose(); _tag = new Tag { Gateway = deviceParams.Gateway, Path = deviceParams.CipPath, PlcType = MapPlcType(deviceParams.LibplctagPlcAttribute), Protocol = Protocol.ab_eip, Name = $"@udt/{templateInstanceId}", Timeout = deviceParams.Timeout, }; await _tag.InitializeAsync(cancellationToken).ConfigureAwait(false); await _tag.ReadAsync(cancellationToken).ConfigureAwait(false); return _tag.GetBuffer(); } public void Dispose() => _tag?.Dispose(); private static PlcType MapPlcType(string attribute) => attribute switch { "controllogix" => PlcType.ControlLogix, "compactlogix" => PlcType.ControlLogix, "micro800" => PlcType.Micro800, _ => PlcType.ControlLogix, }; } internal sealed class LibplctagTemplateReaderFactory : IAbCipTemplateReaderFactory { public IAbCipTemplateReader Create() => new LibplctagTemplateReader(); }