现场的需求的更改
This commit is contained in:
@@ -338,7 +338,7 @@ namespace CapMachine.Wpf.Services
|
|||||||
}
|
}
|
||||||
else if (_superheatSubcoolCalculator.TryCalculateSuperheatK(InhPressTag.EngPvValue, InhTempTag.EngPvValue, out var superheatValue, out var superheatErr))
|
else if (_superheatSubcoolCalculator.TryCalculateSuperheatK(InhPressTag.EngPvValue, InhTempTag.EngPvValue, out var superheatValue, out var superheatErr))
|
||||||
{
|
{
|
||||||
Superheat.EngPvValue =Math.Abs(superheatValue) ;
|
Superheat.EngPvValue = Math.Abs(superheatValue);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -651,11 +651,11 @@ namespace CapMachine.Wpf.Services
|
|||||||
COPCooling = result.COPCooling;
|
COPCooling = result.COPCooling;
|
||||||
IsentropicEfficiencyPct = result.IsentropicEfficiencyPct;
|
IsentropicEfficiencyPct = result.IsentropicEfficiencyPct;
|
||||||
|
|
||||||
// 再把结果回写到对应工程量标签。
|
// 再把结果回写到对应工程量标签
|
||||||
HeatingCapacity.EngPvValue = HeatingCapacityQh_kW;
|
HeatingCapacity.EngPvValue = HeatingCapacityQh_kW * 1000;
|
||||||
COPHeat.EngPvValue = COPHeating;
|
COPHeat.EngPvValue = COPHeating;
|
||||||
IsentrpEff.EngPvValue = IsentropicEfficiencyPct;
|
IsentrpEff.EngPvValue = IsentropicEfficiencyPct;
|
||||||
CoolCapacity.EngPvValue = CoolingCapacityQc_kW;
|
CoolCapacity.EngPvValue = CoolingCapacityQc_kW * 1000;
|
||||||
COPCool.EngPvValue = COPCooling;
|
COPCool.EngPvValue = COPCooling;
|
||||||
|
|
||||||
// 容积效率在旧逻辑中允许单独失败;
|
// 容积效率在旧逻辑中允许单独失败;
|
||||||
@@ -756,21 +756,87 @@ namespace CapMachine.Wpf.Services
|
|||||||
{
|
{
|
||||||
displacement_cc = double.NaN;
|
displacement_cc = double.NaN;
|
||||||
error = string.Empty;
|
error = string.Empty;
|
||||||
|
const double defaultDisplacementCc = 35d;
|
||||||
|
|
||||||
displacement_cc = 35;
|
if (TryGetCompressorDisplacementFromCurrentExperiment(out displacement_cc, out var experimentError))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TryGetCompressorDisplacementFromConfig(out displacement_cc, out var configError))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
displacement_cc = defaultDisplacementCc;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从当前选中的实验信息中读取并解析压缩机排量。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="displacement_cc">排量输出,单位 cc。</param>
|
||||||
|
/// <param name="error">失败原因。</param>
|
||||||
|
/// <returns>是否读取成功。</returns>
|
||||||
|
private bool TryGetCompressorDisplacementFromCurrentExperiment(out double displacement_cc, out string error)
|
||||||
|
{
|
||||||
|
displacement_cc = double.NaN;
|
||||||
|
error = string.Empty;
|
||||||
|
|
||||||
|
if (ConfigService.CurExpInfo == null)
|
||||||
|
{
|
||||||
|
error = "当前未选择实验信息,无法从试验信息读取压缩机排量";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var displacementText = ConfigService.CurExpInfo.CapDisplacement;
|
||||||
|
if (string.IsNullOrWhiteSpace(displacementText))
|
||||||
|
{
|
||||||
|
error = "当前试验信息未填写压缩机排量";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryParseCompressorDisplacementText(displacementText, out displacement_cc))
|
||||||
|
{
|
||||||
|
error = $"当前试验信息压缩机排量无法解析: {displacementText}";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displacement_cc <= 0)
|
||||||
|
{
|
||||||
|
error = $"当前试验信息压缩机排量<=0: {displacement_cc}";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从配置项读取并解析压缩机排量。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="displacement_cc">排量输出,单位 cc。</param>
|
||||||
|
/// <param name="error">失败原因。</param>
|
||||||
|
/// <returns>是否读取成功。</returns>
|
||||||
|
private bool TryGetCompressorDisplacementFromConfig(out double displacement_cc, out string error)
|
||||||
|
{
|
||||||
|
displacement_cc = double.NaN;
|
||||||
|
error = string.Empty;
|
||||||
|
|
||||||
const string key = "CompressorDisplacementCc";
|
const string key = "CompressorDisplacementCc";
|
||||||
//if (!ConfigHelper.IsExist(key))
|
string configValue;
|
||||||
//{
|
try
|
||||||
// error = $"未配置压缩机排量,请在 App.config/appSettings 增加 {key}(单位 cc)";
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
string v = ConfigHelper.GetValue(key);
|
|
||||||
if (!double.TryParse(v, out displacement_cc))
|
|
||||||
{
|
{
|
||||||
error = $"压缩机排量配置无法解析: {v}";
|
configValue = ConfigHelper.GetValue(key);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
error = $"未配置压缩机排量,请在 App.config/appSettings 增加 {key}(单位 cc)";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryParseCompressorDisplacementText(configValue, out displacement_cc))
|
||||||
|
{
|
||||||
|
error = $"压缩机排量配置无法解析: {configValue}";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -783,6 +849,42 @@ namespace CapMachine.Wpf.Services
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析排量文本为数值。
|
||||||
|
/// 支持纯数字与包含单位的文本(如 34.5、34.5cc、34,5 cm3)。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="displacementText">排量文本。</param>
|
||||||
|
/// <param name="displacementCc">解析后的排量数值,单位 cc。</param>
|
||||||
|
/// <returns>是否解析成功。</returns>
|
||||||
|
private static bool TryParseCompressorDisplacementText(string displacementText, out double displacementCc)
|
||||||
|
{
|
||||||
|
displacementCc = double.NaN;
|
||||||
|
if (string.IsNullOrWhiteSpace(displacementText))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var normalizedText = displacementText.Trim();
|
||||||
|
if (double.TryParse(normalizedText, out displacementCc))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (double.TryParse(normalizedText, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out displacementCc))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var match = System.Text.RegularExpressions.Regex.Match(normalizedText, @"[-+]?\d+(?:[\.,]\d+)?");
|
||||||
|
if (!match.Success)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var numericText = match.Value.Replace(',', '.');
|
||||||
|
return double.TryParse(numericText, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out displacementCc);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using CapMachine.Wpf.Services;
|
using CapMachine.Wpf.Services;
|
||||||
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace CapMachine.Wpf.Views
|
namespace CapMachine.Wpf.Views
|
||||||
@@ -8,10 +9,19 @@ namespace CapMachine.Wpf.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainView : Window
|
public partial class MainView : Window
|
||||||
{
|
{
|
||||||
public MainView(ILogService logService)
|
private readonly ZlgCanDriveService _zlgCanDriveService;
|
||||||
|
private readonly ZlgLinDriveService _zlgLinDriveService;
|
||||||
|
private readonly CanDriveService _canDriveService;
|
||||||
|
private readonly LinDriveService _linDriveService;
|
||||||
|
|
||||||
|
public MainView(ILogService logService, ZlgCanDriveService zlgCanDriveService, ZlgLinDriveService zlgLinDriveService, CanDriveService canDriveService, LinDriveService linDriveService)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
LogService = logService;
|
LogService = logService;
|
||||||
|
_zlgCanDriveService = zlgCanDriveService;
|
||||||
|
_zlgLinDriveService = zlgLinDriveService;
|
||||||
|
_canDriveService = canDriveService;
|
||||||
|
_linDriveService = linDriveService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILogService LogService { get; }
|
public ILogService LogService { get; }
|
||||||
@@ -42,10 +52,110 @@ namespace CapMachine.Wpf.Views
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
StopBusCommunicationOnExit();
|
||||||
LogService.Info("Windows关闭");
|
LogService.Info("Windows关闭");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 软件退出时停止总线通信,防止适配器在进程退出后继续自动发送。
|
||||||
|
/// </summary>
|
||||||
|
private void StopBusCommunicationOnExit()
|
||||||
|
{
|
||||||
|
StopZlgBusCommunicationOnExit();
|
||||||
|
StopToomossBusCommunicationOnExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止 ZLG CAN/CANFD 与 LIN 通信。
|
||||||
|
/// </summary>
|
||||||
|
private void StopZlgBusCommunicationOnExit()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_zlgLinDriveService.OpenState)
|
||||||
|
{
|
||||||
|
if (_zlgLinDriveService.IsCycleSend || _zlgLinDriveService.SchEnable)
|
||||||
|
{
|
||||||
|
_zlgLinDriveService.StopSchedule();
|
||||||
|
_zlgLinDriveService.IsCycleSend = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_zlgLinDriveService.CloseDevice();
|
||||||
|
LogService.Info("程序退出时已停止 ZLG LIN 调度/发送并关闭设备");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_zlgCanDriveService.OpenState)
|
||||||
|
{
|
||||||
|
if (_zlgCanDriveService.IsCycleSend || _zlgCanDriveService.SchEnable)
|
||||||
|
{
|
||||||
|
_zlgCanDriveService.StopSchedule();
|
||||||
|
_zlgCanDriveService.IsCycleSend = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_zlgCanDriveService.CloseDevice();
|
||||||
|
LogService.Info("程序退出时已停止 ZLG CAN/CANFD 调度/发送并关闭设备");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogService.Error($"程序退出停止 ZLG 总线失败:{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止 Toomoss CAN 与 LIN 通信。
|
||||||
|
/// </summary>
|
||||||
|
private void StopToomossBusCommunicationOnExit()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_linDriveService.ToomossLinDrive.OpenState)
|
||||||
|
{
|
||||||
|
if (_linDriveService.ToomossLinDrive.IsCycleSend)
|
||||||
|
{
|
||||||
|
_linDriveService.ToomossLinDrive.StopCycleSendMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_linDriveService.ToomossLinDrive.SchEnable)
|
||||||
|
{
|
||||||
|
_linDriveService.ToomossLinDrive.StopSchedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
_linDriveService.ToomossLinDrive.CloseDevice();
|
||||||
|
LogService.Info("程序退出时已停止 Toomoss LIN 调度/发送并关闭设备");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogService.Error($"程序退出停止 Toomoss LIN 失败:{ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_canDriveService.ToomossCanDrive.OpenState)
|
||||||
|
{
|
||||||
|
if (_canDriveService.ToomossCanDrive.IsCycleSend)
|
||||||
|
{
|
||||||
|
_canDriveService.ToomossCanDrive.StopCycleSendMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_canDriveService.ToomossCanDrive.SchEnable)
|
||||||
|
{
|
||||||
|
_canDriveService.ToomossCanDrive.StopSchedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
_canDriveService.ToomossCanDrive.CloseDevice();
|
||||||
|
LogService.Info("程序退出时已停止 Toomoss CAN 调度/发送并关闭设备");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogService.Error($"程序退出停止 Toomoss CAN 失败:{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主界面完成关闭
|
/// 主界面完成关闭
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user