增加干度计算的数据
This commit is contained in:
@@ -7,61 +7,62 @@
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
x:Name="MeterInstance"
|
||||
Width="140"
|
||||
Width="82"
|
||||
Height="155"
|
||||
BorderBrush="Gray"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<materialDesign:Card
|
||||
Margin="3"
|
||||
Margin="0,1"
|
||||
Background="{DynamicResource MaterialDesignLightBackground}"
|
||||
Foreground="{DynamicResource PrimaryHueLightForegroundBrush}"
|
||||
UniformCornerRadius="2">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="4*" />
|
||||
<RowDefinition Height="3*" />
|
||||
<RowDefinition Height="2*" />
|
||||
<RowDefinition Height="3*" />
|
||||
<RowDefinition Height="1.5*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Border
|
||||
Margin="3,3,3,0"
|
||||
Margin="1,3,1,0"
|
||||
Background="#404040"
|
||||
CornerRadius="3" />
|
||||
<StackPanel Margin="3,3,3,0">
|
||||
<DockPanel Margin="3">
|
||||
<StackPanel Margin="1,3,1,0">
|
||||
<DockPanel Margin="1,3">
|
||||
<TextBlock
|
||||
Margin="1,0,1,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left"
|
||||
FontSize="20"
|
||||
FontSize="14"
|
||||
Foreground="White"
|
||||
Text="PV" />
|
||||
<TextBlock
|
||||
Margin="5,0,5,0"
|
||||
Margin="0,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="18"
|
||||
FontSize="13"
|
||||
Foreground="White"
|
||||
Text="{Binding ElementName=MeterInstance, Path=PVValue}" />
|
||||
<TextBlock
|
||||
Margin="1,0"
|
||||
Margin="0,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Right"
|
||||
FontSize="12"
|
||||
FontSize="10"
|
||||
Foreground="White"
|
||||
Text="{Binding ElementName=MeterInstance, Path=Unit}" />
|
||||
</DockPanel>
|
||||
<DockPanel Margin="3,-3,3,0">
|
||||
<DockPanel Margin="1,-3,2,0">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left"
|
||||
FontSize="20"
|
||||
FontSize="16"
|
||||
FontStyle="Italic"
|
||||
Foreground="Gold"
|
||||
Text="SV" />
|
||||
<TextBlock
|
||||
Margin="10,0,5,0"
|
||||
Margin="5,0,5,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="18"
|
||||
FontSize="16"
|
||||
Foreground="Gold"
|
||||
Text="{Binding ElementName=MeterInstance, Path=SVValue}" />
|
||||
<!--<TextBlock
|
||||
@@ -76,17 +77,24 @@
|
||||
</StackPanel>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.5*" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Margin="0,3,0,0">
|
||||
<StackPanel
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="5,3,3,0"
|
||||
Orientation="Horizontal">
|
||||
<!--
|
||||
Command="{Binding ElementName=MeterInstance, Path=AutoHandCommand}"
|
||||
CommandParameter="{Binding ElementName=MeterInstance}"
|
||||
把整个控件作为参数传递进去
|
||||
-->
|
||||
<!-- Width="40" -->
|
||||
<ToggleButton
|
||||
x:Name="ToggleBtnAutoHand"
|
||||
Width="40"
|
||||
@@ -97,7 +105,7 @@
|
||||
Style="{StaticResource MaterialDesignSwitchToggleButton}"
|
||||
ToolTip="手自动" />
|
||||
<TextBlock
|
||||
Margin="0,5,0,0"
|
||||
Margin="3,3,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="Bold"
|
||||
@@ -105,7 +113,10 @@
|
||||
Text="{Binding ElementName=MeterInstance, Path=AutoStateMsg}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Margin="3,3,3,0">
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Margin="3,3,3,0">
|
||||
<StackPanel.Resources />
|
||||
<!--
|
||||
Text="{Binding ElementName=MeterInstance, Path=AutoStateMsg}"
|
||||
@@ -143,7 +154,10 @@
|
||||
Text="MV"
|
||||
Visibility="{Binding ElementName=MeterInstance, Path=IsHandValueShow}" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Margin="3,3,3,0">
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="3,3,3,0">
|
||||
<StackPanel.Resources />
|
||||
<!--
|
||||
Text="{Binding ElementName=MeterInstance, Path=AutoStateMsg}"
|
||||
@@ -185,13 +199,13 @@
|
||||
|
||||
<Border
|
||||
Grid.Row="2"
|
||||
Margin="3,3,3,3"
|
||||
Margin="1,2,1,2"
|
||||
Background="Gray"
|
||||
CornerRadius="3">
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="16"
|
||||
FontSize="12"
|
||||
Foreground="White"
|
||||
Text="{Binding ElementName=MeterInstance, Path=MeterName}" />
|
||||
</Border>
|
||||
|
||||
135
CapMachine.Wpf/PPCalculation/DrynessCALCHelper.cs
Normal file
135
CapMachine.Wpf/PPCalculation/DrynessCALCHelper.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.PPCalculation
|
||||
{
|
||||
/// <summary>
|
||||
/// 干燥度计算帮助类
|
||||
/// </summary>
|
||||
public static class DrynessCALCHelper
|
||||
{
|
||||
public static void GetValue()
|
||||
{
|
||||
|
||||
//var dd= DrynessREFPROP.GetDryness(67,0.3);
|
||||
|
||||
// 获取输入参数
|
||||
double P_suction = 0.3; // 吸气压力 (bar)
|
||||
double mg = 50 / 3600; // 气体制冷剂流量 (kg/h → kg/s)
|
||||
double ml = 4.5 / 3600; // 液体制冷剂流量 (kg/h → kg/s)
|
||||
double T_gas_valve = 35; // 气体回路阀前温度 (°C)
|
||||
double P_gas_valve = 15; // 气体回路阀前压力 (bar)
|
||||
double T_liq_valve = 67; // 液体制冷剂阀前温度 (°C)
|
||||
double P_liq_valve = 14.5; // 液体制冷剂阀前压力 (bar)
|
||||
double x_target = 14.5; // 目标干度
|
||||
|
||||
// 获取焓值
|
||||
double h_gas = GetEnthalpy(P_gas_valve, T_gas_valve + 273.15); // 转换为 K
|
||||
double h_liq = GetEnthalpy(P_liq_valve, T_liq_valve + 273.15); // 转换为 K
|
||||
|
||||
// 计算实际干度
|
||||
double x_actual = CalculateActualDryness(mg, ml, h_gas, h_liq, P_suction);
|
||||
|
||||
|
||||
// 计算目标液体流量
|
||||
double ml_target = CalculateTargetLiquidFlow(mg, h_gas, h_liq, P_suction, x_target);
|
||||
//lblTargetLiquidFlow.Text = $"目标液体流量: {ml_target * 3600:F2} kg/h"; // 转换为 kg/h
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用REFPROP64 获取饱和参数
|
||||
/// </summary>
|
||||
/// <param name="P"></param>
|
||||
/// <param name="Tsat"></param>
|
||||
/// <param name="h_f"></param>
|
||||
/// <param name="h_g"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private static void GetSaturationProperties(double P, out double Tsat, out double h_f, out double h_g)
|
||||
{
|
||||
StringBuilder herr = new StringBuilder(255);
|
||||
double Dl, Dv, hl, hv, sl, sv;
|
||||
int ierr;
|
||||
|
||||
// 调用 REFPROP 的 SATPdll 函数获取饱和参数
|
||||
DrynessREFPROP.SATPdll(P, 0, "P", "H", out Tsat, out Dl, out Dv, out hl, out hv, out sl, out sv, out ierr, herr, 1, 1);
|
||||
|
||||
if (ierr != 0)
|
||||
throw new Exception($"饱和状态计算失败: {herr.ToString()}");
|
||||
|
||||
h_f = hl; // 饱和液体焓 (J/kg)
|
||||
h_g = hv; // 饱和气体焓 (J/kg)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算实际干度
|
||||
/// </summary>
|
||||
/// <param name="mg"></param>
|
||||
/// <param name="ml"></param>
|
||||
/// <param name="h_gas"></param>
|
||||
/// <param name="h_liq"></param>
|
||||
/// <param name="P_suction"></param>
|
||||
/// <returns></returns>
|
||||
public static double CalculateActualDryness(double mg, double ml, double h_gas, double h_liq, double P_suction)
|
||||
{
|
||||
// 获取吸气压力下的饱和参数
|
||||
double Tsat, h_f, h_g_sat;
|
||||
GetSaturationProperties(P_suction, out Tsat, out h_f, out h_g_sat);
|
||||
|
||||
// 计算混合焓
|
||||
double h_total = (mg * h_gas + ml * h_liq) / (mg + ml);
|
||||
|
||||
// 计算干度
|
||||
return (h_total - h_f) / (h_g_sat - h_f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算目标液体流量
|
||||
/// </summary>
|
||||
/// <param name="mg"></param>
|
||||
/// <param name="h_gas"></param>
|
||||
/// <param name="h_liq"></param>
|
||||
/// <param name="P_suction"></param>
|
||||
/// <param name="x_target"></param>
|
||||
/// <returns></returns>
|
||||
public static double CalculateTargetLiquidFlow(double mg, double h_gas, double h_liq, double P_suction, double x_target)
|
||||
{
|
||||
// 获取吸气压力下的饱和参数
|
||||
double Tsat, h_f, h_g_sat;
|
||||
GetSaturationProperties(P_suction, out Tsat, out h_f, out h_g_sat);
|
||||
|
||||
// 计算目标焓
|
||||
double h_target = h_f + x_target * (h_g_sat - h_f);
|
||||
|
||||
// 解方程求目标液体流量
|
||||
return mg * (h_gas - h_target) / (h_target - h_liq);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取焓值
|
||||
/// </summary>
|
||||
/// <param name="P"></param>
|
||||
/// <param name="T"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static double GetEnthalpy(double P, double T)
|
||||
{
|
||||
StringBuilder herr = new StringBuilder(255);
|
||||
double D, Dl, Dv, h, s, u, cv;
|
||||
int ierr;
|
||||
|
||||
// 调用 REFPROP 的 TPFLSHdll 函数获取焓值
|
||||
DrynessREFPROP.TPFLSHdll(T, P, "T", "P", out D, out Dl, out Dv, out h, out s, out u, out cv, out ierr, herr, 1, 1);
|
||||
|
||||
if (ierr != 0)
|
||||
throw new Exception($"焓值计算失败: {herr.ToString()}");
|
||||
|
||||
return h; // 返回焓值 (J/kg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
81
CapMachine.Wpf/PPCalculation/DrynessREFPROP.cs
Normal file
81
CapMachine.Wpf/PPCalculation/DrynessREFPROP.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.PPCalculation
|
||||
{
|
||||
/// <summary>
|
||||
/// 干度的REFPROP 封装
|
||||
/// </summary>
|
||||
public static class DrynessREFPROP
|
||||
{
|
||||
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CharSet = CharSet.Ansi)]
|
||||
public static extern void SETPATHdll(string hpth, long hpth_length);
|
||||
|
||||
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
|
||||
public static extern void SETUPdll(int ncomp, string hFiles, string hFmix, string hrf, out long ierr, out string herr, long hFiles_length, long hFmix_length, long hrf_length, long herr_length);
|
||||
|
||||
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
|
||||
public static extern void SATPdll(double P, double x, string inputType, string outputType, out double Tsat, out double Dl, out double Dv, out double hl, out double hv, out double sl, out double sv, out int ierr, StringBuilder herr, int inputTypeLength, int outputTypeLength);
|
||||
|
||||
[DllImport(@".\PPCalculation\REFPROP\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
|
||||
//[DllImport(@".\REFPRP64.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
|
||||
public static extern void TPFLSHdll(double T, double P, string inputType1, string inputType2, out double D, out double Dl, out double Dv, out double h, out double s, out double u, out double cv, out int ierr, StringBuilder herr, int inputType1Length, int inputType2Length);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据温度和压力计算干度
|
||||
/// </summary>
|
||||
/// <param name="temperature">温度(K)</param>
|
||||
/// <param name="pressure">压力(kPa)</param>
|
||||
/// <returns>干度值(0~1)</returns>
|
||||
public static double GetDryness(double temperature, double pressure)
|
||||
{
|
||||
// 设置REFPROP路径
|
||||
SETPATHdll(@".\PPCalculation\REFPROP", 256);
|
||||
|
||||
// 设置制冷剂(以R134a为例)
|
||||
long ierr = 0;
|
||||
string herr = new string(' ', 255);
|
||||
SETUPdll(1, "R134A", "DEF", "DEF", out ierr, out herr, 255, 3, 3, 255);
|
||||
|
||||
if (ierr != 0)
|
||||
throw new Exception($"REFPROP初始化失败: {herr}");
|
||||
|
||||
// 获取饱和状态参数
|
||||
double Tsat, Dl, Dv, hl, hv, sl, sv;
|
||||
StringBuilder errMsg = new StringBuilder(255);
|
||||
SATPdll(pressure, 0, "P", "T", out Tsat, out Dl, out Dv, out hl, out hv, out sl, out sv,
|
||||
out int satIerr, errMsg, 1, 1);
|
||||
|
||||
if (satIerr != 0)
|
||||
throw new Exception($"饱和状态计算失败: {errMsg}");
|
||||
|
||||
// 获取当前状态参数
|
||||
double D, curDl, curDv, h, s, u, cv;
|
||||
StringBuilder curErrMsg = new StringBuilder(255);
|
||||
TPFLSHdll(temperature, pressure, "T", "P", out D, out curDl, out curDv, out h, out s,
|
||||
out u, out cv, out int tpIerr, curErrMsg, 1, 1);
|
||||
|
||||
if (tpIerr != 0)
|
||||
throw new Exception($"当前状态计算失败: {curErrMsg}");
|
||||
|
||||
// 计算干度
|
||||
double dryness;
|
||||
if (temperature <= Tsat) // 饱和液或湿蒸气
|
||||
{
|
||||
dryness = (h - hl) / (hv - hl);
|
||||
dryness = Math.Max(0, Math.Min(1, dryness)); // 确保干度在0-1之间
|
||||
}
|
||||
else // 过热蒸气
|
||||
{
|
||||
dryness = 1;
|
||||
}
|
||||
|
||||
return dryness;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using CapMachine.Wpf.Models;
|
||||
using CapMachine.Wpf.Models.ProModelPars;
|
||||
using CapMachine.Wpf.Models.Tag;
|
||||
using CapMachine.Wpf.Models.Tag.Cell;
|
||||
using CapMachine.Wpf.PPCalculation;
|
||||
using CapMachine.Wpf.PrismEvent;
|
||||
using HslCommunication;
|
||||
using HslCommunication.Profinet.Melsec;
|
||||
@@ -1356,7 +1357,7 @@ namespace CapMachine.Wpf.Services
|
||||
// 通讯相电流 压缩机
|
||||
TagManger.AddTag(new CapTag()
|
||||
{
|
||||
Id =47,
|
||||
Id = 47,
|
||||
Name = "通讯相电流[A]",
|
||||
NameNoUnit = "通讯相电流",
|
||||
EnName = "ComCapPhCur",
|
||||
@@ -2540,7 +2541,10 @@ namespace CapMachine.Wpf.Services
|
||||
DiagnosticsTime.Reset();
|
||||
DiagnosticsTime.Start();
|
||||
|
||||
await Task.Delay(200);
|
||||
await Task.Delay(20);
|
||||
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
@@ -2644,8 +2648,8 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
foreach (var itemBlockReadTag in TagManger.DicTags)
|
||||
{
|
||||
//需要从PLC读取的标签才算
|
||||
if (itemBlockReadTag.Value.RWInfo == RWInfo.PLCRead && TagManger.TryGetSVModel(itemBlockReadTag.Key, out MeterValueAttrCell sVModel))
|
||||
//需要控制的标签才算 才有SV
|
||||
if (itemBlockReadTag.Value.RWInfo == RWInfo.Control && TagManger.TryGetSVModel(itemBlockReadTag.Key, out MeterValueAttrCell sVModel))
|
||||
{
|
||||
//地址为空的话则下一个
|
||||
if (string.IsNullOrEmpty(sVModel!.Address)) continue;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
//ListTag = new ObservableCollection<ITag>(TagManager.DicTags.Values.ToList());
|
||||
RefreshListTag();
|
||||
|
||||
ListMeterTag = TagManager.DicTags.Values.Where(a => a.Group == "程序").OrderBy(a=>a.Id).Take(11).ToList();
|
||||
ListMeterTag = TagManager.DicTags.Values.Where(a => a.Group == "程序").OrderBy(a=>a.Id).ToList();
|
||||
|
||||
SpeedTag = TagManager.DicTags.GetValueOrDefault("转速[rpm]");
|
||||
ExPressTag = TagManager.DicTags.GetValueOrDefault("排气压力[BarA]");
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
AutoHandCommand="{Binding Source={StaticResource Proxy}, Path=Data.AutoHandCmd}"
|
||||
AutoHandState="False"
|
||||
HandValueCommand="{Binding Source={StaticResource Proxy}, Path=Data.HandValueCmd}"
|
||||
HandValueMVParameter="{Binding PVModel.EngValue}"
|
||||
HandValueMVParameter="{Binding MVModel.EngValue}"
|
||||
HandValueSVParameter="{Binding SVModel.EngValue}"
|
||||
IsEnabled="True"
|
||||
MeterName="{Binding NameNoUnit}"
|
||||
@@ -1161,7 +1161,7 @@
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<!--<Setter Property="Background" Value="Transparent" />-->
|
||||
<Setter Property="Height" Value="20" />
|
||||
<Setter Property="Height" Value="18" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ListView>
|
||||
|
||||
Reference in New Issue
Block a user