using System.ComponentModel.DataAnnotations; namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT; /// /// TwinCAT ADS driver configuration. One instance supports N targets (each identified by /// an AMS Net ID + port). Compiles + runs without a local AMS router but every wire call /// fails with BadCommunicationError until a router is reachable. /// public sealed class TwinCATDriverOptions { /// Gets the list of TwinCAT devices to connect to. public IReadOnlyList Devices { get; init; } = []; /// Gets the list of TwinCAT tag definitions. public IReadOnlyList Tags { get; init; } = []; /// Gets the probe options for TwinCAT connection probing. public TwinCATProbeOptions Probe { get; init; } = new(); /// Gets the default communication timeout. public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(2); /// /// When true (default), SubscribeAsync registers native ADS notifications /// via AddDeviceNotificationExAsync — the PLC pushes changes on its own cycle /// rather than the driver polling. Strictly better for latency + CPU when the target /// supports it (TC2 + TC3 PLC runtimes always do; some soft-PLC / third-party ADS /// implementations may not). When false, the driver falls through to the shared /// PollGroupEngine — same semantics as the other /// libplctag-backed drivers. Set false for deployments where the AMS router has /// notification limits you can't raise. /// public bool UseNativeNotifications { get; init; } = true; /// /// When true, DiscoverAsync walks each device's symbol table via the /// TwinCAT SymbolLoaderFactory (flat mode) + surfaces controller-resident /// globals / program locals under a Discovered/ sub-folder. Pre-declared tags /// from always emit regardless. Default false to preserve /// the strict-config path for deployments where only declared tags should appear. /// public bool EnableControllerBrowse { get; init; } /// /// Maximum batching delay in milliseconds for ADS device notifications. Passed to /// NotificationSettings as the max-delay value: TwinCAT may coalesce notifications /// up to this delay before pushing them. 0 (default) = no batching, push /// immediately. Useful for high-churn signals where the OPC UA subscriber tolerates a /// small delay in exchange for fewer wire round-trips. Listed in docs/v2/driver-specs.md /// section 6 — was previously hard-coded to 0 (Driver.TwinCAT-014). /// public int NotificationMaxDelayMs { get; init; } /// /// Timeout for the AdminUI Test Connect probe, in seconds. The AdminUI clamps to a /// 60s server-side maximum; this default is what the form pre-fills for new instances. /// [Display(Name = "Probe timeout (seconds)", Description = "Connection test timeout. Default 10s.", GroupName = "Diagnostics")] [Range(1, 60)] public int ProbeTimeoutSeconds { get; init; } = 10; } /// /// One TwinCAT target. must parse via /// TwinCATAmsAddress.TryParse; misconfigured devices fail driver initialisation. /// public sealed record TwinCATDeviceOptions( string HostAddress, string? DeviceName = null); /// /// One TwinCAT-backed OPC UA variable. is the full TwinCAT /// symbolic name (e.g. MAIN.bStart, GVL.Counter, Motor1.Status.Running). /// /// /// When non-null, this tag is a 1-D array of elements of /// . Drives IsArray/ArrayDim at discovery and a /// native ADS array read at runtime (Phase 4c). null = scalar (the default). /// public sealed record TwinCATTagDefinition( string Name, string DeviceHostAddress, string SymbolPath, TwinCATDataType DataType, bool Writable = true, bool WriteIdempotent = false, int? ArrayLength = null); /// Probe options for TwinCAT connection monitoring. public sealed class TwinCATProbeOptions { /// Gets a value indicating whether probing is enabled. public bool Enabled { get; init; } = true; /// Gets the probe interval. public TimeSpan Interval { get; init; } = TimeSpan.FromSeconds(5); /// Gets the probe timeout. public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(2); }