This commit is contained in:
xyy
2026-05-15 15:48:43 +08:00
parent a050c307a8
commit ee29fa104d
6 changed files with 54 additions and 11 deletions

BIN
CSI-Z420片剂四用仪.gxw Normal file

Binary file not shown.

View File

@@ -9,6 +9,8 @@
// 硬度 // 硬度
public ushort HardnessValue { get; set; } public ushort HardnessValue { get; set; }
public ushort HardnessStartCoil { get; set; } public ushort HardnessStartCoil { get; set; }
public ushort HardnessStartCoil2 { get; set; }
public ushort HardnessStartCoil3 { get; set; }
public ushort HardnessCompleteCoil { get; set; } public ushort HardnessCompleteCoil { get; set; }
// 脆碎度 // 脆碎度

View File

@@ -136,19 +136,21 @@ namespace TabletTester2025.ViewModels
DissolutionPlotModel.Series.Add(_dissolutionSeries); DissolutionPlotModel.Series.Add(_dissolutionSeries);
// 硬度命令 // 硬度命令
HardnessUpCommand = new AsyncRelayCommand(async () => //HardnessUpCommand = new AsyncRelayCommand(async () =>
{ //{
// await _plc.WriteCoilAsync(0x20, true);
// await Task.Delay(100);
// await _plc.WriteCoilAsync(0x20, false);
//});
await _plc.WriteCoilAsync(0x20, true);
await Task.Delay(100);
await _plc.WriteCoilAsync(0x20, false);
});
HardnessDownCommand = new AsyncRelayCommand(async () => HardnessDownCommand = new AsyncRelayCommand(async () =>
{ {
await _plc.WriteCoilAsync(0x21, true); await _plc.WriteCoilAsync(0x21, true);
await Task.Delay(100); await Task.Delay(100);
await _plc.WriteCoilAsync(0x21, false); await _plc.WriteCoilAsync(0x21, false);
}); });
HardnessResetCommand = new AsyncRelayCommand(() => HardnessResetCommand = new AsyncRelayCommand(() =>
{ {
_hardnessResults.Clear(); _hardnessResults.Clear();
@@ -161,6 +163,7 @@ namespace TabletTester2025.ViewModels
Phase = TestPhase.Idle; Phase = TestPhase.Idle;
return Task.CompletedTask; return Task.CompletedTask;
}); });
PrintHardnessCommand = new AsyncRelayCommand(async () => await PrintReport("硬度")); PrintHardnessCommand = new AsyncRelayCommand(async () => await PrintReport("硬度"));
// 脆碎度命令 // 脆碎度命令
@@ -249,7 +252,9 @@ namespace TabletTester2025.ViewModels
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
await _plc.WriteCoilAsync(_plcConfig.HardnessStartCoil, true); await _plc.WriteCoilAsync((ushort)(StationId == 1 ? _plcConfig.HardnessStartCoil :
StationId == 2 ? _plcConfig.HardnessStartCoil2
: StationId == 3 ? _plcConfig.HardnessStartCoil3 : 0), true);
bool completed = false; bool completed = false;
while (!completed && Phase == TestPhase.Running) while (!completed && Phase == TestPhase.Running)
{ {
@@ -261,7 +266,12 @@ namespace TabletTester2025.ViewModels
HardnessValue = val; HardnessValue = val;
await Task.Delay(1000); await Task.Delay(1000);
} }
HardnessAvg = _hardnessResults.Average(); HardnessAvg = _hardnessResults.Average();
HardnessMax= _hardnessResults.Max();
HardnessMin = _hardnessResults.Min();
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;
@@ -529,5 +539,6 @@ namespace TabletTester2025.ViewModels
double sum = values.Sum(v => Math.Pow(v - avg, 2)); double sum = values.Sum(v => Math.Pow(v - avg, 2));
return Math.Sqrt(sum / values.Count); return Math.Sqrt(sum / values.Count);
} }
} }
} }

View File

@@ -123,8 +123,8 @@
<!-- 按钮区 --> <!-- 按钮区 -->
<WrapPanel Grid.Row="3" HorizontalAlignment="Center" Margin="0,10"> <WrapPanel Grid.Row="3" HorizontalAlignment="Center" Margin="0,10">
<Button Command="{Binding HardnessUpCommand}" Content="梁杆上升" Style="{StaticResource ActionButton}" Background="#FF9800" Margin="5 10 5 10"/> <!--<Button Command="{Binding HardnessUpCommand}" Content="梁杆上升" Style="{StaticResource ActionButton}" Background="#FF9800" Margin="5 10 5 10"/>
<Button Command="{Binding HardnessDownCommand}" Content="梁杆下降" Style="{StaticResource ActionButton}" Background="#FF9800"/> <Button Command="{Binding HardnessDownCommand}" Content="梁杆下降" Style="{StaticResource ActionButton}" Background="#FF9800"/>-->
<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"/>

View File

@@ -1,4 +1,6 @@
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace TabletTester2025 namespace TabletTester2025
{ {
@@ -8,5 +10,31 @@ namespace TabletTester2025
{ {
InitializeComponent(); InitializeComponent();
} }
private void OnHardnessUpPress(object sender, MouseButtonEventArgs e)
{
if (sender is Button btn && btn.DataContext is ViewModels.StationViewModel vm)
vm.StartHardnessUp();
}
private void OnHardnessUpRelease(object sender, MouseButtonEventArgs e)
{
if (sender is Button btn && btn.DataContext is ViewModels.StationViewModel vm)
vm.StopHardnessUp();
}
private void OnHardnessDownPress(object sender, MouseButtonEventArgs e)
{
if (sender is Button btn && btn.DataContext is ViewModels.StationViewModel vm)
vm.StartHardnessDown();
}
private void OnHardnessDownRelease(object sender, MouseButtonEventArgs e)
{
if (sender is Button btn && btn.DataContext is ViewModels.StationViewModel vm)
vm.StopHardnessDown();
}
} }
} }

View File

@@ -8,7 +8,9 @@
"Port": 502, "Port": 502,
"SlaveId": 1, "SlaveId": 1,
"HardnessValue": 100, "HardnessValue": 100,
"HardnessStartCoil": 10, "HardnessStartCoil": 70, //硬度工位1启动测试M70
"HardnessStartCoil2": 70, //硬度工位1启动测试M70
"HardnessStartCoil3": 70, //硬度工位1启动测试M70
"HardnessCompleteCoil": 11, "HardnessCompleteCoil": 11,
"FriabilityStartCoil": 20, "FriabilityStartCoil": 20,
"WeightBefore": 200, "WeightBefore": 200,