diff --git a/S7.Net/Types/Class.cs b/S7.Net/Types/Class.cs index be84c2b9..8a220e02 100644 --- a/S7.Net/Types/Class.cs +++ b/S7.Net/Types/Class.cs @@ -63,6 +63,11 @@ private static double GetIncreasedNumberOfBytes(double numBytes, Type type, Prop IncrementToEven(ref numBytes); numBytes += attribute.ReservedLengthInBytes; break; + case "DateTime": + IncrementToEven(ref numBytes); + numBytes += 8; + break; + default: var propertyClass = Activator.CreateInstance(type) ?? throw new ArgumentException($"Failed to create instance of type {type}.", nameof(type)); @@ -203,6 +208,14 @@ public static double GetClassSize(object instance, double numBytes = 0.0, bool i }; numBytes += sData.Length; break; + case "DateTime": + IncrementToEven(ref numBytes); + var dateBuffer = new byte[8]; + Array.Copy(bytes, (int)numBytes, dateBuffer, 0, 8); + // hier auswerten + value = DateTime.FromByteArray(dateBuffer); + numBytes += 8; + break; default: var propClass = Activator.CreateInstance(propertyType) ?? throw new ArgumentException($"Failed to create instance of type {propertyType}.", nameof(propertyType)); @@ -310,6 +323,9 @@ private static double SetBytesFromProperty(object propertyValue, PropertyInfo? p _ => throw new ArgumentException("Please use a valid string type for the S7StringAttribute") }; break; + case "DateTime": + bytes2 = DateTime.ToByteArray((System.DateTime)propertyValue); + break; default: numBytes = ToBytes(propertyValue, bytes, numBytes); break;