This commit is contained in:
@@ -165,22 +165,25 @@ namespace MembranePoreTester.ViewModels
|
||||
}
|
||||
private async Task ReadPressureModeAsync()
|
||||
{
|
||||
try
|
||||
await SafeExecuteAsync($"ReadPressureModeAsync{StationId}", async () =>
|
||||
{
|
||||
ushort[] values = await _plcService.ReadHoldingRegistersAsync(_plcConfig.PressureModeRegister, 1);
|
||||
ushort val = values[0];
|
||||
string newValue = val == 0 ? "高压" : "低压";
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
try
|
||||
{
|
||||
// 更新选中项
|
||||
HighLowPressure = newValue;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"读取压力模式失败: {ex.Message}");
|
||||
}
|
||||
ushort[] values = await _plcService.ReadHoldingRegistersAsync(_plcConfig.PressureModeRegister, 1);
|
||||
ushort val = values[0];
|
||||
string newValue = val == 0 ? "高压" : "低压";
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 更新选中项
|
||||
HighLowPressure = newValue;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"读取压力模式失败: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task TogglePressAsync()
|
||||
@@ -204,33 +207,38 @@ namespace MembranePoreTester.ViewModels
|
||||
MessageBox.Show($"读取加压状态失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 在 StationItem 类中添加字段
|
||||
private bool _lastEnableReadFailed = false;
|
||||
private DateTime _lastEnableErrorTime = DateTime.MinValue;
|
||||
private async Task ReadEnableStatusAsync()
|
||||
{
|
||||
try
|
||||
await SafeExecuteAsync($"ReadEnableStatus_Station{StationId}", async () =>
|
||||
{
|
||||
bool status = await _plcService.ReadCoilAsync(_plcConfig.EnableCoil); // 读取 M21
|
||||
EnableStatus = status;
|
||||
|
||||
|
||||
bool pressStatus = await _plcService.ReadCoilAsync(_plcConfig.PressCoil);//这里也要更新加压的按钮状态
|
||||
|
||||
_isPressing = pressStatus;
|
||||
|
||||
// 在UI线程更新按钮文字
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
try
|
||||
{
|
||||
PressButtonText = pressStatus ? "停止加压" : "加压";
|
||||
});
|
||||
bool status = await _plcService.ReadCoilAsync(_plcConfig.EnableCoil); // 读取 M21
|
||||
EnableStatus = status;
|
||||
|
||||
|
||||
bool pressStatus = await _plcService.ReadCoilAsync(_plcConfig.PressCoil);//这里也要更新加压的按钮状态
|
||||
|
||||
_isPressing = pressStatus;
|
||||
|
||||
// 在UI线程更新按钮文字
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
PressButtonText = pressStatus ? "停止加压" : "加压";
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 读取出错时保持原状态或显示错误
|
||||
System.Diagnostics.Debug.WriteLine($"读取使能状态失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 读取出错时保持原状态或显示错误
|
||||
System.Diagnostics.Debug.WriteLine($"读取使能状态失败: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task WriteCoilAsync(ushort coil, bool value)
|
||||
@@ -283,7 +291,7 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
for (int i = 1; i <= 1; i++)
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
var station = new StationItem
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user