Skip to content

Commit a3cf902

Browse files
authored
Merge pull request #211 from ryan2445/master
step7v5: handle interface timestamp conflicts in GetInterface(string blkName, S7ConvertingOptions myConvOpt)
2 parents d69267f + b269853 commit a3cf902

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

LibNoDaveConnectionLibrary/DataTypes/Blocks/Step7V5/S7Block.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,6 @@ public class S7Block : Block
9898
/// </summary>
9999
public DateTime LastInterfaceChangeHistory { get; set; }
100100

101-
/// <summary>
102-
/// Returns true if the plaintext interface timestamp is different from the MC7 interface timestamp
103-
/// The default value of DateTime is DateTime.MinValue, so also check to make sure that both values are set
104-
/// </summary>
105-
public bool HasInterfaceTimestampConflict
106-
{
107-
get
108-
{
109-
if (!LastInterfaceChangeHistory.Equals(DateTime.MinValue) &&
110-
!LastInterfaceChange.Equals(DateTime.MinValue) &&
111-
!LastInterfaceChangeHistory.Equals(LastInterfaceChange))
112-
{
113-
return true;
114-
}
115-
116-
return false;
117-
}
118-
}
119-
120101
/// <summary>
121102
/// The total size of the Interface table
122103
/// </summary>
@@ -236,6 +217,22 @@ public enum S7BlockAtributes: byte
236217
//ReadOnly
237218

238219
}
220+
221+
/// <summary>
222+
/// Returns true if dt1 and dt2 are not equal
223+
/// Also checks that both values are not the default value (DateTime.MinValue)
224+
/// </summary>
225+
public static bool HasTimestampConflict(DateTime dt1, DateTime dt2)
226+
{
227+
if (!dt1.Equals(DateTime.MinValue) &&
228+
!dt2.Equals(DateTime.MinValue) &&
229+
!dt1.Equals(dt2))
230+
{
231+
return true;
232+
}
233+
234+
return false;
235+
}
239236
}
240237
}
241238

LibNoDaveConnectionLibrary/DataTypes/Blocks/Step7V5/S7DataBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public IDataRow Structure
5555
{
5656
bool checkIFaceConflict = usedS7ConvertingOptions != null && usedS7ConvertingOptions.CheckForInterfaceTimestampConflicts;
5757

58-
if ((!checkIFaceConflict && StructureFromString != null) || (checkIFaceConflict && !HasInterfaceTimestampConflict))
58+
if ((!checkIFaceConflict && StructureFromString != null) || (checkIFaceConflict && !HasTimestampConflict(LastInterfaceChange, LastInterfaceChangeHistory)))
5959
{
6060
return StructureFromString;
6161
}

LibNoDaveConnectionLibrary/DataTypes/Projectfolders/Step7V5/BlocksOfflineFolder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,14 @@ public S7DataRow GetInterface(string blkName, S7ConvertingOptions myConvOpt)
449449
return null;
450450
TmpBlock myTmpBlk = GetBlockBytes(blkInfo);
451451
List<string> tmpPar = new List<string>();
452-
return Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref tmpPar, blkInfo.BlockType, false, this, null, myConvOpt);
452+
if (myConvOpt.CheckForInterfaceTimestampConflicts && S7Block.HasTimestampConflict(myTmpBlk.LastInterfaceChange, myTmpBlk.LastInterfaceChangeHistory))
453+
{
454+
return GetInterfaceStructureFromMC7(blkInfo, myTmpBlk, null, ref tmpPar);
455+
}
456+
else
457+
{
458+
return Parameter.GetInterfaceOrDBFromStep7ProjectString(myTmpBlk.blkinterface, ref tmpPar, blkInfo.BlockType, false, this, null, myConvOpt);
459+
}
453460
}
454461

455462
/// <summary>
@@ -625,7 +632,7 @@ public Block GetBlock(ProjectBlockInfo blkInfo, S7ConvertingOptions myConvOpt)
625632
retVal.Author = myTmpBlk.username;
626633
retVal.Version = myTmpBlk.version;
627634

628-
if (myConvOpt.CheckForInterfaceTimestampConflicts && retVal.HasInterfaceTimestampConflict)
635+
if (myConvOpt.CheckForInterfaceTimestampConflicts && S7Block.HasTimestampConflict(retVal.LastInterfaceChange, retVal.LastInterfaceChangeHistory))
629636
{
630637
retVal.Parameter = GetInterfaceStructureFromMC7(blkInfo, myTmpBlk, retVal, ref ParaList);
631638
}

0 commit comments

Comments
 (0)