Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions S7.Net/Types/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down