breakpoint1

This commit is contained in:
CortexCore
2023-07-20 01:40:20 +08:00
parent a1ac6bada2
commit 907e037d0d
9 changed files with 284 additions and 245 deletions

View File

@@ -29,6 +29,7 @@ public partial class IDIS_THService : Node
[ExportCategory("UI 绑定")]
[Export] private Button submitButton;
[Export] private CheckButton autoUpdateButton;
[Export] private OptionButton updateModeButton;
[Export] private LineEdit handleEdit;

View File

@@ -26,14 +26,15 @@ public partial class 温湿度Reader : Node
[Export]public double temperature = 26.0;
[ExportCategory("UI 绑定")]
[Export] private UXContainer temperatureContaier;
[Export] private Button connectToModbusButton;
[Export] private UXContainer temperatureContainer;
[Export] private UXContainer humidityContainer;
[Export] private LineEdit ipEdit;
[Export] private LineEdit portEdit;
[Export] private RichTextLabel hintsLabel;
private ModbusMaster _modbus;
private System.Timers.Timer timer;
private Timer timer;
private CancellationTokenSource _CancellationTokenSource;
public override void _Ready()
@@ -48,30 +49,21 @@ public partial class 温湿度Reader : Node
hintsLabel.Text = e.Message;
}
if (ipEdit is not null)
ipEdit.TextChanged+=s=>ip=s;
portEdit.TextChanged+=s=>
{
ipEdit.TextChanged += s => ip = s;
ipEdit.TextSubmitted +=s=> UpdatePortAndIP();
}
if(portEdit is not null)
{
portEdit.TextSubmitted += OnPortChanged;
void OnPortChanged(string s)
try
{
UpdatePortAndIP();
if (int.TryParse(s,out var newPort))
{
}
else
{
portEdit.Text=string.Empty;
portEdit.PlaceholderText = "请输入正确的端口号";
}
port = int.Parse(s);
}
}
UpdatePortAndIP();
catch (Exception e)
{
hintsLabel.SetTextAsync(e.Message);
}
};
connectToModbusButton.Pressed += Connect;
Connect();
timer = new Timer();
timer.Interval = interval;
@@ -86,9 +78,9 @@ public partial class 温湿度Reader : Node
timer.Stop();
}
/// <summary>
/// 内部方法,用于更新IP和端口
/// 连接到Modbus
/// </summary>
private void UpdatePortAndIP()
private void Connect()
{
_modbus?.Dispose();
try
@@ -100,7 +92,6 @@ public partial class 温湿度Reader : Node
BIT4Log.Log<湿Reader>(e.Message);
hintsLabel.SetTextAsync(e.Message);
}
}
/// <summary>
/// 内部方法,定时器回调用于读取Modbus
@@ -140,7 +131,7 @@ public partial class 温湿度Reader : Node
hintsLabel.SetTextAsync("已获取到温湿度数据:"+DateTime.Now);
temperatureContaier.label.SetTextAsync(temperature.ToString(CultureInfo.InvariantCulture)); ;
temperatureContainer.label.SetTextAsync(temperature.ToString(CultureInfo.InvariantCulture)); ;
humidityContainer.label.SetTextAsync(humidity.ToString(CultureInfo.InvariantCulture));
timer.Start();