页面参数设置
This commit is contained in:
@@ -127,7 +127,9 @@ namespace TabletTester2025.ViewModels
|
|||||||
StartHardnessCommand = new AsyncRelayCommand(RunHardnessAsync);
|
StartHardnessCommand = new AsyncRelayCommand(RunHardnessAsync);
|
||||||
StartFriabilityCommand = new AsyncRelayCommand(RunFriabilityAsync);
|
StartFriabilityCommand = new AsyncRelayCommand(RunFriabilityAsync);
|
||||||
StartDisintegrationCommand = new AsyncRelayCommand(RunDisintegrationAsync);
|
StartDisintegrationCommand = new AsyncRelayCommand(RunDisintegrationAsync);
|
||||||
|
|
||||||
StartDissolutionCommand = new AsyncRelayCommand(RunDissolutionAsync);
|
StartDissolutionCommand = new AsyncRelayCommand(RunDissolutionAsync);
|
||||||
|
|
||||||
ExportHistoryCommand = new AsyncRelayCommand(ExportHistoryAsync);
|
ExportHistoryCommand = new AsyncRelayCommand(ExportHistoryAsync);
|
||||||
|
|
||||||
// 溶出曲线
|
// 溶出曲线
|
||||||
@@ -167,13 +169,16 @@ namespace TabletTester2025.ViewModels
|
|||||||
PrintHardnessCommand = new AsyncRelayCommand(async () => await PrintReport("硬度"));
|
PrintHardnessCommand = new AsyncRelayCommand(async () => await PrintReport("硬度"));
|
||||||
|
|
||||||
// 脆碎度命令
|
// 脆碎度命令
|
||||||
StopFriabilityCommand = new AsyncRelayCommand(() => { Phase = TestPhase.Idle; return Task.CompletedTask; });
|
StopFriabilityCommand = new AsyncRelayCommand(() => {
|
||||||
|
//测试停止
|
||||||
|
Phase = TestPhase.Idle; return Task.CompletedTask;
|
||||||
|
});
|
||||||
ResetFriabilityCommand = new AsyncRelayCommand(() =>
|
ResetFriabilityCommand = new AsyncRelayCommand(() =>
|
||||||
{
|
{
|
||||||
FriabilityRemainingRounds = 100;
|
FriabilityRemainingRounds = 100; // 剩余圈数重置为默认值(通常是100圈)
|
||||||
LossPercent = 0;
|
LossPercent = 0; // 失重率清零
|
||||||
WeightBefore = 0;
|
WeightBefore = 0; // 脆碎前重量清零
|
||||||
WeightAfter = 0;
|
WeightAfter = 0;// 脆碎后重量清零
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
});
|
});
|
||||||
PrintFriabilityCommand = new AsyncRelayCommand(async () => await PrintReport("脆碎度"));
|
PrintFriabilityCommand = new AsyncRelayCommand(async () => await PrintReport("脆碎度"));
|
||||||
@@ -251,30 +256,34 @@ namespace TabletTester2025.ViewModels
|
|||||||
double max = App.CurrentPharmaParams.HardnessMax_N;
|
double max = App.CurrentPharmaParams.HardnessMax_N;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
|
||||||
|
{ // 1. 给PLC发指令:启动单次硬度测试
|
||||||
await _plc.WriteCoilAsync((ushort)(StationId == 1 ? _plcConfig.HardnessStartCoil :
|
await _plc.WriteCoilAsync((ushort)(StationId == 1 ? _plcConfig.HardnessStartCoil :
|
||||||
StationId == 2 ? _plcConfig.HardnessStartCoil2
|
StationId == 2 ? _plcConfig.HardnessStartCoil2
|
||||||
: StationId == 3 ? _plcConfig.HardnessStartCoil3 : 0), true);
|
: StationId == 3 ? _plcConfig.HardnessStartCoil3 : 0), true);
|
||||||
bool completed = false;
|
bool completed = false;
|
||||||
while (!completed && Phase == TestPhase.Running)
|
while (!completed && Phase == TestPhase.Running)
|
||||||
{
|
{
|
||||||
await Task.Delay(200);
|
await Task.Delay(200);// 每200ms轮询一次状态
|
||||||
|
|
||||||
completed = await _plc.ReadCoilAsync(_plcConfig.HardnessCompleteCoil);
|
completed = await _plc.ReadCoilAsync(_plcConfig.HardnessCompleteCoil);
|
||||||
}
|
}
|
||||||
double val = await _plc.ReadFloatAsync(_plcConfig.HardnessValue);
|
double val = await _plc.ReadFloatAsync(_plcConfig.HardnessValue);
|
||||||
_hardnessResults.Add(val);
|
_hardnessResults.Add(val); // 把结果存到列表里
|
||||||
HardnessValue = val;
|
|
||||||
await Task.Delay(1000);
|
HardnessValue = val; // 更新界面上的实时测试力值
|
||||||
|
|
||||||
|
await Task.Delay(1000); // 间隔1秒,再进行下一次测试
|
||||||
}
|
}
|
||||||
|
|
||||||
HardnessAvg = _hardnessResults.Average();
|
HardnessAvg = _hardnessResults.Average();
|
||||||
HardnessMax= _hardnessResults.Max();
|
HardnessMax= _hardnessResults.Max();
|
||||||
HardnessMin = _hardnessResults.Min();
|
HardnessMin = _hardnessResults.Min();
|
||||||
|
|
||||||
|
HardnessCurrentCount = count;
|
||||||
HardnessRSD = (StandardDeviation(_hardnessResults) / HardnessAvg) * 100;
|
HardnessRSD = (StandardDeviation(_hardnessResults) / HardnessAvg) * 100;
|
||||||
HardnessPass = HardnessAvg >= min && HardnessAvg <= max;
|
HardnessPass = HardnessAvg >= min && HardnessAvg <= max;
|
||||||
Phase = TestPhase.Completed;
|
Phase = TestPhase.Completed;//恢复启动按钮
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -293,38 +302,75 @@ namespace TabletTester2025.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 脆碎度测试主逻辑(适配3工位、实时状态显示)
|
||||||
|
|
||||||
private async Task RunFriabilityAsync()
|
private async Task RunFriabilityAsync()
|
||||||
{
|
{
|
||||||
if (Phase != TestPhase.Idle) return;
|
// 1. 防并发:如果设备不是空闲状态,直接退出
|
||||||
|
if (Phase != TestPhase.Idle)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 2. 标记当前正在运行的是脆碎度测试
|
||||||
CurrentTest = TestType.Friability;
|
CurrentTest = TestType.Friability;
|
||||||
Phase = TestPhase.Running;
|
Phase = TestPhase.Running;
|
||||||
FriabilityPass = false; // 添加这一行
|
FriabilityPass = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 通过天平读取前重
|
ushort startCoil = StationId switch
|
||||||
|
{
|
||||||
|
1 => _plcConfig.FriabilityStartCoil, // 工位1启动线圈
|
||||||
|
2 => _plcConfig.FriabilityStartCoil2, // 工位2启动线圈
|
||||||
|
3 => _plcConfig.FriabilityStartCoil3, // 工位3启动线圈
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
|
||||||
|
if (startCoil == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("当前工位未配置脆碎度启动线圈地址");
|
||||||
|
}
|
||||||
WeightBefore = await _balance.ReadWeightAsync();
|
WeightBefore = await _balance.ReadWeightAsync();
|
||||||
await _plc.WriteCoilAsync(_plcConfig.FriabilityStartCoil, true);
|
await _plc.WriteCoilAsync(startCoil, true);
|
||||||
|
int totalRounds = 100; // 药典标准脆碎度总圈数:100圈
|
||||||
|
double rpm = FriabilityTargetRpm; // 界面设置的目标转速(r/min)
|
||||||
|
int durationMs = (int)((totalRounds / rpm) * 60 * 1000); // 总运行时间(毫秒)
|
||||||
|
|
||||||
// 根据设定的转速和总圈数计算运行时间
|
for (int i = 0; i < durationMs; i += 100)
|
||||||
int totalRounds = 100;
|
{
|
||||||
double rpm = FriabilityTargetRpm;
|
// 如果用户点了停止,状态会被设为Idle,直接跳出循环
|
||||||
int durationMs = (int)((totalRounds / rpm) * 60 * 1000);
|
if (Phase != TestPhase.Running)
|
||||||
await Task.Delay(durationMs);
|
break;
|
||||||
|
|
||||||
|
// 计算当前剩余圈数
|
||||||
|
double elapsedMs = i;
|
||||||
|
double elapsedRounds = rpm / 60 / 1000 * elapsedMs;
|
||||||
|
int remainingRounds = (int)Math.Ceiling(totalRounds - elapsedRounds);
|
||||||
|
|
||||||
|
// 更新界面绑定的剩余圈数
|
||||||
|
FriabilityRemainingRounds = remainingRounds;
|
||||||
|
|
||||||
|
// 等待100ms,再更新下一次
|
||||||
|
await Task.Delay(100);
|
||||||
|
}
|
||||||
WeightAfter = await _balance.ReadWeightAsync();
|
WeightAfter = await _balance.ReadWeightAsync();
|
||||||
LossPercent = (WeightBefore - WeightAfter) / WeightBefore * 100;
|
|
||||||
FriabilityPass = LossPercent <= App.CurrentPharmaParams.FriabilityMaxLossPercent;
|
FriabilityCurrentRpm = FriabilityTargetRpm;
|
||||||
|
LossPercent = (WeightBefore - WeightAfter) / WeightBefore * 100;//失重率
|
||||||
|
FriabilityPass = LossPercent <= App.CurrentPharmaParams.FriabilityMaxLossPercent; //标准值
|
||||||
|
// 标记测试为已完成
|
||||||
Phase = TestPhase.Completed;
|
Phase = TestPhase.Completed;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await App.Current.Dispatcher.InvokeAsync(() => MessageBox.Show($"脆碎度测试出错: {ex.Message}"));
|
|
||||||
|
await App.Current.Dispatcher.InvokeAsync(() =>
|
||||||
|
MessageBox.Show($"脆碎度测试出错: {ex.Message}"));
|
||||||
Phase = TestPhase.Error;
|
Phase = TestPhase.Error;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Phase = TestPhase.Idle;
|
Phase = TestPhase.Idle;
|
||||||
|
FriabilityRemainingRounds = 100;
|
||||||
await SaveBatchResult();
|
await SaveBatchResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,7 @@
|
|||||||
<Button Command="{Binding HardnessResetCommand}" Content="复位" Style="{StaticResource ActionButton}" Background="#9E9E9E"/>
|
<Button Command="{Binding HardnessResetCommand}" Content="复位" Style="{StaticResource ActionButton}" Background="#9E9E9E"/>
|
||||||
<Button Command="{Binding PrintHardnessCommand}" Content="打印" Style="{StaticResource ActionButton}" Background="#607D8B"/>
|
<Button Command="{Binding PrintHardnessCommand}" Content="打印" Style="{StaticResource ActionButton}" Background="#607D8B"/>
|
||||||
<Button Command="{Binding StartHardnessCommand}" Content="启动测试" Style="{StaticResource ActionButton}" Background="#4CAF50" Margin="5 0 0 0"/>
|
<Button Command="{Binding StartHardnessCommand}" Content="启动测试" Style="{StaticResource ActionButton}" Background="#4CAF50" Margin="5 0 0 0"/>
|
||||||
|
<Button Command="{Binding StopFriabilityCommand}" Content="测试停止" Style="{StaticResource ActionButton}" Background="#F44336"/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|||||||
@@ -11,8 +11,11 @@
|
|||||||
"HardnessStartCoil": 70, //硬度工位1启动测试M70
|
"HardnessStartCoil": 70, //硬度工位1启动测试M70
|
||||||
"HardnessStartCoil2": 70, //硬度工位1启动测试M70
|
"HardnessStartCoil2": 70, //硬度工位1启动测试M70
|
||||||
"HardnessStartCoil3": 70, //硬度工位1启动测试M70
|
"HardnessStartCoil3": 70, //硬度工位1启动测试M70
|
||||||
|
"FriabilityStartCoil": 80, //脆碎工位1启动测试M70
|
||||||
|
"FriabilityStartCoil2": 80, //脆碎工位1启动测试M70
|
||||||
|
"FriabilityStartCoil3": 80, //脆碎工位1启动测试M70
|
||||||
"HardnessCompleteCoil": 11,
|
"HardnessCompleteCoil": 11,
|
||||||
"FriabilityStartCoil": 20,
|
//"FriabilityStartCoil": 20,
|
||||||
"WeightBefore": 200,
|
"WeightBefore": 200,
|
||||||
"WeightAfter": 202,
|
"WeightAfter": 202,
|
||||||
"DisintegrationTemp": 300,
|
"DisintegrationTemp": 300,
|
||||||
|
|||||||
Reference in New Issue
Block a user