页面逻辑添加
This commit is contained in:
@@ -12,11 +12,19 @@
|
||||
public ushort HardnessStartCoil2 { get; set; }
|
||||
public ushort HardnessStartCoil3 { get; set; }
|
||||
public ushort HardnessCompleteCoil { get; set; }
|
||||
|
||||
public ushort HardnessStartReset { get; set; }
|
||||
public ushort HardnessStartStop { get; set; }
|
||||
|
||||
// 脆碎度
|
||||
public ushort FriabilityStartCoil { get; set; }
|
||||
public ushort WeightBefore { get; set; } // 天平重量寄存器(可选)
|
||||
public ushort WeightAfter { get; set; }
|
||||
public ushort FriabilityStartCoil2 { get; set; }
|
||||
public ushort FriabilityStartCoil3 { get; set; }
|
||||
|
||||
public ushort FriabilityStartCoilStop { get; set; }
|
||||
public ushort FriabilityStartCoilReset { get; set; }
|
||||
|
||||
|
||||
// 崩解
|
||||
public ushort DisintegrationTemp { get; set; }
|
||||
|
||||
@@ -3,13 +3,19 @@
|
||||
namespace TabletTester2025.Services
|
||||
{
|
||||
public interface IPlcService
|
||||
{
|
||||
{ //建立通讯链接
|
||||
Task ConnectAsync();
|
||||
//从 PLC 的指定起始地址,读取 1 个 32 位浮点型(float)数据。
|
||||
Task<float> ReadFloatAsync(ushort startAddress);
|
||||
//从 PLC 的指定起始地址,读取 1 个 32 位整型(int)数据。
|
||||
Task<int> ReadIntAsync(ushort startAddress);
|
||||
//向 PLC 的指定线圈地址,写入一个布尔值(开关量)。
|
||||
Task WriteCoilAsync(ushort coilAddress, bool value);
|
||||
//读取 PLC 指定线圈地址的布尔状态,是 WriteCoilAsync 的配套读取方法。
|
||||
Task<bool> ReadCoilAsync(ushort coilAddress);
|
||||
//向 PLC 的指定寄存器地址,写入 1 个 16 位无符号整型(ushort)数据。
|
||||
Task WriteRegisterAsync(ushort registerAddress, ushort value);
|
||||
//批量读取 PLC 的保持寄存器数据,是工业通信中最高效的批量读取方法。
|
||||
Task<ushort[]> ReadHoldingRegistersAsync(ushort startAddress, ushort count);
|
||||
bool IsConnected { get; }
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace TabletTester2025.ViewModels
|
||||
[ObservableProperty] private bool _friabilityCounterClockwise;
|
||||
[ObservableProperty] private double _friabilityCurrentRpm;
|
||||
[ObservableProperty] private int _friabilityRemainingRounds = 100;
|
||||
|
||||
public IAsyncRelayCommand StopHardnessCommand { get; }
|
||||
public IAsyncRelayCommand StopFriabilityCommand { get; }
|
||||
public IAsyncRelayCommand ResetFriabilityCommand { get; }
|
||||
public IAsyncRelayCommand PrintFriabilityCommand { get; }
|
||||
@@ -153,8 +153,13 @@ namespace TabletTester2025.ViewModels
|
||||
await _plc.WriteCoilAsync(0x21, false);
|
||||
});
|
||||
|
||||
HardnessResetCommand = new AsyncRelayCommand(() =>
|
||||
//复位
|
||||
HardnessResetCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
// 1. 标准PLC按钮脉冲逻辑:置1 → 延时 → 置0(模拟按下再松开按钮)
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartReset, true);
|
||||
await Task.Delay(100); // 脉冲宽度,可根据PLC程序调整20~100ms
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartReset, false);
|
||||
_hardnessResults.Clear();
|
||||
HardnessValue = 0;
|
||||
HardnessAvg = 0;
|
||||
@@ -163,14 +168,25 @@ namespace TabletTester2025.ViewModels
|
||||
HardnessMax = 0;
|
||||
HardnessMin = 0;
|
||||
Phase = TestPhase.Idle;
|
||||
return Task.CompletedTask;
|
||||
|
||||
});
|
||||
|
||||
PrintHardnessCommand = new AsyncRelayCommand(async () => await PrintReport("硬度"));
|
||||
|
||||
// 硬度命令停止
|
||||
StopHardnessCommand = new AsyncRelayCommand(async() => {
|
||||
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartStop, true);
|
||||
await Task.Delay(100); // 脉冲宽度,可根据PLC程序调整20~100ms
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartStop, false);
|
||||
|
||||
Phase = TestPhase.Idle;
|
||||
});
|
||||
// 脆碎度命令
|
||||
StopFriabilityCommand = new AsyncRelayCommand(() => {
|
||||
|
||||
//测试停止
|
||||
|
||||
Phase = TestPhase.Idle; return Task.CompletedTask;
|
||||
});
|
||||
ResetFriabilityCommand = new AsyncRelayCommand(() =>
|
||||
|
||||
@@ -15,33 +15,7 @@ namespace TabletTester2025
|
||||
}
|
||||
|
||||
|
||||
//硬度测试
|
||||
// 启动测试按钮点击事件
|
||||
private async void btnStartTest_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 模拟PLC读取硬度值(实际项目替换为你的ReadFloatAsync调用)
|
||||
private async Task<float> ReadPlcHardnessAsync()
|
||||
{
|
||||
await Task.Delay(100); // 模拟通信延迟
|
||||
// 这里可以直接用你之前写好的PLC读取方法:
|
||||
// return await _plc.ReadFloatAsync((ushort)你的硬度地址);
|
||||
return new Random().Next(80, 120) + (float)new Random().NextDouble() * 10;
|
||||
}
|
||||
|
||||
// 复位按钮点击事件
|
||||
private void btnReset_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 梁杆上升按钮(示例)
|
||||
private void btnUp_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,16 @@
|
||||
"HardnessStartCoil": 70, //硬度工位1启动测试M70
|
||||
"HardnessStartCoil2": 70, //硬度工位1启动测试M70
|
||||
"HardnessStartCoil3": 70, //硬度工位1启动测试M70
|
||||
"HardnessStartStop": 73, // 硬度停止
|
||||
"HardnessStartReset": 90, // 硬复位启动
|
||||
|
||||
"FriabilityStartCoil": 80, //脆碎工位1启动测试M70
|
||||
"FriabilityStartCoil2": 80, //脆碎工位1启动测试M70
|
||||
"FriabilityStartCoil3": 80, //脆碎工位1启动测试M70
|
||||
"FriabilityStartCoilStop": 83, // 脆碎停止
|
||||
"FriabilityStartCoilReset": 95, // 脆碎复位启动
|
||||
"HardnessCompleteCoil": 11,
|
||||
//"FriabilityStartCoil": 20,
|
||||
|
||||
"WeightBefore": 200,
|
||||
"WeightAfter": 202,
|
||||
"DisintegrationTemp": 300,
|
||||
|
||||
Reference in New Issue
Block a user