提交更新

This commit is contained in:
CortexCore
2023-07-12 15:27:27 +08:00
parent 4af7cec47b
commit 498b0617f8
13 changed files with 294 additions and 154 deletions

View File

@@ -82,6 +82,7 @@ public partial class 温湿度Reader : Node
public override void _ExitTree()
{
_CancellationTokenSource.Cancel();
timer.Stop();
}
/// <summary>
@@ -107,14 +108,16 @@ public partial class 温湿度Reader : Node
/// <param name="e"></param>
private async void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
_CancellationTokenSource.Cancel();
await UniTask.SwitchToTaskPool();
try
{
_CancellationTokenSource.Token.ThrowIfCancellationRequested();
hintsLabel.SetTextAsync( "正在读取温湿度数据..."+DateTime.Now);
var vs = _modbus.ReadInputRegisters(1, 0, 2);
_CancellationTokenSource.Token.ThrowIfCancellationRequested();
hintsLabel.SetTextAsync( "已采集到数据,正在解析..."+DateTime.Now);
if (vs is not { Length: 2 })
@@ -131,17 +134,19 @@ public partial class 温湿度Reader : Node
temperatureContaier.label.SetTextAsync(temperature.ToString(CultureInfo.InvariantCulture)); ;
humidityContainer.label.SetTextAsync(humidity.ToString(CultureInfo.InvariantCulture));
timer.Start();
}
catch (OperationCanceledException)
{
hintsLabel.SetTextAsync("连接超时:"+DateTime.Now);
BIT4Log.Log<湿Reader>($"Modbus读取任务已取消");
}
catch (Exception ex)
{
hintsLabel.SetTextAsync(ex.Message);
//GD.Print("ex:" + ex);
timer.Start();
}
timer.Start();
}
}