更新2026
This commit is contained in:
@@ -21,7 +21,6 @@ namespace TabletTester2025.ViewModels
|
||||
private readonly DatabaseService _db;
|
||||
private readonly ExcelExportService _excel;
|
||||
private readonly AlarmService _alarm;
|
||||
private readonly BalanceService _balance; // ✅ 新增天平服务
|
||||
private DispatcherTimer _disintegrationTimer;
|
||||
private bool _isLoadingDissolution1Time;
|
||||
private bool _isLoadingDissolution2Time;
|
||||
@@ -149,7 +148,6 @@ namespace TabletTester2025.ViewModels
|
||||
_db = db;
|
||||
_excel = excel;
|
||||
_alarm = alarm;
|
||||
_balance = new BalanceService(); // 实例化天平服务(模拟)
|
||||
|
||||
StartHardnessCommand = new AsyncRelayCommand(RunHardnessAsync);
|
||||
StartFriabilityCommand = new AsyncRelayCommand(RunFriabilityAsync);
|
||||
@@ -632,6 +630,7 @@ namespace TabletTester2025.ViewModels
|
||||
CurrentTest = TestType.Friability;
|
||||
Phase = TestPhase.Running;
|
||||
FriabilityPass = false;
|
||||
bool resultReady = false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -641,7 +640,10 @@ namespace TabletTester2025.ViewModels
|
||||
{
|
||||
throw new InvalidOperationException("未配置脆碎度启动线圈地址");
|
||||
}
|
||||
WeightBefore = await _balance.ReadWeightAsync();
|
||||
WeightBefore = await ReadFriabilityWeightAsync(_plcConfig.WeightBefore, "脆碎前重量");
|
||||
if (WeightBefore <= 0)
|
||||
throw new InvalidOperationException("脆碎前重量必须大于0");
|
||||
|
||||
await _plc.WriteCoilAsync(startCoil, true);
|
||||
int totalRounds = 100; // 药典标准脆碎度总圈数:100圈
|
||||
double rpm = FriabilityTargetRpm; // 界面设置的目标转速(r/min)
|
||||
@@ -664,11 +666,15 @@ namespace TabletTester2025.ViewModels
|
||||
// 等待100ms,再更新下一次
|
||||
await Task.Delay(100);
|
||||
}
|
||||
WeightAfter = await _balance.ReadWeightAsync();
|
||||
if (Phase != TestPhase.Running)
|
||||
throw new InvalidOperationException("脆碎度测试已停止,未保存结果");
|
||||
|
||||
WeightAfter = await ReadFriabilityWeightAsync(_plcConfig.WeightAfter, "脆碎后重量");
|
||||
|
||||
FriabilityCurrentRpm = FriabilityTargetRpm;
|
||||
LossPercent = (WeightBefore - WeightAfter) / WeightBefore * 100;//失重率
|
||||
FriabilityPass = LossPercent <= App.CurrentPharmaParams.FriabilityMaxLossPercent; //标准值
|
||||
resultReady = true;
|
||||
// 标记测试为已完成
|
||||
Phase = TestPhase.Completed;
|
||||
}
|
||||
@@ -683,10 +689,23 @@ namespace TabletTester2025.ViewModels
|
||||
{
|
||||
Phase = TestPhase.Idle;
|
||||
FriabilityRemainingRounds = 100;
|
||||
await SaveBatchResult();
|
||||
if (resultReady)
|
||||
await SaveBatchResult();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<double> ReadFriabilityWeightAsync(ushort registerAddress, string label)
|
||||
{
|
||||
if (registerAddress == 0)
|
||||
throw new InvalidOperationException($"{label}寄存器未配置");
|
||||
|
||||
double value = await _plc.ReadFloatAsync(registerAddress);
|
||||
if (!double.IsFinite(value) || value < 0)
|
||||
throw new InvalidOperationException($"{label}数据异常");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private async Task RunDisintegrationAsync()
|
||||
{
|
||||
if (Phase != TestPhase.Idle) return;
|
||||
|
||||
Reference in New Issue
Block a user