diff --git a/LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Parameter.cs b/LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Parameter.cs index 212b0977..5c86ccdc 100644 --- a/LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Parameter.cs +++ b/LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Parameter.cs @@ -522,7 +522,15 @@ internal static S7DataRow GetInterfaceOrDBFromStep7ProjectString(string txt, ref addRW.StringSize = Convert.ToInt32(tmpType.Substring(pos1 + 1, pos2 - pos1 - 2)); } else - addRW.DataType = (S7DataRowType)Enum.Parse(typeof(S7DataRowType), tmpType.Replace("\0", "").Replace("\t", "").Replace(";", "").Trim().ToUpper()); + { + string typeName = tmpType.Replace("\0", "").Replace("\t", "").Replace(";", "").Trim().ToUpper(); + // STEP 7 accepts these short forms as type keywords + if (typeName == "TOD") + typeName = "TIME_OF_DAY"; + else if (typeName == "DT") + typeName = "DATE_AND_TIME"; + addRW.DataType = (S7DataRowType)Enum.Parse(typeof(S7DataRowType), typeName); + } addRW.DataTypeBlockNumber = akRowTypeNumber; diff --git a/ToolBoxLibUnitTests/TestDataBlockReading.cs b/ToolBoxLibUnitTests/TestDataBlockReading.cs index 4aaeca66..493e54f3 100644 --- a/ToolBoxLibUnitTests/TestDataBlockReading.cs +++ b/ToolBoxLibUnitTests/TestDataBlockReading.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; -using DotNetSiemensPLCToolBoxLibrary.DataTypes; -using DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V5; -using DotNetSiemensPLCToolBoxLibrary.DataTypes.Projectfolders.Step7V5; -using DotNetSiemensPLCToolBoxLibrary.DataTypes.AWL.Step7V5; -using NUnit.Framework; +using System.Collections.Generic; +using DotNetSiemensPLCToolBoxLibrary.DataTypes; +using DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V5; +using DotNetSiemensPLCToolBoxLibrary.DataTypes.Projectfolders.Step7V5; +using DotNetSiemensPLCToolBoxLibrary.DataTypes.AWL.Step7V5; +using NUnit.Framework; using NUnit.Framework.Legacy; -namespace ToolBoxLibUnitTests +namespace ToolBoxLibUnitTests { [TestFixture] public class TestDataBlockReading @@ -99,5 +99,21 @@ public void TestDB4() var rw = test.Children[0] as S7DataRow; var callStr = rw.GetCallingString(); } - } -} + + [Test] + public void TestDBShortTypeNames() + { + var txt = "\r\n STRUCT \t\r\n a : TOD ;\t\r\n b : DT ;\t\r\n END_STRUCT ;\t"; + var par1 = new List(); + var test = + DotNetSiemensPLCToolBoxLibrary.PLCs.S7_xxx.MC7.Parameter.GetInterfaceOrDBFromStep7ProjectString(txt, + ref par1, + PLCBlockType + .DB, + false, + new BlocksOfflineFolder(), new S7Block(), new S7ConvertingOptions()); + ClassicAssert.AreEqual(S7DataRowType.TIME_OF_DAY, ((S7DataRow)test.Children[0]).DataType); + ClassicAssert.AreEqual(S7DataRowType.DATE_AND_TIME, ((S7DataRow)test.Children[1]).DataType); + } + } +}