Skip to content

Commit ef2149b

Browse files
committed
rmeove some console messages and add more errors
1 parent 5c239f8 commit ef2149b

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

src/S7CommPlusDriver/Net/S7Consts.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ public static class S7Consts
3434
public const int errTCPUnreachableHost = 0x00002751;
3535

3636
public const int errIsoConnect = 0x00010000; // Connection error
37-
public const int errIsoInvalidPDU = 0x00030000; // Bad format
37+
public const int errIsoInvalidPDU = 0x00030000; // Bad format
38+
public const int errIsoInvalidPDU1 = 0x00030001; // Bad format
39+
public const int errIsoInvalidPDU2 = 0x00030002; // Bad format
40+
public const int errIsoInvalidPDU3 = 0x00030003; // Bad format
41+
public const int errIsoInvalidPDU4 = 0x00030004; // Bad format
42+
public const int errIsoInvalidPDU5 = 0x00030005; // Bad format
43+
public const int errIsoInvalidPDU6 = 0x00030006; // Bad format
44+
public const int errIsoInvalidPDU7 = 0x00030007; // Bad format
45+
public const int errIsoInvalidPDU8 = 0x00030008; // Bad format
46+
public const int errIsoInvalidPDU9 = 0x00030009; // Bad format
47+
public const int errIsoInvalidPDU10 = 0x00030010; // Bad format
48+
public const int errIsoInvalidPDU11 = 0x00030011; // Bad format
49+
public const int errIsoInvalidPDU12 = 0x00030012; // Bad format
3850
public const int errIsoInvalidDataSize = 0x00040000; // Bad Datasize passed to send/recv : buffer is invalid
3951

4052
public const int errCliNegotiatingPDU = 0x00100000;
@@ -74,10 +86,11 @@ public static class S7Consts
7486
public const int errCliCannotChangeParam = 0x02600000;
7587
public const int errCliFunctionNotImplemented = 0x02700000;
7688

77-
public const int errOpenSSL = 0x03100000;
78-
//------------------------------------------------------------------------------
79-
// PARAMS LIST FOR COMPATIBILITY WITH Snap7.net.cs
80-
//------------------------------------------------------------------------------
89+
public const int errOpenSSL = 0x03100000;
90+
public const int errInitSslResponse = 0x03100001;
91+
//------------------------------------------------------------------------------
92+
// PARAMS LIST FOR COMPATIBILITY WITH Snap7.net.cs
93+
//------------------------------------------------------------------------------
8194
public const Int32 p_u16_LocalPort = 1; // Not applicable here
8295
public const Int32 p_u16_RemotePort = 2;
8396
public const Int32 p_i32_PingTimeout = 3;

src/S7CommPlusDriver/S7CommPlusConnection.cs

+22-23
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@ private void OnDataReceived(byte[] PDU, int len)
261261
if (PDU[pos] != 0x72)
262262
{
263263
m_ReceivedNeedMoreDataForCompletePDU = false;
264-
m_LastError = S7Consts.errIsoInvalidPDU;
264+
m_LastError = S7Consts.errIsoInvalidPDU1;
265265
return;
266266
}
267267
pos++;
268268
protoVersion = PDU[pos];
269269
if (protoVersion != ProtocolVersion.V1 && protoVersion != ProtocolVersion.V2 && protoVersion != ProtocolVersion.V3 && protoVersion != ProtocolVersion.SystemEvent)
270270
{
271271
m_ReceivedNeedMoreDataForCompletePDU = false;
272-
m_LastError = S7Consts.errIsoInvalidPDU;
272+
m_LastError = S7Consts.errIsoInvalidPDU2;
273273
return;
274274
}
275275
// For the first fragment, write the ProtocolVersion into the stream in advance
@@ -303,7 +303,7 @@ private void OnDataReceived(byte[] PDU, int len)
303303
{
304304
Console.WriteLine("S7CommPlusConnection - OnDataReceived: SystemEvent has fatal error");
305305
// Termination neccessary
306-
m_LastError = S7Consts.errIsoInvalidPDU;
306+
m_LastError = S7Consts.errIsoInvalidPDU3;
307307
}
308308
else
309309
{
@@ -364,13 +364,13 @@ private int checkResponseWithIntegrity(IS7pRequest request, IS7pResponse respons
364364
{
365365
if (response == null)
366366
{
367-
Console.WriteLine("checkResponseWithIntegrity: ERROR! response == null");
368-
return S7Consts.errIsoInvalidPDU;
367+
//Console.WriteLine("checkResponseWithIntegrity: ERROR! response == null");
368+
return S7Consts.errIsoInvalidPDU4;
369369
}
370370
if (request.SequenceNumber != response.SequenceNumber)
371371
{
372-
Console.WriteLine(String.Format("checkResponseWithIntegrity: ERROR! SeqenceNumber of Response ({0}) doesn't match Request ({1})", response.SequenceNumber, request.SequenceNumber));
373-
return S7Consts.errIsoInvalidPDU;
372+
//Console.WriteLine(String.Format("checkResponseWithIntegrity: ERROR! SeqenceNumber of Response ({0}) doesn't match Request ({1})", response.SequenceNumber, request.SequenceNumber));
373+
return S7Consts.errIsoInvalidPDU5;
374374
}
375375
// Overflow is possible and allowed
376376
UInt32 reqIntegCheck = (UInt32)request.SequenceNumber + request.IntegrityId;
@@ -428,9 +428,8 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
428428
sslRes = InitSslResponse.DeserializeFromPdu(m_ReceivedPDU);
429429
if (sslRes == null)
430430
{
431-
Console.WriteLine("S7CommPlusConnection - Connect: InitSslResponse with Error!");
432431
m_client.Disconnect();
433-
return m_LastError;
432+
return S7Consts.errInitSslResponse;
434433
}
435434

436435
#endregion
@@ -467,15 +466,15 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
467466
var createObjRes = CreateObjectResponse.DeserializeFromPdu(m_ReceivedPDU);
468467
if (createObjRes == null)
469468
{
470-
Console.WriteLine("S7CommPlusConnection - Connect: CreateObjectResponse with Error!");
469+
//Console.WriteLine("S7CommPlusConnection - Connect: CreateObjectResponse with Error!");
471470
m_client.Disconnect();
472-
return S7Consts.errIsoInvalidPDU;
471+
return S7Consts.errIsoInvalidPDU6;
473472
}
474473
// There are (always?) at least two IDs in the response.
475474
// Usually the first is used for polling data, and the 2nd for jobs which use notifications, e.g. alarming, subscriptions.
476475
m_SessionId = createObjRes.ObjectIds[0];
477476
m_SessionId2 = createObjRes.ObjectIds[1];
478-
Console.WriteLine("S7CommPlusConnection - Connect: Using SessionId=0x" + String.Format("{0:X04}", m_SessionId));
477+
//Console.WriteLine("S7CommPlusConnection - Connect: Using SessionId=0x" + String.Format("{0:X04}", m_SessionId));
479478

480479
// Evaluate Struct 314
481480
PValue sval = createObjRes.ResponseObject.GetAttribute(Ids.ServerSessionVersion);
@@ -504,9 +503,9 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
504503
var setMultiVarRes = SetMultiVariablesResponse.DeserializeFromPdu(m_ReceivedPDU);
505504
if (setMultiVarRes == null)
506505
{
507-
Console.WriteLine("S7CommPlusConnection - Connect: SetMultiVariablesResponse with Error!");
506+
//Console.WriteLine("S7CommPlusConnection - Connect: SetMultiVariablesResponse with Error!");
508507
m_client.Disconnect();
509-
return S7Consts.errIsoInvalidPDU;
508+
return S7Consts.errIsoInvalidPDU7;
510509
}
511510

512511
#endregion
@@ -543,9 +542,9 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
543542
var getVarSubstreamedRes = GetVarSubstreamedResponse.DeserializeFromPdu(m_ReceivedPDU);
544543
if (getVarSubstreamedRes == null)
545544
{
546-
Console.WriteLine("S7CommPlusConnection - Connect.Password: GetVarSubstreamedResponse with Error!");
545+
//Console.WriteLine("S7CommPlusConnection - Connect.Password: GetVarSubstreamedResponse with Error!");
547546
m_client.Disconnect();
548-
return S7Consts.errIsoInvalidPDU;
547+
return S7Consts.errIsoInvalidPDU8;
549548
}
550549

551550
// Check access level
@@ -574,9 +573,9 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
574573
var getVarSubstreamedRes_challenge = GetVarSubstreamedResponse.DeserializeFromPdu(m_ReceivedPDU);
575574
if (getVarSubstreamedRes_challenge == null)
576575
{
577-
Console.WriteLine("S7CommPlusConnection - Connect.Password: getVarSubstreamedRes_challenge with Error!");
576+
//Console.WriteLine("S7CommPlusConnection - Connect.Password: getVarSubstreamedRes_challenge with Error!");
578577
m_client.Disconnect();
579-
return S7Consts.errIsoInvalidPDU;
578+
return S7Consts.errIsoInvalidPDU9;
580579
}
581580

582581
byte[] challenge = (getVarSubstreamedRes_challenge.Value as ValueUSIntArray).GetValue();
@@ -589,9 +588,9 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
589588
}
590589
if (challengeResponse.Length != challenge.Length)
591590
{
592-
Console.WriteLine("S7CommPlusConnection - Connect.Password: challengeResponse.Length != challenge.Length");
591+
//Console.WriteLine("S7CommPlusConnection - Connect.Password: challengeResponse.Length != challenge.Length");
593592
m_client.Disconnect();
594-
return S7Consts.errIsoInvalidPDU;
593+
return S7Consts.errIsoInvalidPDU10;
595594
}
596595
for (int i = 0; i < challengeResponse.Length; ++i)
597596
{
@@ -623,7 +622,7 @@ public int Connect(string address, string password = "", int timeoutMs = 5000)
623622
{
624623
Console.WriteLine("S7CommPlusConnection - Connect.Password: setVariableResponse with Error!");
625624
m_client.Disconnect();
626-
return S7Consts.errIsoInvalidPDU;
625+
return S7Consts.errIsoInvalidPDU11;
627626
}
628627

629628
}
@@ -845,9 +844,9 @@ public int SetPlcOperatingState(Int32 state)
845844
var setVarRes = SetVariableResponse.DeserializeFromPdu(m_ReceivedPDU);
846845
if (setVarRes == null)
847846
{
848-
Console.WriteLine("S7CommPlusConnection - Connect: SetVariableResponse with Error!");
847+
//Console.WriteLine("S7CommPlusConnection - Connect: SetVariableResponse with Error!");
849848
m_client.Disconnect();
850-
return S7Consts.errIsoInvalidPDU;
849+
return S7Consts.errIsoInvalidPDU12;
851850
}
852851

853852
return 0;

0 commit comments

Comments
 (0)