From e5f3877af532cb07b0c0c67145acaff651f6e3b2 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Thu, 27 Jun 2024 16:49:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2=E4=B8=AD?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=8C=89=E9=92=AE=E6=98=BE=E7=A4=BA=E5=86=B0?= =?UTF-8?q?=E7=AE=B1=E6=B8=A9=E5=BA=A6=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E5=86=B0=E7=AE=B1=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.config | 8 ++ DM_Weight/Common/TemperatureRangeRule.cs | 2 +- DM_Weight/Port/PortUtil.cs | 2 +- DM_Weight/ViewModels/FridgeWindowViewModel.cs | 86 ++++++++++++++++++- DM_Weight/ViewModels/HomeWindowViewModel.cs | 45 ++++++---- DM_Weight/Views/FridgeWindow.xaml | 31 ++++++- DM_Weight/Views/HomeWindow.xaml | 3 +- 7 files changed, 155 insertions(+), 22 deletions(-) diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 2e1a4a2..2b61571 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -70,6 +70,14 @@ + + + + + + + + diff --git a/DM_Weight/Common/TemperatureRangeRule.cs b/DM_Weight/Common/TemperatureRangeRule.cs index 1ebe4bd..111c8b2 100644 --- a/DM_Weight/Common/TemperatureRangeRule.cs +++ b/DM_Weight/Common/TemperatureRangeRule.cs @@ -27,7 +27,7 @@ namespace DM_Weight.Common bool bERange = int.TryParse(rang[1], out int eRange); if (bSRange && bERange) { - if (sRange < 2 || eRange > 8) + if ((sRange < 2 || eRange > 8||sRange>8||eRange<2)) { tips = "温度区间设置2-8度,请检查输入"; return new ValidationResult(flag, tips); diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs index 14a6d27..3180486 100644 --- a/DM_Weight/Port/PortUtil.cs +++ b/DM_Weight/Port/PortUtil.cs @@ -1498,7 +1498,7 @@ namespace DM_Weight.Port /// 获取冰箱温度 /// /// - public async Task GetFridgeTemperature() + public async Task GetFridgeTemperature(int iIndex) { float temperature = 0.0f; try diff --git a/DM_Weight/ViewModels/FridgeWindowViewModel.cs b/DM_Weight/ViewModels/FridgeWindowViewModel.cs index 8830785..e5ccaea 100644 --- a/DM_Weight/ViewModels/FridgeWindowViewModel.cs +++ b/DM_Weight/ViewModels/FridgeWindowViewModel.cs @@ -32,6 +32,18 @@ namespace DM_Weight.ViewModels CommonClass.SaveAppSetting("temperatureRange", _temperatureRange); } } + //冰箱2温度区间 + private string _temperatureRange2 = CommonClass.ReadAppSetting("temperatureRange2").ToString(); + public string TemperatureRange2 + { + get => _temperatureRange2; + set + { + SetProperty(ref _temperatureRange2, value); + //更新配置文件中冰箱温度区间 + CommonClass.SaveAppSetting("temperatureRange2", _temperatureRange2); + } + } private float defaultValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue")); //温度值 private float _temperatureValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue")); @@ -77,6 +89,22 @@ namespace DM_Weight.ViewModels set => SetProperty(ref _alarmState, value); } + + //冰箱2状态:true关;false开 + private bool _fridgeState2; + public bool FridgeState2 + { + get => _fridgeState2; + set => SetProperty(ref _fridgeState2, value); + } + //冰箱2报警状态:true关;false开 + private bool _alarmState2; + public bool AlarmState2 + { + get => _alarmState2; + set => SetProperty(ref _alarmState2, value); + } + private int _defaultLoginMode;//1开0关 private int _defaultAlarmMode;//1开0关 @@ -121,6 +149,20 @@ namespace DM_Weight.ViewModels Thread.Sleep(100); CommonClass.SaveAppSetting("FridgeState", "1"); } + + //冰箱2 发送冰箱使能/失能指令 + if (_fridgeState2) + { + await _portUtil.FridgeOff(); + Thread.Sleep(100); + CommonClass.SaveAppSetting("FridgeState2", "0"); + } + else + { + await _portUtil.FridegOpen(); + Thread.Sleep(100); + CommonClass.SaveAppSetting("FridgeState2", "1"); + } //} //温度报警设定 //if (AlarmState != _defaultAlarmMode.Equals(1)) @@ -138,6 +180,20 @@ namespace DM_Weight.ViewModels Thread.Sleep(100); CommonClass.SaveAppSetting("AlarmState", "1"); } + + //冰箱2 发送警报使能/失能指令 + if (_alarmState2) + { + await _portUtil.FridgeAlarmOff(); + Thread.Sleep(100); + CommonClass.SaveAppSetting("AlarmState2", "0"); + } + else + { + await _portUtil.FridgeAlarmOn(); + Thread.Sleep(100); + CommonClass.SaveAppSetting("AlarmState2", "1"); + } //} //if (retTemperature != TemperatureValue) @@ -147,7 +203,7 @@ namespace DM_Weight.ViewModels // CommonClass.SaveAppSetting("temperatureValue", TemperatureValue.ToString()); //} - //设定冰箱温度区间 + //设定冰箱1温度区间 string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-'); string[] newRange = TemperatureRange.Split('-'); if (range.Length >= 2) @@ -166,13 +222,39 @@ namespace DM_Weight.ViewModels if (Max != Convert.ToSingle(newRange[1])) { Thread.Sleep(100); - //设定冰箱温度最有值 + //设定冰箱温度最大值 await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[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); + + if (bMix && bMax) + { + if (Min != Convert.ToSingle(newRange2[0])) + { + //设定冰箱温度最小值 + await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0])); + Thread.Sleep(100); + } + if (Max != Convert.ToSingle(newRange2[1])) + { + Thread.Sleep(100); + //设定冰箱温度最大值 + await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1])); + Thread.Sleep(100); + } + } + } + _portUtil.FridgeOperate = false; AlertMsg alertMsg = new AlertMsg { diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index b378f89..8c4a784 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -281,7 +281,7 @@ namespace DM_Weight.ViewModels { string retStr = string.Empty; byte[] data = null; - float retT = await _portUtil.GetFridgeTemperature(); + float retT = await _portUtil.GetFridgeTemperature(1); Thread.Sleep(80); WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃"; } @@ -293,9 +293,11 @@ namespace DM_Weight.ViewModels { string retStr = string.Empty; byte[] data = null; - float retT = await _portUtil.GetFridgeTemperature(); + float retT = await _portUtil.GetFridgeTemperature(1); Thread.Sleep(80); - WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃"; + float retTemp = await _portUtil.GetFridgeTemperature(2); + Thread.Sleep(80); + WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃;{retTemp}℃"; } } /// @@ -330,6 +332,17 @@ namespace DM_Weight.ViewModels } return "数据异常"; } + + /// + /// 查看冰箱温度 + /// + public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); } + private void CheckAction() + { + GetWD(); + } + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) { @@ -403,20 +416,20 @@ namespace DM_Weight.ViewModels }; timer.Start(); } - #region 温度查询定时 - int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]); - if (interval > 0) - { - WDTimer = new System.Timers.Timer(); + //#region 温度查询定时 + //int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]); + //if (interval > 0) + //{ + // WDTimer = new System.Timers.Timer(); - WDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWD); - WDTimer.Interval = interval; - //WDTimer.Start(); - //WDTimer.AutoReset = true; - //WDTimer.Enabled = true; - } - #endregion - GetWD(); + // WDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWD); + // WDTimer.Interval = interval; + // //WDTimer.Start(); + // //WDTimer.AutoReset = true; + // //WDTimer.Enabled = true; + //} + //#endregion + //GetWD(); if (stopRecord > 0) { System.Timers.Timer timer = new System.Timers.Timer(); diff --git a/DM_Weight/Views/FridgeWindow.xaml b/DM_Weight/Views/FridgeWindow.xaml index f97a692..2e29494 100644 --- a/DM_Weight/Views/FridgeWindow.xaml +++ b/DM_Weight/Views/FridgeWindow.xaml @@ -15,7 +15,8 @@ - + + @@ -41,6 +42,19 @@ + + + + + + + + + +