diff --git a/CapMachine.Wpf/App.xaml.cs b/CapMachine.Wpf/App.xaml.cs index f0fba45..ada0958 100644 --- a/CapMachine.Wpf/App.xaml.cs +++ b/CapMachine.Wpf/App.xaml.cs @@ -136,7 +136,7 @@ namespace CapMachine.Wpf containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); - //containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); diff --git a/CapMachine.Wpf/CapMachine.Wpf.csproj b/CapMachine.Wpf/CapMachine.Wpf.csproj index 98c763e..f053d38 100644 --- a/CapMachine.Wpf/CapMachine.Wpf.csproj +++ b/CapMachine.Wpf/CapMachine.Wpf.csproj @@ -1,7 +1,7 @@  - WinExe + Exe net6.0-windows enable enable diff --git a/CapMachine.Wpf/Services/PPCService.cs b/CapMachine.Wpf/Services/PPCService.cs index 1a11fcf..b5551f5 100644 --- a/CapMachine.Wpf/Services/PPCService.cs +++ b/CapMachine.Wpf/Services/PPCService.cs @@ -24,6 +24,7 @@ namespace CapMachine.Wpf.Services /// 计算扫描 Task /// private static Task CalcTask { get; set; } + private static int _scanLoopStarted; public ConfigService ConfigService { get; } private IEventAggregator _EventAggregator { get; set; } @@ -266,6 +267,11 @@ namespace CapMachine.Wpf.Services /// private void RtScanDeviceStart() { + if (System.Threading.Interlocked.CompareExchange(ref _scanLoopStarted, 1, 0) != 0) + { + return; + } + CalcTask = Task.Run(async () => { while (RtCalcEnable) @@ -332,7 +338,7 @@ namespace CapMachine.Wpf.Services } else if (_superheatSubcoolCalculator.TryCalculateSuperheatK(InhPressTag.EngPvValue, InhTempTag.EngPvValue, out var superheatValue, out var superheatErr)) { - Superheat.EngPvValue = superheatValue; + Superheat.EngPvValue =Math.Abs(superheatValue) ; updated = true; } else @@ -348,7 +354,7 @@ namespace CapMachine.Wpf.Services } else if (_superheatSubcoolCalculator.TryCalculateSubcoolK(TxvFrPressTag.EngPvValue, TxvFrTempTag.EngPvValue, out var subcoolValue, out var subcoolErr)) { - Subcool.EngPvValue = subcoolValue; + Subcool.EngPvValue = Math.Abs(subcoolValue); updated = true; } else diff --git a/CapMachine.Wpf/Services/PPCSuperheatSubcoolCalculationInput.cs b/CapMachine.Wpf/Services/PPCSuperheatSubcoolCalculationInput.cs index c09b666..8dfd8d0 100644 --- a/CapMachine.Wpf/Services/PPCSuperheatSubcoolCalculationInput.cs +++ b/CapMachine.Wpf/Services/PPCSuperheatSubcoolCalculationInput.cs @@ -239,7 +239,7 @@ namespace CapMachine.Wpf.Services /// private sealed class LocalCalculationSupport : IPPCCalculationSupport { - private static readonly object _refpropLock = new object(); + private static readonly object _refpropLock = RefpropGlobalSync.SyncRoot; private static volatile bool _rpInitialized; public bool EnsureRefpropInitialized(out string error) diff --git a/CapMachine.Wpf/Services/PPCThermodynamicSixResultsCalculationInput.cs b/CapMachine.Wpf/Services/PPCThermodynamicSixResultsCalculationInput.cs index ffe7411..0352b9f 100644 --- a/CapMachine.Wpf/Services/PPCThermodynamicSixResultsCalculationInput.cs +++ b/CapMachine.Wpf/Services/PPCThermodynamicSixResultsCalculationInput.cs @@ -1064,7 +1064,7 @@ namespace CapMachine.Wpf.Services /// private sealed class LocalCalculationSupport : IPPCCalculationSupport { - private static readonly object _refpropLock = new object(); + private static readonly object _refpropLock = RefpropGlobalSync.SyncRoot; private static volatile bool _rpInitialized; public bool EnsureRefpropInitialized(out string error) diff --git a/CapMachine.Wpf/Services/RefpropGlobalSync.cs b/CapMachine.Wpf/Services/RefpropGlobalSync.cs new file mode 100644 index 0000000..aa055a0 --- /dev/null +++ b/CapMachine.Wpf/Services/RefpropGlobalSync.cs @@ -0,0 +1,17 @@ +namespace CapMachine.Wpf.Services +{ + /// + /// REFPROP 全局同步对象。 + /// + /// + /// REFPROP 不是线程安全组件,所有底层 DLL 调用必须串行进入。 + /// 该类提供进程内统一锁,供不同计算器共享,避免并发调用导致的瞬时异常结果。 + /// + internal static class RefpropGlobalSync + { + /// + /// REFPROP 全局互斥锁。 + /// + internal static readonly object SyncRoot = new object(); + } +}