diff --git a/Window5.xaml.cs b/Window5.xaml.cs index 2c3686c..5e5263d 100644 --- a/Window5.xaml.cs +++ b/Window5.xaml.cs @@ -244,6 +244,7 @@ namespace ShanghaiEnvironmentalTechnology } } + private void OnResetTimerElapsed(object sender, ElapsedEventArgs e) { string _lang = ConfigurationManager.AppSettings["Language"] ?? "zh-CN"; diff --git a/Window6.xaml.cs b/Window6.xaml.cs index e58f97c..4209c84 100644 --- a/Window6.xaml.cs +++ b/Window6.xaml.cs @@ -229,6 +229,51 @@ namespace ShanghaiEnvironmentalTechnology updateAction: (value) => UpdateTextBox(PressRateTxt, value.ToString()) ); } + + + OnStartTimerElapsed(sender, e); + + + + + + } + + + private void OnStartTimerElapsed(object sender, ElapsedEventArgs e) + { + string _lang = ConfigurationManager.AppSettings["Language"] ?? "zh-CN"; + try + { + bool[] result = _modbusMaster?.ReadCoils(0x01, 98, 1); + bool isRunning = result != null && result.Length > 0 && result[0]; + + Dispatcher.Invoke(() => + { + if (isRunning) + { + btn1.IsEnabled = false; + btn2.IsEnabled = false; + btn3.IsEnabled = false; + btn4.IsEnabled = false; + btn5.IsEnabled = false; + + + } + else + { + btn1.IsEnabled = true; + btn2.IsEnabled = true; + btn3.IsEnabled = true; + btn4.IsEnabled = true; + btn5.IsEnabled = true; + } + }); + } + catch (Exception ex) + { + Console.WriteLine(_lang == "en-US" ? $"Failed to read coil: {ex.Message}" : $"读取线圈或更新UI失败:{ex.Message}"); + } } #endregion @@ -267,13 +312,20 @@ namespace ShanghaiEnvironmentalTechnology private void UpdateTextBox(TextBox textBox, string value) { - Dispatcher.Invoke(() => + try { - if (textBox.IsVisible) // 控件可见时才更新 + Dispatcher.Invoke(() => { - textBox.Text = value; - } - }); + if (textBox.IsVisible) // 控件可见时才更新 + { + textBox.Text = value; + } + }); + } + catch (Exception ex) + { + Console.WriteLine($"更新TextBox失败: {ex.Message}"); + } } private void InitializePlot() @@ -332,8 +384,8 @@ namespace ShanghaiEnvironmentalTechnology try { // 读取寄存器值(保持不变) - ushort[] exhalationData = await Task.Run(() => _modbusMaster?.ReadHoldingRegisters(0x01, _OutBreathAddress, 2)); - ushort[] inhalationData = await Task.Run(() => _modbusMaster?.ReadHoldingRegisters(0x01, _InBreathAddress, 2)); + ushort[] exhalationData = await _modbusMaster?.ReadHoldingRegistersAsync(0x01, _OutBreathAddress, 2); + ushort[] inhalationData = await _modbusMaster?.ReadHoldingRegistersAsync(0x01, _InBreathAddress, 2); // 解析呼气流量(保持不变) ushort a = exhalationData[0]; @@ -615,7 +667,7 @@ namespace ShanghaiEnvironmentalTechnology { Function ma = new Function(_modbusMaster); - ma.WriteToPLCForNew("", registerAddress, Function.DataType.浮点型); + ma.WriteToPLCForNew(handmovementTxt.Text, registerAddress, Function.DataType.浮点型); //// 等待并刷新 //await Task.Delay(300); diff --git a/睡眠呼吸面罩丝杆8888模拟量压力(1).gxw b/睡眠呼吸面罩丝杆8888模拟量压力(1).gxw new file mode 100644 index 0000000..f479812 Binary files /dev/null and b/睡眠呼吸面罩丝杆8888模拟量压力(1).gxw differ