更新2025
This commit is contained in:
@@ -33,7 +33,7 @@ namespace TabletTester2025.ViewModels
|
||||
private bool _isLoadingDissolution2SampleInterval;
|
||||
private bool _isLoadingDisintegrationTime;
|
||||
private bool _isLoadingDisintegrationSpeed;
|
||||
private bool _isLoadingFriabilityTime;
|
||||
private bool _isLoadingFriabilityRounds;
|
||||
private bool _isUpdatingFriabilityWeightFromPlc;
|
||||
|
||||
private readonly List<double> _dissolution1Times = new();
|
||||
@@ -325,7 +325,7 @@ namespace TabletTester2025.ViewModels
|
||||
_isLoadingDissolution2Time = true;
|
||||
_isLoadingDissolution1SampleInterval = true;
|
||||
_isLoadingDissolution2SampleInterval = true;
|
||||
_isLoadingFriabilityTime = true;
|
||||
_isLoadingFriabilityRounds = true;
|
||||
try
|
||||
{
|
||||
HardnessInternalMin = p.HardnessMin_N;
|
||||
@@ -333,6 +333,7 @@ namespace TabletTester2025.ViewModels
|
||||
HardnessTestCount = Math.Max(1, p.HardnessTestCount);
|
||||
FriabilityTargetRpm = p.FriabilityTargetRpm > 0 ? p.FriabilityTargetRpm : 25;
|
||||
double defaultRounds = p.FriabilityTargetRounds > 0 ? p.FriabilityTargetRounds : 100;
|
||||
FriabilityTargetRounds = Math.Max(1, (int)Math.Round(defaultRounds, MidpointRounding.AwayFromZero));
|
||||
FriabilityTargetTimeMin = p.FriabilityTargetTimeMin > 0
|
||||
? p.FriabilityTargetTimeMin
|
||||
: defaultRounds / FriabilityTargetRpm;
|
||||
@@ -360,10 +361,10 @@ namespace TabletTester2025.ViewModels
|
||||
_isLoadingDissolution2Time = false;
|
||||
_isLoadingDissolution1SampleInterval = false;
|
||||
_isLoadingDissolution2SampleInterval = false;
|
||||
_isLoadingFriabilityTime = false;
|
||||
_isLoadingFriabilityRounds = false;
|
||||
}
|
||||
|
||||
_ = WriteFriabilityTimeAsync(FriabilityTargetTimeMin);
|
||||
_ = WriteFriabilityRoundsAsync(FriabilityTargetRounds);
|
||||
}
|
||||
|
||||
private void LoadPharmaDefaults()
|
||||
@@ -999,16 +1000,21 @@ namespace TabletTester2025.ViewModels
|
||||
partial void OnFriabilityTargetTimeMinChanged(double value)
|
||||
{
|
||||
UpdateFriabilityTimingFromTime();
|
||||
|
||||
if (_isLoadingFriabilityTime)
|
||||
return;
|
||||
|
||||
_ = WriteFriabilityTimeAsync(value);
|
||||
}
|
||||
|
||||
partial void OnFriabilityTargetRpmChanged(double value)
|
||||
{
|
||||
UpdateFriabilityTimingFromTime();
|
||||
}
|
||||
|
||||
partial void OnFriabilityTargetRoundsChanged(int value)
|
||||
{
|
||||
if (value > 0 && Phase != TestPhase.Running)
|
||||
FriabilityRemainingRounds = value;
|
||||
|
||||
if (_isLoadingFriabilityRounds || value <= 0)
|
||||
return;
|
||||
|
||||
_ = WriteFriabilityRoundsAsync(value);
|
||||
}
|
||||
|
||||
private void UpdateFriabilityTimingFromTime()
|
||||
@@ -1016,9 +1022,7 @@ namespace TabletTester2025.ViewModels
|
||||
if (!double.IsFinite(FriabilityTargetTimeMin) || FriabilityTargetTimeMin <= 0)
|
||||
return;
|
||||
|
||||
double rpm = FriabilityTargetRpm > 0 ? FriabilityTargetRpm : 25;
|
||||
FriabilityTargetTimeSec = (int)Math.Ceiling(FriabilityTargetTimeMin * 60);
|
||||
FriabilityTargetRounds = Math.Max(1, (int)Math.Round(FriabilityTargetTimeMin * rpm, MidpointRounding.AwayFromZero));
|
||||
|
||||
if (Phase != TestPhase.Running)
|
||||
FriabilityRemainingRounds = FriabilityTargetRounds;
|
||||
@@ -1026,41 +1030,48 @@ namespace TabletTester2025.ViewModels
|
||||
|
||||
private async Task LoadFriabilitySettingsAsync()
|
||||
{
|
||||
await LoadFriabilityTimeAsync();
|
||||
await LoadFriabilityRoundsAsync();
|
||||
await LoadFriabilityWeightsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadFriabilityTimeAsync()
|
||||
private async Task LoadFriabilityRoundsAsync()
|
||||
{
|
||||
ushort registerAddress = ResolveFriabilityTestTimeRegister();
|
||||
ushort registerAddress = ResolveFriabilityRoundsRegister();
|
||||
if (registerAddress == 0)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
_isLoadingFriabilityTime = true;
|
||||
_isLoadingFriabilityRounds = true;
|
||||
int value = await _plc.ReadIntAsync(registerAddress);
|
||||
if (value > 0)
|
||||
{
|
||||
FriabilityTargetTimeMin = value;
|
||||
ApplyFriabilityRoundsFromPlc(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
await WriteFriabilityTimeAsync(FriabilityTargetTimeMin);
|
||||
await WriteFriabilityRoundsAsync(FriabilityTargetRounds);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
try { await WriteFriabilityTimeAsync(FriabilityTargetTimeMin); }
|
||||
try { await WriteFriabilityRoundsAsync(FriabilityTargetRounds); }
|
||||
catch { }
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isLoadingFriabilityTime = false;
|
||||
UpdateFriabilityTimingFromTime();
|
||||
_isLoadingFriabilityRounds = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyFriabilityRoundsFromPlc(int rounds)
|
||||
{
|
||||
FriabilityTargetRounds = Math.Max(1, rounds);
|
||||
|
||||
if (Phase != TestPhase.Running)
|
||||
FriabilityRemainingRounds = FriabilityTargetRounds;
|
||||
}
|
||||
|
||||
private async Task LoadFriabilityWeightsAsync()
|
||||
{
|
||||
try
|
||||
@@ -1100,22 +1111,28 @@ namespace TabletTester2025.ViewModels
|
||||
catch { }
|
||||
}
|
||||
|
||||
private async Task WriteFriabilityTimeAsync(double value)
|
||||
private async Task WriteFriabilityRoundsAsync(int value)
|
||||
{
|
||||
ushort registerAddress = ResolveFriabilityTestTimeRegister();
|
||||
if (registerAddress == 0 || !double.IsFinite(value) || value <= 0)
|
||||
ushort registerAddress = ResolveFriabilityRoundsRegister();
|
||||
if (registerAddress == 0 || value <= 0)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await _plc.WriteRegisterAsync(registerAddress, ToPlcTimeRegisterValue(value));
|
||||
await _plc.WriteRegisterAsync(registerAddress, (ushort)Math.Clamp(value, 0, ushort.MaxValue));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private ushort ResolveFriabilityTestTimeRegister()
|
||||
private ushort ResolveFriabilityRoundsRegister()
|
||||
{
|
||||
return _plcConfig.FriabilityTestTime;
|
||||
if (_plcConfig.FriabilityRounds != 0)
|
||||
return _plcConfig.FriabilityRounds;
|
||||
|
||||
if (_plcConfig.FriabilityRoundsBox != 0)
|
||||
return _plcConfig.FriabilityRoundsBox;
|
||||
|
||||
return _plcConfig.FriabilityTestTime != 0 ? _plcConfig.FriabilityTestTime : (ushort)410;
|
||||
}
|
||||
|
||||
private ushort ResolveFriabilityWeightBeforeRegister()
|
||||
@@ -1409,14 +1426,14 @@ namespace TabletTester2025.ViewModels
|
||||
if (!double.IsFinite(FriabilityTargetTimeMin) || FriabilityTargetTimeMin <= 0)
|
||||
throw new InvalidOperationException("脆碎试验时间必须大于0");
|
||||
|
||||
await WriteFriabilityTimeAsync(FriabilityTargetTimeMin);
|
||||
UpdateFriabilityTimingFromTime();
|
||||
await WriteFriabilityRoundsAsync(FriabilityTargetRounds);
|
||||
|
||||
double weightBefore = await ReadFriabilityWeightAsync(ResolveFriabilityWeightBeforeRegister(), "脆碎前重量");
|
||||
SetFriabilityWeightFromPlc(weightBefore: weightBefore);
|
||||
if (WeightBefore <= 0)
|
||||
throw new InvalidOperationException("脆碎前重量必须大于0");
|
||||
|
||||
UpdateFriabilityTimingFromTime();
|
||||
double rpm = FriabilityTargetRpm > 0 ? FriabilityTargetRpm : 25;
|
||||
double testTimeMin = FriabilityTargetTimeMin > 0 ? FriabilityTargetTimeMin : 4;
|
||||
int totalRounds = Math.Max(1, FriabilityTargetRounds);
|
||||
|
||||
Reference in New Issue
Block a user