Added methods to pause/resume the auto polling

This commit is contained in:
Felix Weiß
2022-09-23 16:38:14 +02:00
parent 88a453355c
commit c7a6559f97
3 changed files with 162 additions and 84 deletions

View File

@@ -32,7 +32,7 @@ class Program {
Task.Factory.StartNew(async () => {
//attaching the logger
Logger.LogLevel = LogLevel.Verbose;
Logger.LogLevel = LogLevel.Critical;
Logger.OnNewLogMessage((date, msg) => {
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
});
@@ -44,6 +44,13 @@ class Program {
//attaching the register collection and an automatic poller
interf.WithRegisterCollection(registers).WithPoller();
_ = Task.Factory.StartNew(async () => {
while (true) {
Console.Title = $"Polling Paused: {interf.PollingPaused}, Speed UP: {interf.BytesPerSecondUpstream} B/s, Speed DOWN: {interf.BytesPerSecondDownstream} B/s";
await Task.Delay(1000);
}
});
await interf.ConnectAsync(
(plcinf) => {
@@ -79,14 +86,28 @@ class Program {
//set the current second to the PLCs TIME register
interf.SetRegister(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Second));
//test pausing poller
bool pollerPaused = false;
while(true) {
Console.WriteLine($"Speed UP: {interf.BytesPerSecondUpstream} B/s");
Console.WriteLine($"Speed DOWN: {interf.BytesPerSecondDownstream} B/s");
await Task.Delay(5000);
pollerPaused = !pollerPaused;
if(pollerPaused) {
Console.WriteLine("Pausing poller");
await interf.PausePollingAsync();
Console.WriteLine("Paused poller");
} else {
interf.ResumePolling();
Console.WriteLine("Resumed poller");
}
await Task.Delay(1000);
}
});
}