Cleanup OpenAsync function.

- Separate into Connect and EstablishConnection step.
- Remove redundant null checks for returned data.
-  Only assing PLC stream object once we fully established a connection, and Close otherwise.
- Replace sync implementation with Async call.
This commit is contained in:
Serge Camille
2020-09-12 11:14:41 +02:00
parent af39659944
commit 106e9912ab
5 changed files with 57 additions and 78 deletions

View File

@@ -11,6 +11,11 @@ namespace S7.Net
/// </summary>
internal class COTP
{
public enum PduType : byte
{
Data = 0xf0,
ConnectionConfirmed = 0xd0
}
/// <summary>
/// Describes a COTP TPDU (Transport protocol data unit)
/// </summary>
@@ -18,7 +23,7 @@ namespace S7.Net
{
public TPKT TPkt { get; }
public byte HeaderLength;
public byte PDUType;
public PduType PDUType;
public int TPDUNumber;
public byte[] Data;
public bool LastDataUnit;
@@ -30,8 +35,8 @@ namespace S7.Net
HeaderLength = tPKT.Data[0]; // Header length excluding this length byte
if (HeaderLength >= 2)
{
PDUType = tPKT.Data[1];
if (PDUType == 0xf0) //DT Data
PDUType = (PduType)tPKT.Data[1];
if (PDUType == PduType.Data) //DT Data
{
var flags = tPKT.Data[2];
TPDUNumber = flags & 0x7F;