S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.34k stars 589 forks source link

ReadBytesWithSingleRequest cannot read >491 Bytes on S7-1500 #145

Closed rapha-dev closed 6 years ago

rapha-dev commented 6 years ago

Possible bug in COTP CR when connecting to a S7-1500, TPDU is too small (actually 512 bytes). Any Read resulting in actualPDU + COTPHeader > TPDU (which is 957 + 3 = 960 > 512) will fail (Socket disconnects).

Maximum Bytes of 491 would work: 509 + 3 = 512 > 512

For reference: PLC4X

Increasing the TPDU to maximum of 1024 bytes (still need to check on S7-300, 400 and 1200) will allow to read an unspecified maximum of bytes as PDUs will be split into multiple PDUs with maximum size.

I will create a PR for this and need some testing.

mycroes commented 6 years ago

This probably also relates to open issue for PR #133.

Increasing the TPDU to maximum of 1024 bytes

We're negotiating 1920 byte PDU, so maybe we should increase to 2048. Also, the ISO over TCP spec states the default is 65355 bytes IIRC, which means we could possibly zero out the PDU size entirely. We should really have access to all supported PLC's to verify these changes though.

rapha-dev commented 6 years ago

You are right, I have made some tests using different sizes up to 2^15, using 2^11 should be sufficient to support max PDU on all available PLCs.

I have noticed all tests negotiated a TPDU of 1024 bytes when requesting a higher value (e.g. 2048).

rapha-dev commented 6 years ago

Merged into develop.