This commit is contained in:
@@ -244,6 +244,7 @@ namespace ShanghaiEnvironmentalTechnology
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnResetTimerElapsed(object sender, ElapsedEventArgs e)
|
private void OnResetTimerElapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
string _lang = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
string _lang = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||||
|
|||||||
@@ -229,6 +229,51 @@ namespace ShanghaiEnvironmentalTechnology
|
|||||||
updateAction: (value) => UpdateTextBox(PressRateTxt, value.ToString())
|
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
|
#endregion
|
||||||
@@ -267,13 +312,20 @@ namespace ShanghaiEnvironmentalTechnology
|
|||||||
|
|
||||||
private void UpdateTextBox(TextBox textBox, string value)
|
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()
|
private void InitializePlot()
|
||||||
@@ -332,8 +384,8 @@ namespace ShanghaiEnvironmentalTechnology
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 读取寄存器值(保持不变)
|
// 读取寄存器值(保持不变)
|
||||||
ushort[] exhalationData = await Task.Run(() => _modbusMaster?.ReadHoldingRegisters(0x01, _OutBreathAddress, 2));
|
ushort[] exhalationData = await _modbusMaster?.ReadHoldingRegistersAsync(0x01, _OutBreathAddress, 2);
|
||||||
ushort[] inhalationData = await Task.Run(() => _modbusMaster?.ReadHoldingRegisters(0x01, _InBreathAddress, 2));
|
ushort[] inhalationData = await _modbusMaster?.ReadHoldingRegistersAsync(0x01, _InBreathAddress, 2);
|
||||||
|
|
||||||
// 解析呼气流量(保持不变)
|
// 解析呼气流量(保持不变)
|
||||||
ushort a = exhalationData[0];
|
ushort a = exhalationData[0];
|
||||||
@@ -615,7 +667,7 @@ namespace ShanghaiEnvironmentalTechnology
|
|||||||
{
|
{
|
||||||
|
|
||||||
Function ma = new Function(_modbusMaster);
|
Function ma = new Function(_modbusMaster);
|
||||||
ma.WriteToPLCForNew("", registerAddress, Function.DataType.浮点型);
|
ma.WriteToPLCForNew(handmovementTxt.Text, registerAddress, Function.DataType.浮点型);
|
||||||
|
|
||||||
//// 等待并刷新
|
//// 等待并刷新
|
||||||
//await Task.Delay(300);
|
//await Task.Delay(300);
|
||||||
|
|||||||
BIN
睡眠呼吸面罩丝杆8888模拟量压力(1).gxw
Normal file
BIN
睡眠呼吸面罩丝杆8888模拟量压力(1).gxw
Normal file
Binary file not shown.
Reference in New Issue
Block a user