Compare commits
3 Commits
0be171ee32
...
af337fc6f3
| Author | SHA1 | Date | |
|---|---|---|---|
| af337fc6f3 | |||
| aa7da6b301 | |||
| ebade3b89d |
@@ -205,6 +205,7 @@ namespace CapMachine.Wpf
|
||||
containerRegistry.RegisterDialog<DialogPIDConfigView, DialogPIDConfigViewModel>();
|
||||
containerRegistry.RegisterDialog<DialogLimitConfigView, DialogLimitConfigViewModel>();
|
||||
containerRegistry.RegisterDialog<DialogSuperHeatCoolConfigView, DialogSuperHeatCoolConfigViewModel>();
|
||||
containerRegistry.RegisterDialog<DialogTherdyConfigView, DialogTherdyConfigViewModel>();
|
||||
containerRegistry.RegisterDialog<DialogLogicRuleView, DialogLogicRuleViewModel>();
|
||||
containerRegistry.RegisterDialog<DialogCanLinConfigImExportView, DialogCanLinConfigImExportViewModel>();
|
||||
containerRegistry.RegisterDialog<DialogCANFdSchConfigView, DialogCANFdSchConfigViewModel>();
|
||||
|
||||
15
CapMachine.Wpf/Models/PPCalc/TherdyConfigModel.cs
Normal file
15
CapMachine.Wpf/Models/PPCalc/TherdyConfigModel.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Prism.Mvvm;
|
||||
|
||||
namespace CapMachine.Wpf.Models.PPCalc
|
||||
{
|
||||
public class TherdyConfigModel : BindableBase
|
||||
{
|
||||
private double _h3TempOffset_C = -10.0;
|
||||
|
||||
public double H3TempOffset_C
|
||||
{
|
||||
get { return _h3TempOffset_C; }
|
||||
set { _h3TempOffset_C = value; RaisePropertyChanged(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,9 @@ namespace CapMachine.Wpf.Services
|
||||
case "过热度/过冷度配置":
|
||||
ShowSuperHeatCool(msg.Par);
|
||||
break;
|
||||
case "COP物性参数回差":
|
||||
ShowTherdyConfig(msg.Par);
|
||||
break;
|
||||
case "规则转换":
|
||||
if (SysRunServer.MachineRunState1.IsRunState)
|
||||
{
|
||||
@@ -104,7 +107,19 @@ namespace CapMachine.Wpf.Services
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// COP物性参数回差配置弹窗
|
||||
/// </summary>
|
||||
private void ShowTherdyConfig(object par)
|
||||
{
|
||||
DialogService.ShowDialog("DialogTherdyConfigView", new DialogParameters() { { "Name", par } }, (dialogResult) =>
|
||||
{
|
||||
if (dialogResult.Result == ButtonResult.OK)
|
||||
{
|
||||
PPCService.ReloadTherdyH3TempOffset();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 过热度和过冷度配置弹窗
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace CapMachine.Wpf.Services
|
||||
new NavigationItem("", "计算信息","",new ObservableCollection<NavigationItem>()
|
||||
{
|
||||
new NavigationItem("SuperHeatCool","过热度/过冷度配置","DialogSuperHeatCoolConfigView"),
|
||||
new NavigationItem("","COP物性参数回差","DialogTherdyConfigView"),
|
||||
//new NavigationItem("Palette","过冷度",""),
|
||||
}),
|
||||
new NavigationItem("", "规则设置","",new ObservableCollection<NavigationItem>()
|
||||
|
||||
@@ -127,6 +127,18 @@ namespace CapMachine.Wpf.Services
|
||||
|
||||
ReloadTherdyH3TempOffset();
|
||||
|
||||
// 订阅 ConfigService.CurExpInfo 属性变化,实验切换时自动刷新排量缓存
|
||||
ConfigService.PropertyChanged += (sender, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(ConfigService.CurExpInfo))
|
||||
{
|
||||
RefreshDisplacementCache();
|
||||
}
|
||||
};
|
||||
|
||||
// 首次初始化排量缓存
|
||||
RefreshDisplacementCache();
|
||||
|
||||
RtScanDeviceStart();
|
||||
}
|
||||
|
||||
@@ -291,6 +303,16 @@ namespace CapMachine.Wpf.Services
|
||||
/// </summary>
|
||||
private bool DebugLog { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存的压缩机排量值(cc),在实验切换时自动刷新
|
||||
/// </summary>
|
||||
private double _cachedDisplacement_cc = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存数据来源标识(用于调试):ExpInfo=实验信息, Config=配置文件, Default=默认值
|
||||
/// </summary>
|
||||
private string _cachedSource = string.Empty;
|
||||
|
||||
private int _CurDisplacementCc;
|
||||
/// <summary>
|
||||
/// 当前的排量信息(供 UI 展示)
|
||||
@@ -683,60 +705,98 @@ namespace CapMachine.Wpf.Services
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取压缩机排量。
|
||||
/// 获取压缩机排量(使用缓存机制,避免每次计算周期实时读取)
|
||||
/// </summary>
|
||||
/// <param name="displacement_cc">排量输出,单位 cc(cm³/rev)。</param>
|
||||
/// <param name="error">失败原因(未配置、解析失败、数值不合法)。</param>
|
||||
/// <returns>是否获取成功。</returns>
|
||||
/// <param name="error">失败原因(仅在缓存异常时返回)。</param>
|
||||
/// <returns>始终返回 true(因为默认回退 35cc 保证缓存始终有效)。</returns>
|
||||
private bool TryGetCompressorDisplacement_cc(out double displacement_cc, out string error)
|
||||
{
|
||||
displacement_cc = double.NaN;
|
||||
displacement_cc = _cachedDisplacement_cc;
|
||||
error = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新压缩机排量缓存,按优先级读取:实验信息 > 配置文件 > 默认值
|
||||
/// 实验切换时自动调用,保证缓存与当前实验信息一致
|
||||
/// </summary>
|
||||
private void RefreshDisplacementCache()
|
||||
{
|
||||
const double defaultDisplacementCc = 35d;
|
||||
const string key = "CompressorDisplacementCc";
|
||||
double displacementCc = defaultDisplacementCc;
|
||||
string source = "Default";
|
||||
|
||||
static bool TryParseDisplacementCc(string? text, out double displacementCc)
|
||||
// 优先1:从当前实验信息读取
|
||||
if (ConfigService?.CurExpInfo != null &&
|
||||
TryParseCompressorDisplacementTextToCc(ConfigService.CurExpInfo.CapDisplacement, out var expCc) &&
|
||||
expCc > 0)
|
||||
{
|
||||
displacementCc = double.NaN;
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
displacementCc = expCc;
|
||||
source = "ExpInfo";
|
||||
}
|
||||
// 优先2:从 App.config 配置读取
|
||||
else
|
||||
{
|
||||
string configValue = ConfigHelper.GetValue("CompressorDisplacementCc");
|
||||
if (!string.IsNullOrWhiteSpace(configValue) &&
|
||||
TryParseCompressorDisplacementTextToCc(configValue, out var cfgCc) &&
|
||||
cfgCc > 0)
|
||||
{
|
||||
return false;
|
||||
displacementCc = cfgCc;
|
||||
source = "Config";
|
||||
}
|
||||
|
||||
var normalized = text.Trim().ToLowerInvariant();
|
||||
normalized = normalized.Replace(',', '.');
|
||||
|
||||
var match = Regex.Match(normalized, @"[-+]?\d+(\.\d+)?");
|
||||
if (!match.Success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!double.TryParse(match.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var v))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
displacementCc = v;
|
||||
return true;
|
||||
// 优先3:使用默认值(已在初始化时设置)
|
||||
}
|
||||
|
||||
try
|
||||
// 更新缓存字段
|
||||
_cachedDisplacement_cc = displacementCc;
|
||||
_cachedSource = source;
|
||||
|
||||
// 同步更新 UI 展示属性
|
||||
CurDisplacementCc = (int)displacementCc;
|
||||
|
||||
// 记录日志(便于调试)
|
||||
Logger?.Info($"压缩机排量缓存已刷新: {displacementCc}cc (来源: {source})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制刷新压缩机排量缓存(供外部主动调用,用于调试或特殊情况如 App.config 配置修改后)
|
||||
/// </summary>
|
||||
public void ForceRefreshDisplacementCache()
|
||||
{
|
||||
RefreshDisplacementCache();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析压缩机排量文本,支持多种格式(如 34.5cc、34,5 cm3 等)
|
||||
/// </summary>
|
||||
/// <param name="text">排量文本</param>
|
||||
/// <param name="displacementCc">解析出的排量值(cc)</param>
|
||||
/// <returns>是否解析成功</returns>
|
||||
private static bool TryParseCompressorDisplacementTextToCc(string? text, out double displacementCc)
|
||||
{
|
||||
displacementCc = double.NaN;
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
string raw = ConfigHelper.GetValue(key);
|
||||
if (TryParseDisplacementCc(raw, out var cfgCc) && cfgCc > 0)
|
||||
{
|
||||
displacement_cc = cfgCc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略配置读取异常,走默认回退值
|
||||
return false;
|
||||
}
|
||||
|
||||
displacement_cc = defaultDisplacementCc;
|
||||
var normalized = text.Trim().ToLowerInvariant();
|
||||
normalized = normalized.Replace(',', '.');
|
||||
|
||||
var match = Regex.Match(normalized, @"[-+]?\d+(\.\d+)?");
|
||||
if (!match.Success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!double.TryParse(match.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var v))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
displacementCc = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
114
CapMachine.Wpf/ViewModels/DialogTherdyConfigViewModel.cs
Normal file
114
CapMachine.Wpf/ViewModels/DialogTherdyConfigViewModel.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using CapMachine.Core;
|
||||
using CapMachine.Wpf.Models.PPCalc;
|
||||
using Prism.Commands;
|
||||
using Prism.Services.Dialogs;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.ViewModels
|
||||
{
|
||||
public class DialogTherdyConfigViewModel : DialogViewModel
|
||||
{
|
||||
private const string H3TempOffsetConfigKey = "Therdy_H3TempOffset_C";
|
||||
|
||||
public DialogTherdyConfigViewModel()
|
||||
{
|
||||
TherdyConfig = new TherdyConfigModel();
|
||||
LoadConfig();
|
||||
}
|
||||
|
||||
private string _h3TempOffsetText = string.Empty;
|
||||
public string H3TempOffsetText
|
||||
{
|
||||
get { return _h3TempOffsetText; }
|
||||
set { _h3TempOffsetText = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
public TherdyConfigModel TherdyConfig { get; set; }
|
||||
|
||||
private DelegateCommand saveCmd;
|
||||
public DelegateCommand SaveCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (saveCmd == null)
|
||||
{
|
||||
saveCmd = new DelegateCommand(SaveCmdMethod);
|
||||
}
|
||||
return saveCmd;
|
||||
}
|
||||
set { saveCmd = value; }
|
||||
}
|
||||
|
||||
private DelegateCommand cancelCmd;
|
||||
public DelegateCommand CancelCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cancelCmd == null)
|
||||
{
|
||||
cancelCmd = new DelegateCommand(CancelCmdMethod);
|
||||
}
|
||||
return cancelCmd;
|
||||
}
|
||||
set { cancelCmd = value; }
|
||||
}
|
||||
|
||||
private void LoadConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
string raw = ConfigHelper.GetValue(H3TempOffsetConfigKey);
|
||||
if (!string.IsNullOrWhiteSpace(raw) && double.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out var v))
|
||||
{
|
||||
TherdyConfig.H3TempOffset_C = v;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
H3TempOffsetText = TherdyConfig.H3TempOffset_C.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private void SaveConfig()
|
||||
{
|
||||
ConfigHelper.SetValue(H3TempOffsetConfigKey, TherdyConfig.H3TempOffset_C.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
private void SaveCmdMethod()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!double.TryParse(H3TempOffsetText, NumberStyles.Float, CultureInfo.InvariantCulture, out var offsetC))
|
||||
{
|
||||
MessageBox.Show("回差值格式不正确,请输入数字(例如 -10)。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
TherdyConfig.H3TempOffset_C = offsetC;
|
||||
SaveConfig();
|
||||
DialogParameters pars = new DialogParameters
|
||||
{
|
||||
{ "H3TempOffset_C", TherdyConfig.H3TempOffset_C }
|
||||
};
|
||||
RaiseRequestClose(new DialogResult(ButtonResult.OK, pars));
|
||||
}
|
||||
catch
|
||||
{
|
||||
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelCmdMethod()
|
||||
{
|
||||
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
|
||||
}
|
||||
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
LoadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
new CbxItems(){ Key="通讯Cmp母线电压",Text="通讯Cmp母线电压"},
|
||||
new CbxItems(){ Key="通讯Cmp母线电流",Text="通讯Cmp母线电流"},
|
||||
new CbxItems(){ Key="通讯Cmp相电流",Text="通讯Cmp相电流"},
|
||||
new CbxItems(){ Key="通讯Cmp逆变器温度",Text="通讯Cmp逆变器温度"},
|
||||
new CbxItems(){ Key="通讯Cmp功率",Text="通讯Cmp功率"},
|
||||
new CbxItems(){ Key="通讯Cmp芯片温度",Text="通讯Cmp芯片温度"},
|
||||
|
||||
|
||||
59
CapMachine.Wpf/Views/DialogTherdyConfigView.xaml
Normal file
59
CapMachine.Wpf/Views/DialogTherdyConfigView.xaml
Normal file
@@ -0,0 +1,59 @@
|
||||
<UserControl
|
||||
x:Class="CapMachine.Wpf.Views.DialogTherdyConfigView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:CapMachine.Wpf.Views"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Width="800"
|
||||
Height="240"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0">
|
||||
<StackPanel
|
||||
Margin="20"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="10,0,10,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="26"
|
||||
FontWeight="Bold"
|
||||
Foreground="DimGray"
|
||||
Text="排气压力饱和温度回差(℃):" />
|
||||
<TextBox
|
||||
Width="160"
|
||||
Margin="10,0,0,0"
|
||||
HorizontalContentAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
FontSize="24"
|
||||
Text="{Binding H3TempOffsetText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Margin="0,10,20,10"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
Margin="10,0"
|
||||
Command="{Binding SaveCmd}"
|
||||
Content="确定"
|
||||
Foreground="White" />
|
||||
<Button
|
||||
Margin="10,0"
|
||||
Command="{Binding CancelCmd}"
|
||||
Content="取消"
|
||||
Foreground="White" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
12
CapMachine.Wpf/Views/DialogTherdyConfigView.xaml.cs
Normal file
12
CapMachine.Wpf/Views/DialogTherdyConfigView.xaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CapMachine.Wpf.Views
|
||||
{
|
||||
public partial class DialogTherdyConfigView : UserControl
|
||||
{
|
||||
public DialogTherdyConfigView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<materialDesign:Card
|
||||
Grid.ColumnSpan="6"
|
||||
Grid.ColumnSpan="5"
|
||||
Margin="3"
|
||||
Background="{DynamicResource MaterialDesignLightBackground}"
|
||||
Foreground="{DynamicResource PrimaryHueLightForegroundBrush}"
|
||||
@@ -232,6 +232,39 @@
|
||||
</StackPanel>
|
||||
</materialDesign:Card>
|
||||
|
||||
<materialDesign:Card
|
||||
Grid.Column="5"
|
||||
Margin="3"
|
||||
Background="{DynamicResource MaterialDesignLightBackground}"
|
||||
Foreground="{DynamicResource PrimaryHueLightForegroundBrush}"
|
||||
UniformCornerRadius="5">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="10,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="/Assets/Fonts/#iconfont"
|
||||
FontSize="26"
|
||||
Foreground="LimeGreen"
|
||||
Text="" />
|
||||
<TextBlock
|
||||
Foreground="LimeGreen"
|
||||
Style="{StaticResource TitelStyle}"
|
||||
Text="排量:" />
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontSize="26"
|
||||
FontWeight="Bold"
|
||||
Text="{Binding PPCService.CurDisplacementCc}" />
|
||||
<TextBlock
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="22"
|
||||
FontWeight="Bold"
|
||||
Foreground="LimeGreen"
|
||||
Text="cc" />
|
||||
</StackPanel>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!--<materialDesign:Card
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="3"
|
||||
|
||||
BIN
temp_ppc_hasco.cs
Normal file
BIN
temp_ppc_hasco.cs
Normal file
Binary file not shown.
Reference in New Issue
Block a user