diff --git a/S7.Net/Enums.cs b/S7.Net/Enums.cs index ff33d04..f4b4778 100644 --- a/S7.Net/Enums.cs +++ b/S7.Net/Enums.cs @@ -181,6 +181,11 @@ /// /// Counter variable type /// - Counter + Counter, + + /// + /// DateTIme variable type + /// + DateTime } } diff --git a/S7.Net/PLCHelpers.cs b/S7.Net/PLCHelpers.cs index d4e5f18..803d349 100644 --- a/S7.Net/PLCHelpers.cs +++ b/S7.Net/PLCHelpers.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using DateTime = S7.Net.Types.DateTime; namespace S7.Net { @@ -146,6 +147,15 @@ namespace S7.Net { return Bit.ToBitArray(bytes); } + case VarType.DateTime: + if (varCount == 1) + { + return DateTime.FromByteArray(bytes); + } + else + { + return DateTime.ToArray(bytes); + } default: return null; } @@ -178,6 +188,8 @@ namespace S7.Net case VarType.DInt: case VarType.Real: return varCount * 4; + case VarType.DateTime: + return varCount * 8; default: return 0; } diff --git a/S7.Net/Protocol/Serialization.cs b/S7.Net/Protocol/Serialization.cs index 40cb629..613c9f4 100644 --- a/S7.Net/Protocol/Serialization.cs +++ b/S7.Net/Protocol/Serialization.cs @@ -41,6 +41,8 @@ namespace S7.Net.Protocol return Types.Double.ToByteArray((double)value); case "Single": return Types.Single.ToByteArray((float)value); + case "DateTime": + return Types.DateTime.ToByteArray((System.DateTime) value); case "Byte[]": return (byte[])value; case "Int16[]": @@ -60,6 +62,8 @@ namespace S7.Net.Protocol // if the consumer does not pay attention to string length. var stringVal = (string) value; return Types.String.ToByteArray(stringVal, stringVal.Length); + case "DateTime[]": + return Types.DateTime.ToByteArray((System.DateTime[]) value); default: throw new InvalidVariableTypeException(); }