S7NetPlus / s7netplus

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

invoking ReadBytesAsync method sometimes never return #547

Open yushu3166 opened 3 weeks ago

yushu3166 commented 3 weeks ago

code: if (!await ConnectAsync()) { return null; } Stopwatch stopwatch = Stopwatch.StartNew(); stopwatch.Start(); try { var cts = new CancellationTokenSource(1000 * 3); byte[] bytes = await _Plc.ReadBytesAsync(DataType.DataBlock, DB, start, length, cts.Token); stopwatch.Stop(); if (bytes == null || bytes.Length == 0) { _LogUtil.Error($"S7Plc error:{stopwatch.Elapsed.TotalMilliseconds},IP:{_Plc.IP},DB:{DB},start:{start},length:{length},MaxPDUSize:{_Plc.MaxPDUSize}"); } return bytes;

} catch (Exception ex) { stopwatch.Stop(); _LogUtil.Error($"S7Plc Exception:{stopwatch.Elapsed.TotalMilliseconds},IP:{_Plc.IP},DB:{DB},start:{start},length:{length},MaxPDUSize:{_Plc.MaxPDUSize}, ex:{ex.Message}"); } return null;

=============

byte[] bytes = await _Plc.ReadBytesAsync(DataType.DataBlock, DB, start, length, cts.Token); // sometimes here never return or throw exception,why?