数据更新112
This commit is contained in:
@@ -28,6 +28,10 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
private const double DynamicWindowEndSeconds = 0.6;
|
||||
private const int MinimumDynamicWindowPointCount = 10;
|
||||
private const int StandardTrialCount = 3;
|
||||
private const string DefaultPlcPortName = "COM3";
|
||||
private const string DefaultAdcPortName = "COM4";
|
||||
private const string LegacyPlcPortName = "COM7";
|
||||
private const string LegacyAdcPortName = "COM8";
|
||||
|
||||
private readonly SlipResistanceDeviceService deviceService = new();
|
||||
private readonly SlipExcelExportService excelExportService = new();
|
||||
@@ -41,6 +45,9 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
|
||||
private bool isLoadingDeviceSettings;
|
||||
private bool wasRunning;
|
||||
private string activePlcPortName = string.Empty;
|
||||
private string activeAdcPortName = string.Empty;
|
||||
private int activeBaudRate;
|
||||
private List<SlipDataPoint> lastCompletedRun = [];
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -101,10 +108,10 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
private string frictionCoefficient2 = "0.00";
|
||||
|
||||
[ObservableProperty]
|
||||
private string plcPortName = "COM7";
|
||||
private string plcPortName = DefaultPlcPortName;
|
||||
|
||||
[ObservableProperty]
|
||||
private string adcPortName = "COM8";
|
||||
private string adcPortName = DefaultAdcPortName;
|
||||
|
||||
[ObservableProperty]
|
||||
private int baudRate = 115200;
|
||||
@@ -136,6 +143,12 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
[ObservableProperty]
|
||||
private string resultSummary = "等待 3 次有效试验";
|
||||
|
||||
[ObservableProperty]
|
||||
private string testButtonText = "测试";
|
||||
|
||||
[ObservableProperty]
|
||||
private string resetButtonText = "复位";
|
||||
|
||||
[ObservableProperty]
|
||||
private string staticCoefficient = "0.00";
|
||||
|
||||
@@ -233,7 +246,7 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
|
||||
LoadDeviceSettings();
|
||||
UpdateTargetLoad();
|
||||
deviceService.Start(CurrentSettings());
|
||||
RestartDeviceConnection();
|
||||
_ = LoadPlcParametersAsync();
|
||||
|
||||
refreshTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(20) };
|
||||
@@ -244,7 +257,8 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
[RelayCommand]
|
||||
private async Task Clear()
|
||||
{
|
||||
await RunDeviceCommand(deviceService.PulseResetAsync(), "已发送复位指令 M90");
|
||||
ApplyConnectionSettings();
|
||||
await RunDeviceCommand(deviceService.PulseResetAsync(), "已按老代码逻辑发送复位指令 M90");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -256,8 +270,20 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
[RelayCommand]
|
||||
private async Task StartTest()
|
||||
{
|
||||
BeginRun();
|
||||
await RunDeviceCommand(deviceService.PulseStartTestAsync(), "已发送测试启动指令 M80,等待 M81 运行状态");
|
||||
ApplyConnectionSettings();
|
||||
var device = deviceService.CurrentSnapshot;
|
||||
if (device.IsTestRunning)
|
||||
{
|
||||
await RunDeviceCommand(deviceService.PulseStopTestAsync(), "已按老代码逻辑发送停止指令 M83");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ValidateAdcCoefficientsBeforeTest())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunDeviceCommand(deviceService.PulseStartTestAsync(), "已按老代码逻辑发送测试启动指令 M80,等待 M81 运行状态");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -307,21 +333,17 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public Task StartLiftMotionAsync() => RunDeviceCommand(deviceService.StartLiftAsync(), "垂直架提升中,松开停止");
|
||||
[RelayCommand]
|
||||
private Task LiftMotion() => RunDeviceCommand(deviceService.ApplyOldLiftAsync(), "提升按老代码逻辑执行:M4=0, M5=1");
|
||||
|
||||
public Task StopLiftMotionAsync() => RunDeviceCommand(deviceService.StopLiftAsync(), "垂直架提升已停止");
|
||||
[RelayCommand]
|
||||
private Task LowerMotion() => RunDeviceCommand(deviceService.ApplyOldLowerAsync(), "下降按老代码逻辑执行:M5=0, M4=1");
|
||||
|
||||
public Task StartLowerMotionAsync() => RunDeviceCommand(deviceService.StartLowerAsync(), "垂直架下降中,松开停止");
|
||||
[RelayCommand]
|
||||
private Task MoveLeftMotion() => RunDeviceCommand(deviceService.ToggleOldMoveLeftAsync(), "左移按老代码逻辑切换 M1");
|
||||
|
||||
public Task StopLowerMotionAsync() => RunDeviceCommand(deviceService.StopLowerAsync(), "垂直架下降已停止");
|
||||
|
||||
public Task StartMoveLeftMotionAsync() => RunDeviceCommand(deviceService.StartMoveLeftAsync(), "水平板左移中,松开停止");
|
||||
|
||||
public Task StopMoveLeftMotionAsync() => RunDeviceCommand(deviceService.StopMoveLeftAsync(), "水平板左移已停止");
|
||||
|
||||
public Task StartMoveRightMotionAsync() => RunDeviceCommand(deviceService.StartMoveRightAsync(), "水平板右移中,松开停止");
|
||||
|
||||
public Task StopMoveRightMotionAsync() => RunDeviceCommand(deviceService.StopMoveRightAsync(), "水平板右移已停止");
|
||||
[RelayCommand]
|
||||
private Task MoveRightMotion() => RunDeviceCommand(deviceService.ToggleOldMoveRightAsync(), "右移按老代码逻辑切换 M2");
|
||||
|
||||
public Task StopAllMotionAsync() => RunDeviceCommand(deviceService.StopAllMotionAsync(), "全部运动已停止");
|
||||
|
||||
@@ -350,7 +372,7 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
private void CloseSettingsDialog()
|
||||
{
|
||||
IsSettingsDialogOpen = false;
|
||||
deviceService.UpdateSettings(CurrentSettings());
|
||||
ApplyConnectionSettings();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -452,19 +474,34 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
private void RefreshFromDevice()
|
||||
{
|
||||
var device = deviceService.CurrentSnapshot;
|
||||
DeviceStatus = device.IsConnected
|
||||
? device.IsTestRunning ? "联机 / 测试中" : device.IsResetting ? "联机 / 复位中" : "联机 / 待机"
|
||||
: "离线";
|
||||
|
||||
VerticalPressure = device.VerticalLoadN.ToString("F1", CultureInfo.InvariantCulture);
|
||||
HorizontalForce = device.HorizontalFrictionN.ToString("F1", CultureInfo.InvariantCulture);
|
||||
FrictionCoefficient = device.FrictionCoefficient.ToString("F3", CultureInfo.InvariantCulture);
|
||||
Distance = device.DisplacementMm.ToString("F1", CultureInfo.InvariantCulture);
|
||||
ActualLoadText = $"{VerticalPressure} N";
|
||||
if (device.IsConnected)
|
||||
{
|
||||
DeviceStatus = device.IsTestRunning ? "联机 / 测试中" : device.IsResetting ? "联机 / 复位中" : "联机 / 待机";
|
||||
TestButtonText = device.IsTestRunning ? "停止" : "测试";
|
||||
ResetButtonText = device.IsResetting ? "复位中" : "复位";
|
||||
VerticalPressure = device.VerticalLoadN.ToString("F1", CultureInfo.InvariantCulture);
|
||||
HorizontalForce = device.HorizontalFrictionN.ToString("F1", CultureInfo.InvariantCulture);
|
||||
FrictionCoefficient = device.FrictionCoefficient.ToString("F3", CultureInfo.InvariantCulture);
|
||||
Distance = device.DisplacementMm.ToString("F1", CultureInfo.InvariantCulture);
|
||||
ActualLoadText = $"{VerticalPressure} N";
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceStatus = IsAdcCalibrationError(device.LastError) ? "数据无效" : "离线";
|
||||
TestButtonText = device.IsTestRunning ? "停止" : "测试";
|
||||
ResetButtonText = device.IsResetting ? "复位中" : "复位";
|
||||
VerticalPressure = "--";
|
||||
HorizontalForce = "--";
|
||||
FrictionCoefficient = "--";
|
||||
Distance = "--";
|
||||
ActualLoadText = "-- N";
|
||||
}
|
||||
|
||||
if (!device.IsConnected && !string.IsNullOrWhiteSpace(device.LastError))
|
||||
{
|
||||
CurrentStatus = $"设备离线:{device.LastError}";
|
||||
CurrentStatus = IsAdcCalibrationError(device.LastError)
|
||||
? $"数据无效:{device.LastError}"
|
||||
: $"设备离线:{device.LastError}";
|
||||
}
|
||||
|
||||
var isRecording = device.IsConnected && device.IsTestRunning;
|
||||
@@ -694,6 +731,54 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
deviceService.UpdateSettings(CurrentSettings());
|
||||
}
|
||||
|
||||
private void ApplyConnectionSettings()
|
||||
{
|
||||
var settings = CurrentSettings();
|
||||
if (ConnectionSettingsChanged(settings))
|
||||
{
|
||||
RestartDeviceConnection(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
deviceService.UpdateSettings(settings);
|
||||
}
|
||||
|
||||
private bool ConnectionSettingsChanged(DeviceSettings settings) =>
|
||||
!string.Equals(activePlcPortName, settings.PlcPortName, StringComparison.OrdinalIgnoreCase)
|
||||
|| !string.Equals(activeAdcPortName, settings.AdcPortName, StringComparison.OrdinalIgnoreCase)
|
||||
|| activeBaudRate != settings.BaudRate;
|
||||
|
||||
private void RestartDeviceConnection()
|
||||
{
|
||||
RestartDeviceConnection(CurrentSettings());
|
||||
}
|
||||
|
||||
private void RestartDeviceConnection(DeviceSettings settings)
|
||||
{
|
||||
deviceService.Start(settings);
|
||||
activePlcPortName = settings.PlcPortName;
|
||||
activeAdcPortName = settings.AdcPortName;
|
||||
activeBaudRate = settings.BaudRate;
|
||||
}
|
||||
|
||||
private bool ValidateAdcCoefficientsBeforeTest()
|
||||
{
|
||||
var invalid = new List<string>();
|
||||
AddInvalidCoefficient(NormalPressureCoefficient, "正压力校准系数", invalid);
|
||||
AddInvalidCoefficient(FrictionCoefficient1, "摩擦1校准系数", invalid);
|
||||
AddInvalidCoefficient(FrictionCoefficient2, "摩擦2校准系数", invalid);
|
||||
|
||||
if (invalid.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var message = "ADC 校准系数无效:" + string.Join("、", invalid) + ";请填写旧机实际标定系数后再开始测试";
|
||||
Log.Warning("阻止测试启动:{Message}", message);
|
||||
CurrentStatus = message;
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task LoadPlcParametersAsync()
|
||||
{
|
||||
try
|
||||
@@ -739,8 +824,8 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
FrictionCoefficient1 = settings.FrictionCoefficient1 ?? FrictionCoefficient1;
|
||||
FrictionZero2 = settings.FrictionZero2 ?? FrictionZero2;
|
||||
FrictionCoefficient2 = settings.FrictionCoefficient2 ?? FrictionCoefficient2;
|
||||
PlcPortName = settings.PlcPortName ?? PlcPortName;
|
||||
AdcPortName = settings.AdcPortName ?? AdcPortName;
|
||||
PlcPortName = NormalizeSavedPort(settings.PlcPortName, DefaultPlcPortName, LegacyPlcPortName);
|
||||
AdcPortName = NormalizeSavedPort(settings.AdcPortName, DefaultAdcPortName, LegacyAdcPortName);
|
||||
BaudRate = settings.BaudRate > 0 ? settings.BaudRate : BaudRate;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -831,6 +916,27 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out numericValue)
|
||||
|| double.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out numericValue);
|
||||
|
||||
private static void AddInvalidCoefficient(string value, string label, List<string> invalid)
|
||||
{
|
||||
if (!TryParseDouble(value, out var coefficient) || Math.Abs(coefficient) < 0.0001)
|
||||
{
|
||||
invalid.Add($"{label}={value}");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAdcCalibrationError(string error) =>
|
||||
error.Contains("ADC 校准参数无效", StringComparison.Ordinal);
|
||||
|
||||
private static string NormalizeSavedPort(string? savedPort, string defaultPort, string legacyPort)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(savedPort) || string.Equals(savedPort, legacyPort, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return defaultPort;
|
||||
}
|
||||
|
||||
return savedPort;
|
||||
}
|
||||
|
||||
private static LineSeries<ObservablePoint> CreateLineSeries(
|
||||
string name,
|
||||
ObservableCollection<ObservablePoint> values,
|
||||
|
||||
Reference in New Issue
Block a user