From 34c6cbb69c462af6cbc71adb8467410d56ca3f36 Mon Sep 17 00:00:00 2001
From: maqiao <625215135@qq.com>
Date: Wed, 12 Mar 2025 17:47:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=86=B0=E7=AE=B1=E8=B6=85=E6=B8=A9=E5=BA=A6?=
=?UTF-8?q?=E8=8C=83=E5=9B=B4=E6=8A=A5=E8=AD=A6=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DM_Weight/App.config | 6 +-
DM_Weight/Port/PortUtil.cs | 38 +++++
.../ViewModels/FridgeOnlyWindowViewModel.cs | 14 +-
DM_Weight/ViewModels/HomeWindowViewModel.cs | 152 ++++++++++++++++--
DM_Weight/Views/FridgeOnlyWindow.xaml | 13 +-
DM_Weight/Views/HomeWindow.xaml | 2 +-
6 files changed, 205 insertions(+), 20 deletions(-)
diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index c7db2fb..25cac1e 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -37,7 +37,7 @@
-
+
@@ -76,6 +76,10 @@
+
+
+
diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs
index 4fc2252..1cea921 100644
--- a/DM_Weight/Port/PortUtil.cs
+++ b/DM_Weight/Port/PortUtil.cs
@@ -1756,6 +1756,44 @@ namespace DM_Weight.Port
}
return temperature;
}
+ //读制冷片温度
+ public async Task GetFridgeTemperature2()
+ {
+ float temperature = 0.0f;
+ try
+ {
+ fridgeSerial.DiscardInBuffer();
+ byte bAddress;
+ byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x0C, 0x00, 0x01, 0x40, 0xC9 };
+ //byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01 };
+ ////获取数组CRC校验码
+ //byte[] byteDate = CRC16MODBUS.CrcModBus(buffer);
+ ////Array.Reverse(byteDate);
+ //int dataLength = buffer.Length;
+ //Array.Resize(ref buffer, dataLength + byteDate.Length);
+ //for (int i = 0; i < byteDate.Length; i++)
+ //{
+ // buffer[dataLength + i] = byteDate[i];
+ //}
+ logger.Info($"获制冷片温度【{Convert.ToHexString(buffer)}】");
+ fridgeSerial.Write(buffer, 0, 8);
+ byte[] retByte = await GetBufferByPort(fridgeSerial, 7);
+ logger.Info($"获取制冷片温度返回【{Convert.ToHexString(retByte)}】");
+ if (retByte != null && retByte.Length >= 7)
+ {
+ var hight = retByte[3];
+ var low = retByte[4];
+ int iHight = Convert.ToInt32(hight << 8);
+ int iLow = Convert.ToInt32(retByte[4]);
+ temperature = Convert.ToSingle(iHight + iLow) / 10;
+ }
+ }
+ catch (Exception ex)
+ {
+ logger.Info($"获取制冷片温度发生异常:ex:{ex.Message}");
+ }
+ return temperature;
+ }
///
/// 设置冰箱温度
///
diff --git a/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs b/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs
index 1fa7beb..5a16251 100644
--- a/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs
+++ b/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs
@@ -30,7 +30,19 @@ namespace DM_Weight.ViewModels
//更新配置文件中冰箱温度区间
CommonClass.SaveAppSetting("temperatureRange", _temperatureRange);
}
- }
+ }
+ //温度不在范围超时时间
+ private string _outRangeTime = ConfigurationManager.AppSettings["OutRangeTime"].ToString();
+ public string OutRangeTime
+ {
+ get => _outRangeTime; set
+ {
+ SetProperty(ref _outRangeTime, value);
+ //更新配置文件中冰箱温度区间
+ CommonClass.SaveAppSetting("OutRangeTime", _outRangeTime);
+ }
+ }
+
private float defaultValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
//温度值
private float _temperatureValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs
index 68283f8..b87ddc5 100644
--- a/DM_Weight/ViewModels/HomeWindowViewModel.cs
+++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs
@@ -24,6 +24,7 @@ using Newtonsoft.Json.Linq;
using DM_Weight.msg;
using System.Threading;
using DM_Weight.Common;
+using System.Windows.Media;
namespace DM_Weight.ViewModels
{
@@ -41,7 +42,13 @@ namespace DM_Weight.ViewModels
///
private string _wd = "恒温冷藏抽屉当前温度2.8(非真实数据)";
public string WD { get => _wd; set => SetProperty(ref _wd, value); }
- System.Timers.Timer WDTimer;
+
+ private SolidColorBrush _alertColor=Brushes.White;
+ public SolidColorBrush AlertColor
+ {
+ get=> _alertColor;
+ set => SetProperty(ref _alertColor, value);
+ }
///
/// 是否有冰箱抽屉
@@ -49,6 +56,18 @@ namespace DM_Weight.ViewModels
private string hasFridge = ConfigurationManager.AppSettings["hasFridge"].ToString().Equals("1") ? "Visible" : "Collapsed";
public string HasFridge { get => hasFridge; set => SetProperty(ref hasFridge, value); }
+ //温度区间
+ private string TemperatureRange = CommonClass.ReadAppSetting("temperatureRange").ToString();
+ //温度不在区间计时器(超过配置文件中的时间后要报警)
+ public DateTime? FridgeTime { get; set; }
+ //冰箱是否异常状态:0正常,1异常
+ //public string FridgeWorkingState = ConfigurationManager.AppSettings["FridgeworkingState"].ToString();
+ //冰箱开关状态:0开,1关
+ public string FridgeState = ConfigurationManager.AppSettings["FridgeState"].ToString();
+ //冰箱渡不在区间超时时间
+ private string _outRangeTime = ConfigurationManager.AppSettings["OutRangeTime"].ToString();
+ public string OutRangeTime { get => _outRangeTime; set => SetProperty(ref _outRangeTime, value); }
+
private int loginMode = Convert.ToInt32(ConfigurationManager.AppSettings["loginMode"]?.ToString() ?? "1");
public bool MultiLogin
{
@@ -651,36 +670,141 @@ namespace DM_Weight.ViewModels
////获取录像机的时间
//_chkFunction.HIK_DVR_TIME();
//_chkFunction.HIKStartDVRRecord();
-
- new PromiseUtil().taskAsyncLoop(60000, 0, async (options, next, stop) =>
+ string[] tempRange = TemperatureRange.Split('-');
+ new PromiseUtil().taskAsyncLoop(10000, 0, async (options, next, stop) =>
{
try
{
- if (!_portUtil.FridgeOperate)
+ if (!_portUtil.FridgeOperate && FridgeState.Equals("0"))
{
string retStr = string.Empty;
byte[] data = null;
float retT = await _portUtil.GetFridgeTemperature(1);
Thread.Sleep(80);
- WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT), 2)}℃";
+ WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT), 2)}℃;";
logger.Info(WD);
- //if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) > 1)
- //{
- // float retTemp = await _portUtil.GetFridgeTemperature(2);
- // Thread.Sleep(80);
- // WD += $"{retTemp}℃";
- //}
- if (IsLeave)
+ if (tempRange != null && tempRange.Count() >= 2)
{
- stop();
+ if (retT < Convert.ToSingle(tempRange[0]) || retT > Convert.ToSingle(tempRange[1]))
+ {
+ //查询制冷片温度
+ float retT2 = await _portUtil.GetFridgeTemperature2();
+ if (retT2 > 65)
+ {
+ if (!FridgeState.Equals("1"))
+ {
+ //停掉冰箱
+ await _portUtil.FridgeOff(1);
+ CommonClass.SaveAppSetting("FridgeState", "1");
+ AlertMsg alertMsg = new AlertMsg
+ {
+ Message = $"冰箱制冷片温度超过65度,已关闭冰箱制冷功能!!!",
+ Type = MsgType.ERROR
+ };
+ _eventAggregator.GetEvent().Publish(alertMsg);
+ }
+ logger.Info($"制冷片温度超过65度");
+ Thread.Sleep(100);
+ //给出提示
+ WD += "冰箱温度异常,已关闭冰箱制冷功能";
+ AlertColor=Brushes.Red;
+ FridgeTime = null;
+ stop();
+ }
+ else
+ {
+ if (FridgeTime == null)
+ {
+ FridgeTime = DateTime.Now;
+ //温度不在范围,但没有超过时间
+ if (IsLeave)
+ {
+ FridgeTime = null;
+ stop();
+ }
+ else
+ {
+ next();
+ }
+ }
+ else
+ {
+ if ((DateTime.Now - FridgeTime.Value).TotalMinutes > Convert.ToInt32(OutRangeTime))
+ {
+ logger.Info($"冰箱温度不在范围内,超过{OutRangeTime}分钟");
+ //停掉冰箱
+ await _portUtil.FridgeOff(1);
+ Thread.Sleep(100);
+ CommonClass.SaveAppSetting("FridgeState", "0");
+ //给出提示
+ WD += "冰箱温度异常,已关闭冰箱制冷功能;";
+ AlertColor = Brushes.Red;
+ FridgeState = "1";
+ CommonClass.SaveAppSetting("FridgeState", "1");
+ AlertMsg alertMsg = new AlertMsg
+ {
+ Message = $"冰箱温度异常,已关闭冰箱制冷功能!!!",
+ Type = MsgType.ERROR
+ };
+ _eventAggregator.GetEvent().Publish(alertMsg);
+ FridgeTime = null;
+ stop();
+ }
+ else
+ {
+ //温度不在范围,但没有超过时间
+ if (IsLeave)
+ {
+ FridgeTime = null;
+ stop();
+ }
+ else
+ {
+ next();
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if (IsLeave)
+ {
+ FridgeTime = null;
+ stop();
+ }
+ else
+ {
+ next();
+ }
+ }
}
else
{
- next();
+ logger.Info($"获取冰箱温度范围有误{TemperatureRange}");
+
+ //if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) > 1)
+ //{
+ // float retTemp = await _portUtil.GetFridgeTemperature(2);
+ // Thread.Sleep(80);
+ // WD += $"{retTemp}℃";
+ //}
+ if (IsLeave)
+ {
+ FridgeTime = null;
+ stop();
+ }
+ else
+ {
+ next();
+ }
}
}
else
{
+ WD = $"恒温冷藏抽屉串口关闭或冰箱制冷异常制冷关闭!!!";
+ AlertColor = Brushes.Red;
+ FridgeTime = null;
stop();
}
}
diff --git a/DM_Weight/Views/FridgeOnlyWindow.xaml b/DM_Weight/Views/FridgeOnlyWindow.xaml
index d432c28..0c6657a 100644
--- a/DM_Weight/Views/FridgeOnlyWindow.xaml
+++ b/DM_Weight/Views/FridgeOnlyWindow.xaml
@@ -23,7 +23,8 @@
-
+
+
@@ -58,8 +59,14 @@
ToolTip="报警状态"
Content="打开"
materialDesign:ToggleButtonAssist.OnContent="关闭" />
-
-
+
+
+
+
diff --git a/DM_Weight/Views/HomeWindow.xaml b/DM_Weight/Views/HomeWindow.xaml
index 56c76c7..b0f9127 100644
--- a/DM_Weight/Views/HomeWindow.xaml
+++ b/DM_Weight/Views/HomeWindow.xaml
@@ -123,7 +123,7 @@
-
+