Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoking ReadBytesAsync method sometimes never return #547

Open
yushu3166 opened this issue Oct 31, 2024 · 0 comments
Open

invoking ReadBytesAsync method sometimes never return #547

yushu3166 opened this issue Oct 31, 2024 · 0 comments

Comments

@yushu3166
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant