Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
34 changes: 25 additions & 9 deletions ToolBoxLibUnitTests/TestDataBlockReading.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<string>();
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);
}
}
}
Loading