From a047c5bba4c2b561fdf9839ce893fcfbce95c62e Mon Sep 17 00:00:00 2001 From: Serge Camille Date: Tue, 18 Aug 2020 19:51:55 +0200 Subject: [PATCH] Fix chunk size for WriteBytesAsync. The previous problem of not being able to use a larger chunk size than 200 was that the complete header building code for the async implementation was incorrect. Specifically, it wrote the package size only as a byte instead of a int16, thus restricting the package size to something < 256. With the sharing of the Header building code in the previous commits, this problem was resolved by accident, and thus the chunk size can be increased to the maximum value allowed by the PDUSize. --- S7.Net/PlcAsynchronous.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs index 334cbbe..26cf05c 100644 --- a/S7.Net/PlcAsynchronous.cs +++ b/S7.Net/PlcAsynchronous.cs @@ -265,10 +265,7 @@ namespace S7.Net int count = value.Length; while (count > 0) { - //TODO: Figure out how to use MaxPDUSize here - //Snap7 seems to choke on PDU sizes above 256 even if snap7 - //replies with bigger PDU size in connection setup. - var maxToWrite = (int)Math.Min(count, 200); + var maxToWrite = (int)Math.Min(count, MaxPDUSize - 35); await WriteBytesWithASingleRequestAsync(dataType, db, startByteAdr + localIndex, value, localIndex, maxToWrite); count -= maxToWrite; localIndex += maxToWrite;