From a88721ce315551e49054a650487697059091f357 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 28 May 2026 09:01:28 -0400 Subject: [PATCH] refactor(driver-twincat): extract TwinCATDriverOptions to .Contracts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move TwinCATDriverOptions and TwinCATDataType enum to a new Driver.TwinCAT.Contracts sibling project. TwinCATDataTypeExtensions (which uses DriverDataType from Core.Abstractions) stays in the runtime driver as TwinCATDataTypeExtensions.cs. Replace two doc-comment references: PollGroupEngine TwinCATAmsAddress.TryParse per the approved decision — no compilable usings were present. The runtime Driver.TwinCAT project gains a ProjectReference to .Contracts; the .slnx is updated accordingly. --- ZB.MOM.WW.OtOpcUa.slnx | 1 + .../TwinCATDataType.cs | 29 ------------------ .../TwinCATDriverOptions.cs | 4 +-- ...WW.OtOpcUa.Driver.TwinCAT.Contracts.csproj | 9 ++++++ .../TwinCATDataTypeExtensions.cs | 30 +++++++++++++++++++ .../ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.csproj | 1 + 6 files changed, 43 insertions(+), 31 deletions(-) rename src/Drivers/{ZB.MOM.WW.OtOpcUa.Driver.TwinCAT => ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts}/TwinCATDataType.cs (51%) rename src/Drivers/{ZB.MOM.WW.OtOpcUa.Driver.TwinCAT => ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts}/TwinCATDriverOptions.cs (95%) create mode 100644 src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts.csproj create mode 100644 src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataTypeExtensions.cs diff --git a/ZB.MOM.WW.OtOpcUa.slnx b/ZB.MOM.WW.OtOpcUa.slnx index 34b52687..30038332 100644 --- a/ZB.MOM.WW.OtOpcUa.slnx +++ b/ZB.MOM.WW.OtOpcUa.slnx @@ -32,6 +32,7 @@ + diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataType.cs b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/TwinCATDataType.cs similarity index 51% rename from src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataType.cs rename to src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/TwinCATDataType.cs index 9b0900aa..8f6851d1 100644 --- a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataType.cs +++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/TwinCATDataType.cs @@ -1,5 +1,3 @@ -using ZB.MOM.WW.OtOpcUa.Core.Abstractions; - namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT; /// @@ -34,30 +32,3 @@ public enum TwinCATDataType /// UDT / FB instance. Resolved per member at discovery time. Structure, } - -/// Extension methods for TwinCATDataType. -public static class TwinCATDataTypeExtensions -{ - /// Maps a TwinCAT data type to the equivalent driver data type. - /// The TwinCAT data type to convert. - /// The corresponding driver data type. - public static DriverDataType ToDriverDataType(this TwinCATDataType t) => t switch - { - TwinCATDataType.Bool => DriverDataType.Boolean, - TwinCATDataType.SInt => DriverDataType.Int16, // signed 8-bit — no narrower OPC UA atom - TwinCATDataType.USInt => DriverDataType.UInt16, // unsigned 8-bit — no narrower OPC UA atom - TwinCATDataType.Int => DriverDataType.Int16, - TwinCATDataType.UInt => DriverDataType.UInt16, - TwinCATDataType.DInt => DriverDataType.Int32, - TwinCATDataType.UDInt => DriverDataType.UInt32, - TwinCATDataType.LInt => DriverDataType.Int64, - TwinCATDataType.ULInt => DriverDataType.UInt64, - TwinCATDataType.Real => DriverDataType.Float32, - TwinCATDataType.LReal => DriverDataType.Float64, - TwinCATDataType.String or TwinCATDataType.WString => DriverDataType.String, - TwinCATDataType.Time or TwinCATDataType.Date - or TwinCATDataType.DateTime or TwinCATDataType.TimeOfDay => DriverDataType.UInt32, - TwinCATDataType.Structure => DriverDataType.String, - _ => DriverDataType.Int32, - }; -} diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDriverOptions.cs b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/TwinCATDriverOptions.cs similarity index 95% rename from src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDriverOptions.cs rename to src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/TwinCATDriverOptions.cs index 22072c29..24aad19a 100644 --- a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDriverOptions.cs +++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/TwinCATDriverOptions.cs @@ -22,7 +22,7 @@ public sealed class TwinCATDriverOptions /// 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 - /// — same semantics as the other + /// PollGroupEngine — same semantics as the other /// libplctag-backed drivers. Set false for deployments where the AMS router has /// notification limits you can't raise. /// @@ -50,7 +50,7 @@ public sealed class TwinCATDriverOptions /// /// One TwinCAT target. must parse via -/// ; misconfigured devices fail driver initialisation. +/// TwinCATAmsAddress.TryParse; misconfigured devices fail driver initialisation. /// public sealed record TwinCATDeviceOptions( string HostAddress, diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts.csproj b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts.csproj new file mode 100644 index 00000000..d911061a --- /dev/null +++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Contracts.csproj @@ -0,0 +1,9 @@ + + + net10.0 + enable + enable + true + + + diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataTypeExtensions.cs b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataTypeExtensions.cs new file mode 100644 index 00000000..bd070be0 --- /dev/null +++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/TwinCATDataTypeExtensions.cs @@ -0,0 +1,30 @@ +using ZB.MOM.WW.OtOpcUa.Core.Abstractions; + +namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT; + +/// Extension methods for TwinCATDataType. +public static class TwinCATDataTypeExtensions +{ + /// Maps a TwinCAT data type to the equivalent driver data type. + /// The TwinCAT data type to convert. + /// The corresponding driver data type. + public static DriverDataType ToDriverDataType(this TwinCATDataType t) => t switch + { + TwinCATDataType.Bool => DriverDataType.Boolean, + TwinCATDataType.SInt => DriverDataType.Int16, // signed 8-bit — no narrower OPC UA atom + TwinCATDataType.USInt => DriverDataType.UInt16, // unsigned 8-bit — no narrower OPC UA atom + TwinCATDataType.Int => DriverDataType.Int16, + TwinCATDataType.UInt => DriverDataType.UInt16, + TwinCATDataType.DInt => DriverDataType.Int32, + TwinCATDataType.UDInt => DriverDataType.UInt32, + TwinCATDataType.LInt => DriverDataType.Int64, + TwinCATDataType.ULInt => DriverDataType.UInt64, + TwinCATDataType.Real => DriverDataType.Float32, + TwinCATDataType.LReal => DriverDataType.Float64, + TwinCATDataType.String or TwinCATDataType.WString => DriverDataType.String, + TwinCATDataType.Time or TwinCATDataType.Date + or TwinCATDataType.DateTime or TwinCATDataType.TimeOfDay => DriverDataType.UInt32, + TwinCATDataType.Structure => DriverDataType.String, + _ => DriverDataType.Int32, + }; +} diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.csproj b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.csproj index 4024f26f..5c41789a 100644 --- a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.csproj +++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.csproj @@ -13,6 +13,7 @@ +