From f885bc52f15e33aac2e9c7f22fd85934a3959380 Mon Sep 17 00:00:00 2001
From: maqiao <625215135@qq.com>
Date: Tue, 28 Oct 2025 15:45:13 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B9=98=E4=B9=A1=E6=8D=A2?=
=?UTF-8?q?=E6=96=B0=E5=86=B7=E8=97=8F=E6=8A=BD=E5=B1=89=E6=9F=A5=E6=B8=A9?=
=?UTF-8?q?=E5=BA=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DM_Weight/App.config | 4 +-
DM_Weight/Port/PortUtil.cs | 60 ++++++++++++++++++++-
DM_Weight/ViewModels/HomeWindowViewModel.cs | 4 +-
3 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index 3cbbe58..f7ff196 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -3,7 +3,7 @@
-
+
-
+
diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs
index 1cea921..13f3e1b 100644
--- a/DM_Weight/Port/PortUtil.cs
+++ b/DM_Weight/Port/PortUtil.cs
@@ -1883,7 +1883,65 @@ namespace DM_Weight.Port
}
//FridgeOperate = false;
}
- #endregion
+ #endregion
+
+ #region 新冰箱抽屉获取温度
+
+ ///
+ /// 获取冰箱温度
+ ///
+ ///
+ public async Task GetFridgeTemperatureForNew(int iIndex)
+ {
+ float temperature = 0.0f;
+ try
+ {
+ fridgeSerial.DiscardInBuffer();
+ byte bAddress;
+ if (iIndex == 1)
+ {
+ bAddress = 0x01;
+ }
+ else
+ {
+ bAddress = 0x02;
+ }
+ byte[] buffer = new byte[] { bAddress, 0x03, 0x00, 0x03, 0x02 };
+
+ //获取数组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;
+ }
+ #endregion
}
}
diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs
index 30bf3c2..230225a 100644
--- a/DM_Weight/ViewModels/HomeWindowViewModel.cs
+++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs
@@ -459,7 +459,7 @@ namespace DM_Weight.ViewModels
{
string retStr = string.Empty;
byte[] data = null;
- float retT = await _portUtil.GetFridgeTemperature(1);
+ float retT = await _portUtil.GetFridgeTemperatureForNew(1);
Thread.Sleep(80);
WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT), 2)}℃";
logger.Info(WD);
@@ -706,7 +706,7 @@ namespace DM_Weight.ViewModels
{
string retStr = string.Empty;
byte[] data = null;
- float retT = await _portUtil.GetFridgeTemperature(1);
+ float retT = await _portUtil.GetFridgeTemperatureForNew(1);
Thread.Sleep(80);
WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT), 2)}℃;";
AlertColor = Brushes.White;