Skip to content

Commit 7ce2722

Browse files
committed
DeleteObject: Parameter for integrity yes/no
1 parent 676c95a commit 7ce2722

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/S7CommPlusDriver/Core/DeleteObjectResponse.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class DeleteObjectResponse : IS7pResponse
3030
public uint IntegrityId { get; set; }
3131
public bool WithIntegrityId { get; set; }
3232

33-
public DeleteObjectResponse(byte protocolVersion)
33+
public DeleteObjectResponse(byte protocolVersion, bool withIntegrityId)
3434
{
3535
ProtocolVersion = protocolVersion;
36-
WithIntegrityId = false;
36+
WithIntegrityId = withIntegrityId; // When deleting the Sesssion Object-Id, there's no Integrity-Id!
3737
}
3838

3939
public int Deserialize(Stream buffer)
@@ -52,7 +52,11 @@ public int Deserialize(Stream buffer)
5252
PObject errorObject = new PObject();
5353
ret += S7p.DecodeObject(buffer, ref errorObject);
5454
}
55-
55+
if (WithIntegrityId)
56+
{
57+
ret += S7p.DecodeUInt32Vlq(buffer, out uint iid);
58+
IntegrityId = iid;
59+
}
5660
return ret;
5761
}
5862

@@ -71,7 +75,7 @@ public override string ToString()
7175
return s;
7276
}
7377

74-
public static DeleteObjectResponse DeserializeFromPdu(Stream pdu)
78+
public static DeleteObjectResponse DeserializeFromPdu(Stream pdu, bool withIntegrityId)
7579
{
7680
byte protocolVersion;
7781
byte opcode;
@@ -91,7 +95,7 @@ public static DeleteObjectResponse DeserializeFromPdu(Stream pdu)
9195
{
9296
return null;
9397
}
94-
DeleteObjectResponse resp = new DeleteObjectResponse(protocolVersion);
98+
DeleteObjectResponse resp = new DeleteObjectResponse(protocolVersion, withIntegrityId);
9599
resp.Deserialize(pdu);
96100

97101
return resp;

src/S7CommPlusDriver/S7CommPlusConnection.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Threading;
2020
using System.IO;
2121
using System.Linq;
22+
using System.Diagnostics;
2223

2324
namespace S7CommPlusDriver
2425
{
@@ -540,15 +541,16 @@ private int DeleteObject(uint deleteObjectId)
540541
// And the error code gives an error, but not a fatal one.
541542
// If we delete another object, there should be an IntegrityId in the response, and
542543
// the response gives no error.
543-
var delRes = DeleteObjectResponse.DeserializeFromPdu(m_ReceivedStream);
544544
if (deleteObjectId == m_SessionId)
545545
{
546-
Console.WriteLine("S7CommPlusConnection - DeleteSession: Deleted our own Session Id object, not checking the response.");
546+
var delRes = DeleteObjectResponse.DeserializeFromPdu(m_ReceivedStream, false);
547+
Trace.WriteLine("S7CommPlusConnection - DeleteSession: Deleted our own Session Id object, not checking the response.");
547548
m_SessionId = 0; // not valid anymore
548549
m_SessionId2 = 0;
549550
}
550551
else
551552
{
553+
var delRes = DeleteObjectResponse.DeserializeFromPdu(m_ReceivedStream, true);
552554
res = checkResponseWithIntegrity(delReq, delRes);
553555
if (res != 0)
554556
{

0 commit comments

Comments
 (0)