mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 11:11:23 +00:00
Added methods to pause/resume the auto polling
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user