Open yushu3166 opened 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?
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?