From 44215a008b0889abdb08bfa97c2d367933651c4c Mon Sep 17 00:00:00 2001
From: maqiao <625215135@qq.com>
Date: Thu, 28 Nov 2024 16:33:37 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=86=B0=E7=AE=B1=E5=8F=8A?=
=?UTF-8?q?=E5=BD=95=E5=83=8F=E6=9C=BA=E7=9B=B8=E5=85=B3=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DM_Weight/App.config | 2 +-
DM_Weight/App.xaml.cs | 2 +-
DM_Weight/DM_Weight.csproj | 2 +-
DM_Weight/Finger/FingerprintUtil.cs | 22 +-
DM_Weight/Port/PortUtil.cs | 766 +++++++++---------
.../ViewModels/FridgeOnlyWindowViewModel.cs | 160 ++--
DM_Weight/ViewModels/FridgeWindowViewModel.cs | 294 +++----
DM_Weight/ViewModels/HomeWindowViewModel.cs | 114 +--
DM_Weight/ViewModels/LoginWindowViewModel.cs | 41 +-
DM_Weight/ViewModels/MainWindowViewModel.cs | 10 +-
DM_Weight/Views/HomeWindow.xaml | 2 +-
DM_Weight/Views/LoginWindow.xaml | 4 +-
DM_Weight/util/SqlSugarHelper.cs | 1 +
13 files changed, 715 insertions(+), 705 deletions(-)
diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index 38204ac..4d847a7 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -99,7 +99,7 @@
-
+
diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs
index bc5c79a..d355a08 100644
--- a/DM_Weight/App.xaml.cs
+++ b/DM_Weight/App.xaml.cs
@@ -97,7 +97,7 @@ namespace DM_Weight
// 组态屏工具
containerRegistry.RegisterSingleton();
// 录像机
- containerRegistry.RegisterSingleton();
+ //containerRegistry.RegisterSingleton();
containerRegistry.Register();
diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj
index b35d455..c96bcf0 100644
--- a/DM_Weight/DM_Weight.csproj
+++ b/DM_Weight/DM_Weight.csproj
@@ -1,7 +1,7 @@
- WinExe
+ Exe
net6.0-windows
enable
true
diff --git a/DM_Weight/Finger/FingerprintUtil.cs b/DM_Weight/Finger/FingerprintUtil.cs
index 0aae4d8..6388b71 100644
--- a/DM_Weight/Finger/FingerprintUtil.cs
+++ b/DM_Weight/Finger/FingerprintUtil.cs
@@ -20,22 +20,22 @@ namespace DM_Weight.Finger
{
private readonly ILog logger = LogManager.GetLogger(typeof(FingerprintUtil));
- public zkemkeeper.CZKEMClass axCZKEM1; //= new zkemkeeper.CZKEMClass();
+ public zkemkeeper.CZKEMClass axCZKEM1;// = new zkemkeeper.CZKEMClass();
public bool bIsConnected = false;
- private string fingerIp = ConfigurationManager.AppSettings["fingerIp"].ToString();
+ private string fingerIp = ConfigurationManager.AppSettings["fingerIp"]?.ToString() ?? "";
private int fingerPort = 4370;
- private int machineNumber = Convert.ToInt32(ConfigurationManager.AppSettings["machineNumber"].ToString());
- private int machineType = Convert.ToInt32(ConfigurationManager.AppSettings["machineType"].ToString());
+ private int machineNumber = Convert.ToInt32(ConfigurationManager.AppSettings["machineNumber"]?.ToString() ?? "0");
+ private int machineType = Convert.ToInt32(ConfigurationManager.AppSettings["machineType"]?.ToString() ?? "0");
private readonly IEventAggregator _eventAggregator;
public FingerprintUtil(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
logger.Info($"进入构造器,开始连接指纹机");
- Task.Run(() =>
- {
+ // Task.Factory.StartNew(() =>
+ //{
ConnectionMain();
- });
+ //});
}
public void ConnectionMain()
@@ -47,7 +47,7 @@ namespace DM_Weight.Finger
logger.Info($"连接指纹机,IP:{fingerIp},端口:{fingerPort},机器号:{machineNumber},连接结果:{bIsConnected}");
if (bIsConnected)
{
- if (axCZKEM1.RegEvent(machineNumber, 65535))
+ if (axCZKEM1.RegEvent(machineNumber, 9))
{
this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
//this.axCZKEM1.OnEnrollFinger += new zkemkeeper._IZKEMEvents_OnEnrollFingerEventHandler(axCZKEM1_OnEnrollFinger);
@@ -62,7 +62,7 @@ namespace DM_Weight.Finger
Result = bIsConnected,
});
}
- catch(Exception ex)
+ catch (Exception ex)
{
logger.Info($"连接指纹机异常{ex.Message.ToString()}");
}
@@ -90,10 +90,10 @@ namespace DM_Weight.Finger
Id = iEnrollNumber,
FingerIndex = iFingerIndex
};
-
+
axCZKEM1.StartIdentify();
axCZKEM1.RefreshData(1);
-
+
logger.Info($"触发用户登记指纹事件,用户id:{iEnrollNumber}指纹索引:{iFingerIndex}登记结果:{(iActionResult == 0)}");
message.Result = (iActionResult == 0);
_eventAggregator.GetEvent().Publish(message);
diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs
index e54d8d0..d248b17 100644
--- a/DM_Weight/Port/PortUtil.cs
+++ b/DM_Weight/Port/PortUtil.cs
@@ -44,7 +44,7 @@ namespace DM_Weight.Port
public SerialPort scanCodeSerial;
// 冰箱串口
- public SerialPort fridgeSerial;
+ //public SerialPort fridgeSerial;
// 抽屉串口协议232 | 485
@@ -236,7 +236,7 @@ namespace DM_Weight.Port
logger.Info($"进行抽屉操作抽屉号【{DrawerNo}】类型【{BoardType}】库位【{string.Join(",", ColNos)}】窗口【{WindowName}】");
Operate = true;
//开始录像
- _chkFunction.HIKStartDVRRecord();
+ //_chkFunction.HIKStartDVRRecord();
logger.Info($"时间:{DateTime.Now}");
try
{
@@ -695,8 +695,8 @@ namespace DM_Weight.Port
private readonly IEventAggregator _eventAggregator;
- private CHKFunction _chkFunction;
- public PortUtil(IEventAggregator eventAggregator, CHKFunction chkFunction)
+ //private CHKFunction _chkFunction;
+ public PortUtil(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
try
@@ -733,18 +733,18 @@ namespace DM_Weight.Port
{
logger.Error("条码枪串口打开错误" + e.Message);
}
- try
- {
- string FridgePortPath = ConfigurationManager.AppSettings["FridgePortPath"];
- logger.Info($"打开冰箱串口【{FridgePortPath}】");
- fridgeSerial = new SerialPort(FridgePortPath, 9600, Parity.None, 8);
- fridgeSerial.Open();
- logger.Info($"冰箱串口打开结果【{fridgeSerial.IsOpen}】");
- }
- catch (Exception e)
- {
- logger.Error("冰箱串口打开错误" + e.Message);
- }
+ //try
+ //{
+ // string FridgePortPath = ConfigurationManager.AppSettings["FridgePortPath"];
+ // logger.Info($"打开冰箱串口【{FridgePortPath}】");
+ // fridgeSerial = new SerialPort(FridgePortPath, 9600, Parity.None, 8);
+ // fridgeSerial.Open();
+ // logger.Info($"冰箱串口打开结果【{fridgeSerial.IsOpen}】");
+ //}
+ //catch (Exception e)
+ //{
+ // logger.Error("冰箱串口打开错误" + e.Message);
+ //}
if (_canBusExsit)
{
try
@@ -761,7 +761,7 @@ namespace DM_Weight.Port
}
}
- _chkFunction = chkFunction;
+ //_chkFunction = chkFunction;
}
@@ -1546,385 +1546,385 @@ namespace DM_Weight.Port
}
#endregion
- ///
- /// 冰箱使能
- ///
- ///
- public async Task FridegOpen(int iIndex)
- {
- try
- {
- fridgeSerial.DiscardInBuffer();
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD4, 0x00, 0x01, 0x0C, 0xF2 };
- //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 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);
- await Task.Delay(80);
- }
- catch (Exception ex)
- {
- logger.Info($"冰箱使能发生异常:ex:{ex.Message}");
- }
- FridgeOperate = false;
- }
- ///
- /// 冰箱失能
- ///
- ///
- public async Task FridgeOff(int iIndex)
- {
- try
- {
- fridgeSerial.DiscardInBuffer();
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD4, 0x00, 0x00, 0xCD, 0x32 };
- //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 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);
- await Task.Delay(80);
- }
- catch (Exception ex)
- {
- logger.Info($"冰箱失能发生异常:ex:{ex.Message}");
- }
- FridgeOperate = false;
- }
- ///
- /// 冰箱报警使能
- ///
- ///
- public async Task FridgeAlarmOn(int iIndex)
- {
- try
- {
- fridgeSerial.DiscardInBuffer();
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD5, 0x00, 0x01, 0x5D, 0x32 };
- //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 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);
- await Task.Delay(80);
- }
- catch (Exception ex)
- {
- logger.Info($"冰箱报警使能发生异常:ex:{ex.Message}");
- }
- FridgeOperate = false;
+ /////
+ ///// 冰箱使能
+ /////
+ /////
+ //public async Task FridegOpen(int iIndex)
+ //{
+ // try
+ // {
+ // fridgeSerial.DiscardInBuffer();
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD4, 0x00, 0x01, 0x0C, 0xF2 };
+ // //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 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);
+ // await Task.Delay(80);
+ // }
+ // catch (Exception ex)
+ // {
+ // logger.Info($"冰箱使能发生异常:ex:{ex.Message}");
+ // }
+ // FridgeOperate = false;
+ //}
+ /////
+ ///// 冰箱失能
+ /////
+ /////
+ //public async Task FridgeOff(int iIndex)
+ //{
+ // try
+ // {
+ // fridgeSerial.DiscardInBuffer();
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD4, 0x00, 0x00, 0xCD, 0x32 };
+ // //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD4, 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);
+ // await Task.Delay(80);
+ // }
+ // catch (Exception ex)
+ // {
+ // logger.Info($"冰箱失能发生异常:ex:{ex.Message}");
+ // }
+ // FridgeOperate = false;
+ //}
+ /////
+ ///// 冰箱报警使能
+ /////
+ /////
+ //public async Task FridgeAlarmOn(int iIndex)
+ //{
+ // try
+ // {
+ // fridgeSerial.DiscardInBuffer();
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD5, 0x00, 0x01, 0x5D, 0x32 };
+ // //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 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);
+ // await Task.Delay(80);
+ // }
+ // catch (Exception ex)
+ // {
+ // logger.Info($"冰箱报警使能发生异常:ex:{ex.Message}");
+ // }
+ // FridgeOperate = false;
- }
+ //}
- ///
- /// 冰箱报警失能
- ///
- ///
- public async Task FridgeAlarmOff(int iIndex)
- {
- try
- {
- fridgeSerial.DiscardInBuffer();
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD5, 0x00, 0x00, 0x9C, 0xF2 };
- //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x00 };
- ////获取数组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);
- await Task.Delay(80);
- }
- catch (Exception ex)
- {
- logger.Info($"冰箱报警失能发生异常:ex:{ex.Message}");
- }
- FridgeOperate = false;
- }
- ///
- /// 冰箱温度设定最小
- ///
- ///
- public async Task FridgeMinSetting(float min, int iIndex)
- {
- try
- {
+ /////
+ ///// 冰箱报警失能
+ /////
+ /////
+ //public async Task FridgeAlarmOff(int iIndex)
+ //{
+ // try
+ // {
+ // fridgeSerial.DiscardInBuffer();
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xD5, 0x00, 0x00, 0x9C, 0xF2 };
+ // //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xD5, 0x00, 0x00 };
+ // ////获取数组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);
+ // await Task.Delay(80);
+ // }
+ // catch (Exception ex)
+ // {
+ // logger.Info($"冰箱报警失能发生异常:ex:{ex.Message}");
+ // }
+ // FridgeOperate = false;
+ //}
+ /////
+ ///// 冰箱温度设定最小
+ /////
+ /////
+ //public async Task FridgeMinSetting(float min, int iIndex)
+ //{
+ // try
+ // {
- int iMix = Convert.ToInt32(min * 10);
- fridgeSerial.DiscardInBuffer();
- //byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB };
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] bufferMin = new byte[] { bAddress, 0x06, 0x10, 0xC9, 0x00, (byte)(iMix & 0xff) };
- //获取数组CRC校验码
- byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMin);
- //Array.Reverse(byteDate);
- int dataLength = bufferMin.Length;
- Array.Resize(ref bufferMin, dataLength + byteDate.Length);
- for (int i = 0; i < byteDate.Length; i++)
- {
- bufferMin[dataLength + i] = byteDate[i];
- }
- logger.Info($"冰箱温度设定Min:【{Convert.ToHexString(bufferMin)}】");
- fridgeSerial.Write(bufferMin, 0, 8);
- }
- catch (Exception ex)
- {
- logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
- }
- }
- ///
- /// 冰箱温度设定最大
- ///
- ///
- public async Task FridgeMaxSetting(float max, int iIndex)
- {
- try
- {
- int iMax = Convert.ToInt32(max * 10);
- fridgeSerial.DiscardInBuffer();
- //byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB };
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] bufferMax = new byte[] { bAddress, 0x06, 0x10, 0xC8, 0x00, (byte)(iMax & 0xff) };
- //获取数组CRC校验码
- byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMax);
- //Array.Reverse(byteDate);
- int dataLength = bufferMax.Length;
- Array.Resize(ref bufferMax, dataLength + byteDate.Length);
- for (int i = 0; i < byteDate.Length; i++)
- {
- bufferMax[dataLength + i] = byteDate[i];
- }
- logger.Info($"冰箱温度设定Max:【{Convert.ToHexString(bufferMax)}】");
- fridgeSerial.Write(bufferMax, 0, 8);
- }
- catch (Exception ex)
- {
- logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
- }
- }
- ///
- /// 获取冰箱温度
- ///
- ///
- public async Task GetFridgeTemperature(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, 0x10, 0x02, 0x00, 0x01, 0x21, 0x0A };
- //byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01 };
+ // int iMix = Convert.ToInt32(min * 10);
+ // fridgeSerial.DiscardInBuffer();
+ // //byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB };
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] bufferMin = new byte[] { bAddress, 0x06, 0x10, 0xC9, 0x00, (byte)(iMix & 0xff) };
+ // //获取数组CRC校验码
+ // byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMin);
+ // //Array.Reverse(byteDate);
+ // int dataLength = bufferMin.Length;
+ // Array.Resize(ref bufferMin, dataLength + byteDate.Length);
+ // for (int i = 0; i < byteDate.Length; i++)
+ // {
+ // bufferMin[dataLength + i] = byteDate[i];
+ // }
+ // logger.Info($"冰箱温度设定Min:【{Convert.ToHexString(bufferMin)}】");
+ // fridgeSerial.Write(bufferMin, 0, 8);
+ // }
+ // catch (Exception ex)
+ // {
+ // logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
+ // }
+ //}
+ /////
+ ///// 冰箱温度设定最大
+ /////
+ /////
+ //public async Task FridgeMaxSetting(float max, int iIndex)
+ //{
+ // try
+ // {
+ // int iMax = Convert.ToInt32(max * 10);
+ // fridgeSerial.DiscardInBuffer();
+ // //byte[] bufferMin = new byte[] { 0x01, 0x06, 0x10, 0xC9, 0x00, 0x15, 0x9C, 0xFB };
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] bufferMax = new byte[] { bAddress, 0x06, 0x10, 0xC8, 0x00, (byte)(iMax & 0xff) };
+ // //获取数组CRC校验码
+ // byte[] byteDate = CRC16MODBUS.CrcModBus(bufferMax);
+ // //Array.Reverse(byteDate);
+ // int dataLength = bufferMax.Length;
+ // Array.Resize(ref bufferMax, dataLength + byteDate.Length);
+ // for (int i = 0; i < byteDate.Length; i++)
+ // {
+ // bufferMax[dataLength + i] = byteDate[i];
+ // }
+ // logger.Info($"冰箱温度设定Max:【{Convert.ToHexString(bufferMax)}】");
+ // fridgeSerial.Write(bufferMax, 0, 8);
+ // }
+ // catch (Exception ex)
+ // {
+ // logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
+ // }
+ //}
+ /////
+ ///// 获取冰箱温度
+ /////
+ /////
+ //public async Task GetFridgeTemperature(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, 0x10, 0x02, 0x00, 0x01, 0x21, 0x0A };
+ // //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];
- //}
+ // ////获取数组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);
+ // logger.Info($"获取冰箱温度【{Convert.ToHexString(buffer)}】");
+ // fridgeSerial.Write(buffer, 0, 8);
- byte[] retByte = await GetBufferByPort(fridgeSerial, 7);
+ // byte[] retByte = await GetBufferByPort(fridgeSerial, 7);
- logger.Info($"获取冰箱温度返回【{Convert.ToHexString(retByte)}】");
+ // 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)
- {
+ // 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;
- }
- ///
- /// 设置冰箱温度
- ///
- ///
- public async Task SetFridgeTemperature(float temperature, int iIndex)
- {
- int tpt = (int)temperature * 10;
- byte Temperature = (byte)(tpt & 0xff);
- try
- {
- //if (!FridgeOperate)
- {
- fridgeSerial.DiscardInBuffer();
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- //byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01, 0x21,0x0A };
- byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0x02, 0x00, (byte)Temperature };
+ // logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
+ // }
+ // return temperature;
+ //}
+ /////
+ ///// 设置冰箱温度
+ /////
+ /////
+ //public async Task SetFridgeTemperature(float temperature, int iIndex)
+ //{
+ // int tpt = (int)temperature * 10;
+ // byte Temperature = (byte)(tpt & 0xff);
+ // try
+ // {
+ // //if (!FridgeOperate)
+ // {
+ // fridgeSerial.DiscardInBuffer();
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // //byte[] buffer = new byte[] { 0x01, 0x03, 0x10, 0x02, 0x00, 0x01, 0x21,0x0A };
+ // byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0x02, 0x00, (byte)Temperature };
- //获取数组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);
+ // //获取数组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);
- await GetBufferByPort(fridgeSerial, 8);
- }
- }
- catch (Exception ex)
- {
+ // await GetBufferByPort(fridgeSerial, 8);
+ // }
+ // }
+ // catch (Exception ex)
+ // {
- logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
- }
- return temperature;
- }
- ///
- /// 冰箱延迟报警
- ///
- ///
- public async Task FridgeDelayWarm(int iIndex)
- {
- try
- {
- //if (!FridgeOperate)
- {
- fridgeSerial.DiscardInBuffer();
- byte bAddress;
- if (iIndex == 1)
- {
- bAddress = 0x01;
- }
- else
- {
- bAddress = 0x02;
- }
- byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xCD, 0x00, 0x01, 0xDD, 0x35 };
- //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xCD, 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);
- }
- }
- catch (Exception ex)
- {
+ // logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
+ // }
+ // return temperature;
+ //}
+ /////
+ ///// 冰箱延迟报警
+ /////
+ /////
+ //public async Task FridgeDelayWarm(int iIndex)
+ //{
+ // try
+ // {
+ // //if (!FridgeOperate)
+ // {
+ // fridgeSerial.DiscardInBuffer();
+ // byte bAddress;
+ // if (iIndex == 1)
+ // {
+ // bAddress = 0x01;
+ // }
+ // else
+ // {
+ // bAddress = 0x02;
+ // }
+ // byte[] buffer = new byte[] { bAddress, 0x06, 0x10, 0xCD, 0x00, 0x01, 0xDD, 0x35 };
+ // //byte[] buffer = new byte[] { 0x01, 0x06, 0x10, 0xCD, 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);
+ // }
+ // }
+ // catch (Exception ex)
+ // {
- logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
- }
- //FridgeOperate = false;
- }
+ // logger.Info($"获取冰箱温度发生异常:ex:{ex.Message}");
+ // }
+ // //FridgeOperate = false;
+ //}
#endregion
}
diff --git a/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs b/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs
index 1fa7beb..899dfa3 100644
--- a/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs
+++ b/DM_Weight/ViewModels/FridgeOnlyWindowViewModel.cs
@@ -92,94 +92,94 @@ namespace DM_Weight.ViewModels
///
/// 保存按钮
///
- public DelegateCommand SaveCommand { get => new DelegateCommand(SaveAction, () => !IsInvalid); }
+ //public DelegateCommand SaveCommand { get => new DelegateCommand(SaveAction, () => !IsInvalid); }
public bool KeepAlive => false;
- private async void SaveAction()
- {
- try
- {
- _portUtil.FridgeOperate = true;
+ //private async void SaveAction()
+ //{
+ // try
+ // {
+ // _portUtil.FridgeOperate = true;
- //设置温度值验证不通过则直接返回不保存
- //获取冰箱温度
- //if (_fridgeState != _defaultLoginMode.Equals(1))
- //{
- // ConfigurationManager.RefreshSection("FridgeState");
- //发送冰箱使能/失能指令
- if (_fridgeState)
- {
- await _portUtil.FridgeOff(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("FridgeState", "0");
- }
- else
- {
- await _portUtil.FridegOpen(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("FridgeState", "1");
- }
- //发送警报使能/失能指令
- if (_alarmState)
- {
- await _portUtil.FridgeAlarmOff(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("AlarmState", "0");
- }
- else
- {
- await _portUtil.FridgeAlarmOn(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("AlarmState", "1");
- }
- //设定冰箱1温度区间
- string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
- string[] newRange = TemperatureRange.Split('-');
- if (range.Length >= 2)
- {
- bool bMix = float.TryParse(range[0], out float Min);
- bool bMax = float.TryParse(range[1], out float Max);
+ // //设置温度值验证不通过则直接返回不保存
+ // //获取冰箱温度
+ // //if (_fridgeState != _defaultLoginMode.Equals(1))
+ // //{
+ // // ConfigurationManager.RefreshSection("FridgeState");
+ // //发送冰箱使能/失能指令
+ // if (_fridgeState)
+ // {
+ // await _portUtil.FridgeOff(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("FridgeState", "0");
+ // }
+ // else
+ // {
+ // await _portUtil.FridegOpen(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("FridgeState", "1");
+ // }
+ // //发送警报使能/失能指令
+ // if (_alarmState)
+ // {
+ // await _portUtil.FridgeAlarmOff(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("AlarmState", "0");
+ // }
+ // else
+ // {
+ // await _portUtil.FridgeAlarmOn(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("AlarmState", "1");
+ // }
+ // //设定冰箱1温度区间
+ // string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
+ // string[] newRange = TemperatureRange.Split('-');
+ // if (range.Length >= 2)
+ // {
+ // bool bMix = float.TryParse(range[0], out float Min);
+ // bool bMax = float.TryParse(range[1], out float Max);
- if (bMix && bMax)
- {
- if (Min != Convert.ToSingle(newRange[0]))
- {
- //设定冰箱温度最小值
- await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]), 1);
- Thread.Sleep(100);
- }
- if (Max != Convert.ToSingle(newRange[1]))
- {
- Thread.Sleep(100);
- //设定冰箱温度最大值
- await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]), 1);
- Thread.Sleep(100);
- }
- }
- }
+ // if (bMix && bMax)
+ // {
+ // if (Min != Convert.ToSingle(newRange[0]))
+ // {
+ // //设定冰箱温度最小值
+ // await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]), 1);
+ // Thread.Sleep(100);
+ // }
+ // if (Max != Convert.ToSingle(newRange[1]))
+ // {
+ // Thread.Sleep(100);
+ // //设定冰箱温度最大值
+ // await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]), 1);
+ // Thread.Sleep(100);
+ // }
+ // }
+ // }
- _portUtil.FridgeOperate = false;
- AlertMsg alertMsg = new AlertMsg
- {
- Message = $"保存成功",
- Type = MsgType.SUCCESS
- };
- _eventAggregator.GetEvent().Publish(alertMsg);
- }
- catch (Exception ex)
- {
+ // _portUtil.FridgeOperate = false;
+ // AlertMsg alertMsg = new AlertMsg
+ // {
+ // Message = $"保存成功",
+ // Type = MsgType.SUCCESS
+ // };
+ // _eventAggregator.GetEvent().Publish(alertMsg);
+ // }
+ // catch (Exception ex)
+ // {
- AlertMsg alertMsg = new AlertMsg
- {
- Message = $"保存异常{ex.ToString}",
- Type = MsgType.ERROR
- };
- _eventAggregator.GetEvent().Publish(alertMsg);
- _portUtil.FridgeOperate = false;
- }
- }
+ // AlertMsg alertMsg = new AlertMsg
+ // {
+ // Message = $"保存异常{ex.ToString}",
+ // Type = MsgType.ERROR
+ // };
+ // _eventAggregator.GetEvent().Publish(alertMsg);
+ // _portUtil.FridgeOperate = false;
+ // }
+ //}
//手动实现调用配置的逻辑 规避修改配置文件后不起作用的问题
public int ReadAppSetting(string key)
{
diff --git a/DM_Weight/ViewModels/FridgeWindowViewModel.cs b/DM_Weight/ViewModels/FridgeWindowViewModel.cs
index 8e2f4f4..8930ef0 100644
--- a/DM_Weight/ViewModels/FridgeWindowViewModel.cs
+++ b/DM_Weight/ViewModels/FridgeWindowViewModel.cs
@@ -121,167 +121,167 @@ namespace DM_Weight.ViewModels
///
/// 保存按钮
///
- public DelegateCommand SaveCommand { get => new DelegateCommand(SaveAction, () => !IsInvalid); }
+ //public DelegateCommand SaveCommand { get => new DelegateCommand(SaveAction, () => !IsInvalid); }
public bool KeepAlive => false;
- private async void SaveAction()
- {
- try
- {
- _portUtil.FridgeOperate = true;
+ //private async void SaveAction()
+ //{
+ // try
+ // {
+ // _portUtil.FridgeOperate = true;
- //设置温度值验证不通过则直接返回不保存
- //获取冰箱温度
- //if (_fridgeState != _defaultLoginMode.Equals(1))
- //{
- // ConfigurationManager.RefreshSection("FridgeState");
- //发送冰箱使能/失能指令
- if (_fridgeState)
- {
- await _portUtil.FridgeOff(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("FridgeState", "0");
- }
- else
- {
- await _portUtil.FridegOpen(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("FridgeState", "1");
- }
+ // //设置温度值验证不通过则直接返回不保存
+ // //获取冰箱温度
+ // //if (_fridgeState != _defaultLoginMode.Equals(1))
+ // //{
+ // // ConfigurationManager.RefreshSection("FridgeState");
+ // //发送冰箱使能/失能指令
+ // if (_fridgeState)
+ // {
+ // await _portUtil.FridgeOff(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("FridgeState", "0");
+ // }
+ // else
+ // {
+ // await _portUtil.FridegOpen(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("FridgeState", "1");
+ // }
- //冰箱2 发送冰箱使能/失能指令
- if (_fridgeState2)
- {
- await _portUtil.FridgeOff(2);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("FridgeState2", "0");
- }
- else
- {
- await _portUtil.FridegOpen(2);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("FridgeState2", "1");
- }
- //}
- //温度报警设定
- //if (AlarmState != _defaultAlarmMode.Equals(1))
- //{
- //发送警报使能/失能指令
- if (_alarmState)
- {
- await _portUtil.FridgeAlarmOff(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("AlarmState", "0");
- }
- else
- {
- await _portUtil.FridgeAlarmOn(1);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("AlarmState", "1");
- }
+ // //冰箱2 发送冰箱使能/失能指令
+ // if (_fridgeState2)
+ // {
+ // await _portUtil.FridgeOff(2);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("FridgeState2", "0");
+ // }
+ // else
+ // {
+ // await _portUtil.FridegOpen(2);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("FridgeState2", "1");
+ // }
+ // //}
+ // //温度报警设定
+ // //if (AlarmState != _defaultAlarmMode.Equals(1))
+ // //{
+ // //发送警报使能/失能指令
+ // if (_alarmState)
+ // {
+ // await _portUtil.FridgeAlarmOff(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("AlarmState", "0");
+ // }
+ // else
+ // {
+ // await _portUtil.FridgeAlarmOn(1);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("AlarmState", "1");
+ // }
- //冰箱2 发送警报使能/失能指令
- if (_alarmState2)
- {
- await _portUtil.FridgeAlarmOff(2);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("AlarmState2", "0");
- }
- else
- {
- await _portUtil.FridgeAlarmOn(2);
- Thread.Sleep(100);
- CommonClass.SaveAppSetting("AlarmState2", "1");
- }
- //}
+ // //冰箱2 发送警报使能/失能指令
+ // if (_alarmState2)
+ // {
+ // await _portUtil.FridgeAlarmOff(2);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("AlarmState2", "0");
+ // }
+ // else
+ // {
+ // await _portUtil.FridgeAlarmOn(2);
+ // Thread.Sleep(100);
+ // CommonClass.SaveAppSetting("AlarmState2", "1");
+ // }
+ // //}
- //if (retTemperature != TemperatureValue)
- //{
- // //设定冰箱温度
- // await _portUtil.SetFridgeTemperature(TemperatureValue);
+ // //if (retTemperature != TemperatureValue)
+ // //{
+ // // //设定冰箱温度
+ // // await _portUtil.SetFridgeTemperature(TemperatureValue);
- // CommonClass.SaveAppSetting("temperatureValue", TemperatureValue.ToString());
- //}
- //设定冰箱1温度区间
- string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
- string[] newRange = TemperatureRange.Split('-');
- if (range.Length >= 2)
- {
- bool bMix = float.TryParse(range[0], out float Min);
- bool bMax = float.TryParse(range[1], out float Max);
+ // // CommonClass.SaveAppSetting("temperatureValue", TemperatureValue.ToString());
+ // //}
+ // //设定冰箱1温度区间
+ // string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
+ // string[] newRange = TemperatureRange.Split('-');
+ // if (range.Length >= 2)
+ // {
+ // bool bMix = float.TryParse(range[0], out float Min);
+ // bool bMax = float.TryParse(range[1], out float Max);
- if (bMix && bMax)
- {
- if (Min != Convert.ToSingle(newRange[0]))
- {
- //设定冰箱温度最小值
- await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]),1);
- Thread.Sleep(100);
- }
- if (Max != Convert.ToSingle(newRange[1]))
- {
- Thread.Sleep(100);
- //设定冰箱温度最大值
- await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]), 1);
- Thread.Sleep(100);
- }
- }
- }
+ // if (bMix && bMax)
+ // {
+ // if (Min != Convert.ToSingle(newRange[0]))
+ // {
+ // //设定冰箱温度最小值
+ // await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange[0]),1);
+ // Thread.Sleep(100);
+ // }
+ // if (Max != Convert.ToSingle(newRange[1]))
+ // {
+ // Thread.Sleep(100);
+ // //设定冰箱温度最大值
+ // await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]), 1);
+ // Thread.Sleep(100);
+ // }
+ // }
+ // }
- //设定冰箱2温度区间
- string[] range2 = ConfigurationManager.AppSettings["temperatureRange2"].Split('-');
- string[] newRange2 = TemperatureRange2.Split('-');
- if (range2.Length >= 2)
- {
- bool bMix = float.TryParse(range2[0], out float Min);
- bool bMax = float.TryParse(range2[1], out float Max);
+ // //设定冰箱2温度区间
+ // string[] range2 = ConfigurationManager.AppSettings["temperatureRange2"].Split('-');
+ // string[] newRange2 = TemperatureRange2.Split('-');
+ // if (range2.Length >= 2)
+ // {
+ // bool bMix = float.TryParse(range2[0], out float Min);
+ // bool bMax = float.TryParse(range2[1], out float Max);
- if (bMix && bMax)
- {
- if (Min != Convert.ToSingle(newRange2[0]))
- {
- //设定冰箱温度最小值
- await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0]), 2);
- Thread.Sleep(100);
- }
- if (Max != Convert.ToSingle(newRange2[1]))
- {
- Thread.Sleep(100);
- //设定冰箱温度最大值
- await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1]), 2);
- Thread.Sleep(100);
- }
- }
- }
+ // if (bMix && bMax)
+ // {
+ // if (Min != Convert.ToSingle(newRange2[0]))
+ // {
+ // //设定冰箱温度最小值
+ // await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0]), 2);
+ // Thread.Sleep(100);
+ // }
+ // if (Max != Convert.ToSingle(newRange2[1]))
+ // {
+ // Thread.Sleep(100);
+ // //设定冰箱温度最大值
+ // await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1]), 2);
+ // Thread.Sleep(100);
+ // }
+ // }
+ // }
- _portUtil.FridgeOperate = false;
- AlertMsg alertMsg = new AlertMsg
- {
- Message = $"保存成功",
- Type = MsgType.SUCCESS
- };
- _eventAggregator.GetEvent().Publish(alertMsg);
+ // _portUtil.FridgeOperate = false;
+ // AlertMsg alertMsg = new AlertMsg
+ // {
+ // Message = $"保存成功",
+ // Type = MsgType.SUCCESS
+ // };
+ // _eventAggregator.GetEvent().Publish(alertMsg);
- //_fridgeState = ReadAppSetting("FridgeState").Equals(1);
- //_defaultLoginMode = ReadAppSetting("FridgeState");
- //_defaultAlarmMode = ReadAppSetting("AlarmState");
- //_alarmState = ReadAppSetting("AlarmState").Equals(1);
- //_temperatureRange = CommonClass.ReadAppSetting("temperatureRange");
- //_temperatureValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
- }
- catch (Exception ex)
- {
+ // //_fridgeState = ReadAppSetting("FridgeState").Equals(1);
+ // //_defaultLoginMode = ReadAppSetting("FridgeState");
+ // //_defaultAlarmMode = ReadAppSetting("AlarmState");
+ // //_alarmState = ReadAppSetting("AlarmState").Equals(1);
+ // //_temperatureRange = CommonClass.ReadAppSetting("temperatureRange");
+ // //_temperatureValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
+ // }
+ // catch (Exception ex)
+ // {
- AlertMsg alertMsg = new AlertMsg
- {
- Message = $"保存异常{ex.ToString}",
- Type = MsgType.ERROR
- };
- _eventAggregator.GetEvent().Publish(alertMsg);
- _portUtil.FridgeOperate = false;
- }
- }
+ // AlertMsg alertMsg = new AlertMsg
+ // {
+ // Message = $"保存异常{ex.ToString}",
+ // Type = MsgType.ERROR
+ // };
+ // _eventAggregator.GetEvent().Publish(alertMsg);
+ // _portUtil.FridgeOperate = false;
+ // }
+ //}
public FridgeWindowViewModel()
{
diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs
index ff05062..4c08c17 100644
--- a/DM_Weight/ViewModels/HomeWindowViewModel.cs
+++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs
@@ -214,8 +214,12 @@ namespace DM_Weight.ViewModels
logger.Info($"用户【{Operator?.Nickname}】退出登录");
Operator = null;
Reviewer = null;
- _regionManager.RequestNavigate("MainRegion", "LoginWindow");
- _regionManager.RequestNavigate("MainRegion", "BeforeLogin");
+ System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+ {
+ _regionManager.RequestNavigate("MainRegion", "LoginWindow");
+ }));
+ //_regionManager.RequestNavigate("MainRegion", "BeforeLogin");
+
}
else
{
@@ -338,16 +342,16 @@ namespace DM_Weight.ViewModels
public bool Is16Drawer { get => _is16Drawer; set => SetProperty(ref _is16Drawer, value); }
public bool KeepAlive => false;
private PortUtil _portUtil;
- private CHKFunction _chkFunction;
+ //private CHKFunction _chkFunction;
IEventAggregator _eventAggregator;
- public HomeWindowViewModel(IRegionManager iRegionManager, PortUtil portUtil, IDialogService dialogService, IUnityContainer container, IEventAggregator eventAggregator, CHKFunction cHKFunction)
+ public HomeWindowViewModel(IRegionManager iRegionManager, PortUtil portUtil, IDialogService dialogService, IUnityContainer container, IEventAggregator eventAggregator)
{
_portUtil = portUtil;
_regionManager = iRegionManager;
_dialogService = dialogService;
_container = container;
this._eventAggregator = eventAggregator;
- _chkFunction = cHKFunction;
+ //_chkFunction = cHKFunction;
}
public DelegateCommand OpenFingerDialog
@@ -417,35 +421,35 @@ namespace DM_Weight.ViewModels
///
/// 获取温度信息
///
- private async void GetWD(object sender, ElapsedEventArgs e)
- {
- if (!_portUtil.FridgeOperate)
- {
- string retStr = string.Empty;
- byte[] data = null;
- float retT = await _portUtil.GetFridgeTemperature(1);
- Thread.Sleep(80);
- WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃";
- }
- }
+ //private async void GetWD(object sender, ElapsedEventArgs e)
+ //{
+ // if (!_portUtil.FridgeOperate)
+ // {
+ // string retStr = string.Empty;
+ // byte[] data = null;
+ // float retT = await _portUtil.GetFridgeTemperature(1);
+ // Thread.Sleep(80);
+ // WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃";
+ // }
+ //}
- private async void GetWD()
- {
- if (!_portUtil.FridgeOperate)
- {
- string retStr = string.Empty;
- byte[] data = null;
- float retT = await _portUtil.GetFridgeTemperature(1);
- Thread.Sleep(80);
- WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃;";
- if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) > 1)
- {
- float retTemp = await _portUtil.GetFridgeTemperature(2);
- Thread.Sleep(80);
- WD += $"{retTemp}℃";
- }
- }
- }
+ //private async void GetWD()
+ //{
+ // if (!_portUtil.FridgeOperate)
+ // {
+ // string retStr = string.Empty;
+ // byte[] data = null;
+ // float retT = await _portUtil.GetFridgeTemperature(1);
+ // Thread.Sleep(80);
+ // WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃;";
+ // if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) > 1)
+ // {
+ // float retTemp = await _portUtil.GetFridgeTemperature(2);
+ // Thread.Sleep(80);
+ // WD += $"{retTemp}℃";
+ // }
+ // }
+ //}
///
/// 将收到的返回转换成具体温度数值
///
@@ -482,11 +486,11 @@ namespace DM_Weight.ViewModels
///
/// 查看冰箱温度
///
- public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); }
- private void CheckAction()
- {
- GetWD();
- }
+ //public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); }
+ //private void CheckAction()
+ //{
+ //GetWD();
+ //}
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
@@ -550,7 +554,7 @@ namespace DM_Weight.ViewModels
if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
{
logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录");
- _chkFunction.HIKStopDVRRecord();
+ //_chkFunction.HIKStopDVRRecord();
Operator = null;
Reviewer = null;
Application.Current.Dispatcher.Invoke(() =>
@@ -577,25 +581,25 @@ namespace DM_Weight.ViewModels
//}
//#endregion
//GetWD();
- if (stopRecord > 0)
- {
- System.Timers.Timer timer = new System.Timers.Timer();
- timer.Interval = 1000;
- timer.Elapsed += (sender, e) =>
- {
+ //if (stopRecord > 0)
+ //{
+ // System.Timers.Timer timer = new System.Timers.Timer();
+ // timer.Interval = 1000;
+ // timer.Elapsed += (sender, e) =>
+ // {
- //指定时间内无人操作鼠标键盘则停止录像
- if (!_portUtil.Operate && CheckComputerFreeState.GetLastInputTime() > stopRecord)
- {
- _chkFunction.HIKStopDVRRecord();
- }
- };
- timer.Start();
- }
+ // //指定时间内无人操作鼠标键盘则停止录像
+ // if (!_portUtil.Operate && CheckComputerFreeState.GetLastInputTime() > stopRecord)
+ // {
+ // _chkFunction.HIKStopDVRRecord();
+ // }
+ // };
+ // timer.Start();
+ //}
logger.Info($"当前时间:{DateTime.Now}\r\n获取录像机的时间");
//获取录像机的时间
- _chkFunction.HIK_DVR_TIME();
- _chkFunction.HIKStartDVRRecord();
+ //_chkFunction.HIK_DVR_TIME();
+ //_chkFunction.HIKStartDVRRecord();
}
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs
index 9144f2a..2539ee5 100644
--- a/DM_Weight/ViewModels/LoginWindowViewModel.cs
+++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs
@@ -65,7 +65,7 @@ namespace DM_Weight.ViewModels
private FingerprintUtil _fingerprintUtil;
private PortUtil _portUtil;
- private CHKFunction _chkFunction;
+ //private CHKFunction _chkFunction;
public Boolean LoginBtnEnable { get { return _loginBtnEnable; } set { SetProperty(ref _loginBtnEnable, value); } }
public string Password { get { return password; } set { SetProperty(ref password, value); } }
@@ -84,17 +84,17 @@ namespace DM_Weight.ViewModels
get => _portUtil._canBusExsit && !_portUtil.canBusSerial.IsOpen;
}
- private bool _fingerMsg= CHKFunction.HKUserId>=0;
+ private bool _fingerMsg;
public bool FingerMsg
{
get => _fingerMsg;
set => SetProperty(ref _fingerMsg, value);
}
- public bool FridgePortMsg
- {
- get => !_portUtil.fridgeSerial.IsOpen;
- }
+ //public bool FridgePortMsg
+ //{
+ // get => !_portUtil.fridgeSerial.IsOpen;
+ //}
//录像机登录状态
private bool _hikMsg;
public bool HIKMsg
@@ -110,13 +110,14 @@ namespace DM_Weight.ViewModels
// _regionManager = regionManager;
// _eventAggregator = eventAggregator;
//}
- public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, CHKFunction chcFunction)
+ public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil)
{
- //_fingerprintUtil = fingerprintUtil;
+ _fingerprintUtil = fingerprintUtil;
_portUtil = portUtil;
- _chkFunction= chcFunction;
+ //_chkFunction= chcFunction;
_regionManager = regionManager;
_eventAggregator = eventAggregator;
+ _eventAggregator.GetEvent().Subscribe(LoginEvent);
}
private DelegateCommand? _loginCommand;
@@ -355,7 +356,7 @@ _exitCommand ??= new DelegateCommand(Exit);
void Exit()
{
- _chkFunction.HIKLoginOut();
+ //_chkFunction.HIKLoginOut();
Process.GetCurrentProcess().Kill();
Environment.Exit(0);
}
@@ -363,18 +364,22 @@ _exitCommand ??= new DelegateCommand(Exit);
void LoginEvent(FingerprintMsg msg)
{
logger.Info(msg.ToString());
- if (msg.Message.Equals("CONNECT"))
- {
- FingerMsg = !msg.Result;
- }
+ //if (msg.Message.Equals("CONNECT"))
+ //{
+ // FingerMsg = !msg.Result;
+ //}
if (LoginBtnEnable)
{
if (msg.Message.Equals("LOGIN"))
{
- UserList userList = SqlSugarHelper.Db.Queryable()
-
+ UserList userList = new UserList();
+ userList = SqlSugarHelper.Db.Queryable()
.Includes(u => u.Role)
- .First(u => u.Id == msg.Id);
+ .Where(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString())
+ .WithCacheIF(false).First();
+ //.First(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString());
+
+
if (userList == null)
{
@@ -441,7 +446,7 @@ _exitCommand ??= new DelegateCommand(Exit);
//接收导航传过来的参数 现在是在此处初始化了表格数据
public void OnNavigatedTo(NavigationContext navigationContext)
{
- FingerMsg = false;// !_fingerprintUtil.bIsConnected;
+ FingerMsg = !_fingerprintUtil.bIsConnected;
_eventAggregator.GetEvent().Subscribe(LoginEvent);
}
diff --git a/DM_Weight/ViewModels/MainWindowViewModel.cs b/DM_Weight/ViewModels/MainWindowViewModel.cs
index 25e24a0..fa4d1ff 100644
--- a/DM_Weight/ViewModels/MainWindowViewModel.cs
+++ b/DM_Weight/ViewModels/MainWindowViewModel.cs
@@ -60,20 +60,20 @@ namespace DM_Weight.ViewModels
// this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2);
// _screenUtil = screenUtil;
//}
- private FingerprintUtil _fingerprintUtil;
+ //private FingerprintUtil _fingerprintUtil;
IRegionManager _regionManager;
IUnityContainer _container;
- private CHKFunction _cHKFunction;
- public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, ScreenUtil screenUtil, CHKFunction cHKFunction)
+ //private CHKFunction _cHKFunction;
+ public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, ScreenUtil screenUtil)
{
//_portUtil = portUtil;
this.eventAggregator = eventAggregator;
this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2);
_screenUtil = screenUtil;
- _fingerprintUtil = fingerprintUtil;
+ //_fingerprintUtil = fingerprintUtil;
_regionManager = regionManager;
_container = container;
- _cHKFunction = cHKFunction;
+ //_cHKFunction = cHKFunction;
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
diff --git a/DM_Weight/Views/HomeWindow.xaml b/DM_Weight/Views/HomeWindow.xaml
index 5005b78..5334f82 100644
--- a/DM_Weight/Views/HomeWindow.xaml
+++ b/DM_Weight/Views/HomeWindow.xaml
@@ -123,7 +123,7 @@
-
+
diff --git a/DM_Weight/Views/LoginWindow.xaml b/DM_Weight/Views/LoginWindow.xaml
index 000a75f..9ef9f04 100644
--- a/DM_Weight/Views/LoginWindow.xaml
+++ b/DM_Weight/Views/LoginWindow.xaml
@@ -198,8 +198,8 @@
-
-
+
+
diff --git a/DM_Weight/util/SqlSugarHelper.cs b/DM_Weight/util/SqlSugarHelper.cs
index b9baf81..3a0351a 100644
--- a/DM_Weight/util/SqlSugarHelper.cs
+++ b/DM_Weight/util/SqlSugarHelper.cs
@@ -12,6 +12,7 @@ namespace DM_Weight.util
ConnectionString = ConfigurationManager.ConnectionStrings["database"].ToString(),
DbType = DbType.MySql,
IsAutoCloseConnection = true
+
},
db =>
{