Skip to content

Commit 5c9a2d7

Browse files
committed
CreateObjectRequest: Optional integrity-id
1 parent 099f902 commit 5c9a2d7

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/S7CommPlusDriver/Core/CreateObjectRequest.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public class CreateObjectRequest : IS7pRequest
3232
public uint IntegrityId { get; set; }
3333
public bool WithIntegrityId { get; set; }
3434

35-
public CreateObjectRequest(byte protocolVersion, UInt16 seqNum)
35+
public CreateObjectRequest(byte protocolVersion, UInt16 seqNum, bool withIntegrityId)
3636
{
3737
ProtocolVersion = protocolVersion;
3838
SequenceNumber = seqNum;
39-
WithIntegrityId = false;
39+
WithIntegrityId = withIntegrityId;
4040
}
4141

4242
public void SetRequestIdValue(UInt32 requestId, PValue requestValue)
@@ -80,13 +80,15 @@ public int Serialize(Stream buffer)
8080
ret += S7p.EncodeByte(buffer, TransportFlags);
8181

8282
// Request set
83-
ret += S7p.EncodeUInt32(buffer, Ids.ObjectServerSessionContainer);
84-
ret += S7p.EncodeByte(buffer, 0x00);
85-
ret += S7p.EncodeByte(buffer, Datatype.UDInt);
86-
ret += S7p.EncodeUInt32Vlq(buffer, 0);
87-
83+
ret += S7p.EncodeUInt32(buffer, RequestId);
84+
ret += RequestValue.Serialize(buffer);
8885
ret += S7p.EncodeUInt32(buffer, 0); // Unknown value 1
8986

87+
if (WithIntegrityId)
88+
{
89+
ret += S7p.EncodeUInt32Vlq(buffer, IntegrityId);
90+
}
91+
9092
// Object
9193
ret += RequestObject.Serialize(buffer);
9294

src/S7CommPlusDriver/S7CommPlusConnection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private UInt32 GetNextIntegrityId(ushort functioncode)
8181
case Functioncode.SetVariable:
8282
case Functioncode.SetVarSubStreamed:
8383
case Functioncode.DeleteObject:
84+
case Functioncode.CreateObject:
8485
if (m_IntegrityId_Set == UInt32.MaxValue)
8586
{
8687
m_IntegrityId_Set = 0;
@@ -435,7 +436,7 @@ public int Connect(string address)
435436

436437
#region Step 3: CreateObjectRequest / Response (with TLS)
437438

438-
var createObjReq = new CreateObjectRequest(ProtocolVersion.V1, 0);
439+
var createObjReq = new CreateObjectRequest(ProtocolVersion.V1, 0, false);
439440
createObjReq.SetNullServerSessionData();
440441
res = SendS7plusFunctionObject(createObjReq);
441442
if (res != 0)

0 commit comments

Comments
 (0)