From 7fa019f18eb7dcf15ea6128bc04fd956af285a9a Mon Sep 17 00:00:00 2001 From: fyf Date: Tue, 8 Nov 2022 13:54:30 +0800 Subject: [PATCH 1/4] 1 --- BPASmartClient.ScreenLib/AppMain.cs | 4 +- BPASmartClient.ScreenLib/Helper/Main.cs | 68 ++++++- .../煮面机/ScreenMorksControlViewModel.cs | 132 ++++++++++++- BPASmartClient.ScreenMaxWok/App.config | 181 +++++++++++++++++- 4 files changed, 368 insertions(+), 17 deletions(-) diff --git a/BPASmartClient.ScreenLib/AppMain.cs b/BPASmartClient.ScreenLib/AppMain.cs index d49e53f5..3624193f 100644 --- a/BPASmartClient.ScreenLib/AppMain.cs +++ b/BPASmartClient.ScreenLib/AppMain.cs @@ -13,6 +13,8 @@ namespace BPASmartClient.ScreenLib { public AppMain(Window window, Type type) { + //启动Redis数据读取 + Main.GetInstance.Start(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; FSystemHelper.GetInstance.CreateDesktopShortcut(); WindowLargeScreen windowLarge = new WindowLargeScreen(); @@ -43,8 +45,6 @@ namespace BPASmartClient.ScreenLib } #endregion window = windowLarge; - Main main = new Main(); - main.Start(); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) diff --git a/BPASmartClient.ScreenLib/Helper/Main.cs b/BPASmartClient.ScreenLib/Helper/Main.cs index 83d5f579..171082cf 100644 --- a/BPASmartClient.ScreenLib/Helper/Main.cs +++ b/BPASmartClient.ScreenLib/Helper/Main.cs @@ -1,5 +1,6 @@ using BPA.Communication; using BPA.Helper; +using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -13,7 +14,7 @@ namespace BPASmartClient.ScreenLib /// /// 主函数 /// - public class Main + public class Main { #region 接口继承变量 /// @@ -53,18 +54,26 @@ namespace BPASmartClient.ScreenLib /// private static volatile Main _Instance; public static Main GetInstance => _Instance ?? (_Instance = new Main()); - public Main() { - RedisConnection= System.Configuration.ConfigurationManager.AppSettings["RedisConnection"].ToString(); - Name = System.Configuration.ConfigurationManager.AppSettings["DeviceMC"].ToString(); + public Main() + { + ReadPZ(); + if (PZdic.ContainsKey("RedisConnection")) + RedisConnection = PZdic["RedisConnection"]; + if (PZdic.ContainsKey("DeviceMC")) + Name = PZdic["DeviceMC"]; } /// /// 设备数据 /// - public List reeisDatas { get; set; } = new List(); + public Dictionary> redisDatasDic = new Dictionary>(); /// /// 告警数据 /// - public List reeisDatasAic { get; set; } = new List(); + public Dictionary> redisAicDatasDic = new Dictionary>(); + /// + /// 配置数据 + /// + public Dictionary PZdic=new Dictionary(); #endregion #region 线程处理函数 @@ -80,8 +89,42 @@ namespace BPASmartClient.ScreenLib if (IsRunning && IsRunningReids) { //1.读取Redis变量 - List Values = RedisHelper.GetInstance.Read>($"{Name}[Device]").Content; - List reeisDatasAic = RedisHelper.GetInstance.Read>($"{Name}[Alarm]").Content; + if (!string.IsNullOrEmpty(Name)) + { + redisDatasDic = new Dictionary>(); + redisAicDatasDic = new Dictionary>(); + if (Name.Contains(",")) + { + Name.Split(',')?.ToList().ForEach(x => + { + Dictionary valuePairs = new Dictionary(); + RedisHelper.GetInstance.Read>($"{x}[Device]").Content?.ToList().ForEach(k => { + valuePairs[k.VarName] = k; + }); + redisDatasDic[x]= valuePairs;//设备数据 + + Dictionary valuePairsAic = new Dictionary(); + RedisHelper.GetInstance.Read>($"{x}[Alarm]").Content?.ToList().ForEach(k => { + valuePairsAic[k.VarName] = k; + }); + redisAicDatasDic[x] = valuePairsAic;//告警数据 + }); + } + else + { + Dictionary valuePairs = new Dictionary(); + RedisHelper.GetInstance.Read>($"{Name}[Device]").Content?.ToList().ForEach(k => { + valuePairs[k.VarName] = k; + }); + redisDatasDic[Name] = valuePairs;//设备数据 + + Dictionary valuePairsAic = new Dictionary(); + RedisHelper.GetInstance.Read>($"{Name}[Alarm]").Content?.ToList().ForEach(k => { + valuePairsAic[k.VarName] = k; + }); + redisAicDatasDic[Name] = valuePairsAic;//告警数据 + } + } } } catch (Exception ex) @@ -150,6 +193,15 @@ namespace BPASmartClient.ScreenLib #region 调用事件 /// + /// 读取配置 + /// + public void ReadPZ() + { + System.Configuration.ConfigurationManager.AppSettings.AllKeys?.ToList().ForEach(key => { + PZdic[key]= System.Configuration.ConfigurationManager.AppSettings[key].ToString(); + }); + } + /// /// 初始化连接Redis MQTT /// public void Connection() diff --git a/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs b/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs index 49957813..a6af7f0b 100644 --- a/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs +++ b/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs @@ -7,12 +7,19 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Newtonsoft.Json; namespace BPASmartClient.ScreenLib { public class ScreenMorksControlViewModel : NotifyBase { #region 变量 + /// + /// 广告地址 + /// + public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } } + private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString()); + /// /// 柱状图显示集合 /// @@ -43,12 +50,6 @@ namespace BPASmartClient.ScreenLib public int YCDdCount { get { return _YCDdCount; } set { _YCDdCount = value; OnPropertyChanged(); } } private int _YCDdCount = 0; - /// - /// 广告地址 - /// - public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } } - private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString()); - /// /// 正在制作订单数据 /// @@ -186,6 +187,125 @@ namespace BPASmartClient.ScreenLib })); Thread.Sleep(5000); }), $"{DateTime.Now},线程服务"); + + + + } + + /// + /// 数据运行器 + /// + public void DataRun() + { + string Dev = "MorkS";//当前设备名称 + string name = Main.GetInstance.PZdic.ContainsKey($"{Dev}_Name") ? Main.GetInstance.PZdic[$"{Dev}_Name"].ToString(): DateTime.Now.ToString(); + ThreadManage.GetInstance().StartLong(new Action(() => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + if (!string.IsNullOrEmpty(name) && Main.GetInstance.redisDatasDic != null && Main.GetInstance.redisDatasDic.ContainsKey(name) && Main.GetInstance.redisDatasDic[name]!=null) + { + List list=new List { "IsRun", "RunStatus", "OrderCount", "ErrorOrderCount", "OrderMakeList", "OrderMakeListOver", "AlarmList" }; + list?.ForEach(x => { + if (Main.GetInstance.PZdic.ContainsKey($"{Dev}_{x}")) + { + if (Main.GetInstance.redisDatasDic[name].ContainsKey(Main.GetInstance.PZdic[$"{Dev}_{x}"])) + { + string _value = Main.GetInstance.redisDatasDic[name][Main.GetInstance.PZdic[$"{Dev}_{x}"]].VarVaule; + #region 执行更新界面数据 + switch (x) + { + case "IsRun"://是否运行 + DevIsRun = _value == "0" ? DevIsRun.停止 : DevIsRun.运行; + break; + case "RunStatus"://运行状态 + DevIsRun = _value == "0" ? DevIsRun.停止 : DevIsRun.运行; + break; + case "OrderCount"://是否运行 + try + { + DdCount = int.Parse(_value); + } + catch (Exception ex) + { + DdCount = 0; + } + break; + case "ErrorOrderCount": + try + { + YCDdCount = int.Parse(_value); + } + catch (Exception ex) + { + YCDdCount = 0; + } + break; + case "OrderMakeList": + try + { + OrderMakeList = new ObservableCollection(); + JsonConvert.DeserializeObject>(_value)?.OrderBy(l => l.SortNum)?.ToList().ForEach(par => { + OrderMakeList.Add(par); + }); + } + catch (Exception ex) + { + OrderMakeList = new ObservableCollection(); + } + break; + case "OrderMakeListOver": + try + { + OrderMakeListOver = new ObservableCollection(); + JsonConvert.DeserializeObject>(_value)?.OrderBy(l => l.SortNum)?.ToList().ForEach(par => { + OrderMakeListOver.Add(par); + }); + } + catch (Exception ex) + { + OrderMakeListOver = new ObservableCollection(); + } + break; + case "AlarmList": + try + { + AlarmList = new ObservableCollection(); + JsonConvert.DeserializeObject>(_value)?.OrderBy(l => l.AlarmTime)?.ToList().ForEach(par => { + AlarmList.Add(par); + }); + + //Histogram=new + //if (AlarmList.Count > 0) + //{ + + //} + } + catch (Exception ex) + { + OrderMakeListOver = new ObservableCollection(); + } + break; + default: + break; + } + #endregion + + } + } + + }); + } + + //Histogram = new[] { + // new KeyValuePair(name_s[0], new Random().Next(0,400)), + // new KeyValuePair(name_s[1], new Random().Next(0,400)), + // new KeyValuePair(name_s[2], new Random().Next(0,400)), + // new KeyValuePair(name_s[3], new Random().Next(0,400)), + // new KeyValuePair(name_s[4], new Random().Next(0,400))}; + })); + Thread.Sleep(500); + }), $"{name},线程服务"); } } } diff --git a/BPASmartClient.ScreenMaxWok/App.config b/BPASmartClient.ScreenMaxWok/App.config index 04466302..8d057181 100644 --- a/BPASmartClient.ScreenMaxWok/App.config +++ b/BPASmartClient.ScreenMaxWok/App.config @@ -3,7 +3,186 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 0da142d1181ca05d101f8969cdac935163fa631c Mon Sep 17 00:00:00 2001 From: fyf Date: Tue, 8 Nov 2022 13:57:45 +0800 Subject: [PATCH 2/4] 1 --- .../炒锅/ScreenMinWokControl.xaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BPASmartClient.ScreenLib/炒锅/ScreenMinWokControl.xaml b/BPASmartClient.ScreenLib/炒锅/ScreenMinWokControl.xaml index 315bbc51..b533a084 100644 --- a/BPASmartClient.ScreenLib/炒锅/ScreenMinWokControl.xaml +++ b/BPASmartClient.ScreenLib/炒锅/ScreenMinWokControl.xaml @@ -63,7 +63,7 @@ 设备当前状态 - + @@ -72,11 +72,11 @@ - 今日刷卡数 + 今日订单数 - 异常刷卡数 + 异常订单数 @@ -280,7 +280,7 @@ 设备当前状态 - + @@ -289,11 +289,11 @@ - 今日刷卡数 + 今日订单数 - 异常刷卡数 + 异常订单数 From 01f80168082faba50c421e28918edeedda3d910a Mon Sep 17 00:00:00 2001 From: fyf Date: Tue, 8 Nov 2022 14:00:25 +0800 Subject: [PATCH 3/4] 1 --- SmartClient.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartClient.sln b/SmartClient.sln index 35a590d8..aa81c08a 100644 --- a/SmartClient.sln +++ b/SmartClient.sln @@ -174,7 +174,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmart.MenuLoad", "BPASma EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MorkBF", "BPASmartClient.MorkBF\BPASmartClient.MorkBF.csproj", "{CD0FBCF1-9C49-4032-96AD-B9E25F86F2A7}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "7.DeviceMotion", "7.DeviceMotion", "{7BE13E55-D8B1-4232-AE63-8BF122633297}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "7.DeviceScreen", "7.DeviceScreen", "{7BE13E55-D8B1-4232-AE63-8BF122633297}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "公共库", "公共库", "{C6984F48-A0FE-47A4-B63B-E4E5BCFCD6D3}" EndProject From fc2bf12324ef2dcfc8d2f451bb76aeec84f92c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Tue, 8 Nov 2022 17:10:52 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Morks=E6=95=B0=E6=8D=AE=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Model/OrderStatistics.cs | 21 ++++++++++++ BPASmartClient.MorkS/Control_Morks.cs | 2 ++ BPASmartClient.MorkS/DataServer.cs | 45 +++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 BPASmartClient.Model/OrderStatistics.cs create mode 100644 BPASmartClient.MorkS/DataServer.cs diff --git a/BPASmartClient.Model/OrderStatistics.cs b/BPASmartClient.Model/OrderStatistics.cs new file mode 100644 index 00000000..84340930 --- /dev/null +++ b/BPASmartClient.Model/OrderStatistics.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class OrderStatistics + { + /// + /// 订单总量 + /// + public int Count { get; set; } + + /// + /// 统计时间 + /// + public DateTime StatisticsTime { get; set; } + } +} diff --git a/BPASmartClient.MorkS/Control_Morks.cs b/BPASmartClient.MorkS/Control_Morks.cs index a04aea4f..e7bd1ec2 100644 --- a/BPASmartClient.MorkS/Control_Morks.cs +++ b/BPASmartClient.MorkS/Control_Morks.cs @@ -273,6 +273,8 @@ namespace BPASmartClient.MorkS if (order.MorkOrder.GoodBatchings == null) return; if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId)) return; OrderCount++; + Json.Data.StatisticsTime=DateTime.Now; + Json.Data.Count++; OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT); DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}"); mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId); diff --git a/BPASmartClient.MorkS/DataServer.cs b/BPASmartClient.MorkS/DataServer.cs new file mode 100644 index 00000000..6d49c57d --- /dev/null +++ b/BPASmartClient.MorkS/DataServer.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using BPA.Helper; +using BPASmartClient.MQTT; + +namespace BPASmartClient.MorkS +{ + public class DataServer + { + + private volatile static DataServer _Instance; + public static DataServer GetInstance => _Instance ?? (_Instance = new DataServer()); + private DataServer() { } + + public void Init() + { + MQTTProxy mQTTProxy = new MQTTProxy(); + mQTTProxy.Connected = new Action(() => + { + mQTTProxy.Subscrib(""); + ThreadManage.GetInstance().StartLong(new Action(() => + { + mQTTProxy.Publish("", ""); + Thread.Sleep(100); + }), "海科食堂大屏监听"); + }); + mQTTProxy.Connect("UserName", "Password", "Host", 1883, $"MORKS 设备监听数据{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } + + + //订单信息(正在制作,等待制作,制作完成) + //煮面炉上下状态(6个煮面炉上或下) + //温度状态(煮面炉温度是否到达) + //料仓位置(当前料仓在几号位置) + //料仓上下物料检测 + //落碗机构缺碗检测 + //机器人状态 + //当日订单总量 + //报警信息 + } +}