diff --git a/BPASmartClient.Business/Plugin/OrderProxy.cs b/BPASmartClient.Business/Plugin/OrderProxy.cs index 2c13e9f9..8fd409d5 100644 --- a/BPASmartClient.Business/Plugin/OrderProxy.cs +++ b/BPASmartClient.Business/Plugin/OrderProxy.cs @@ -9,6 +9,7 @@ using BPASmartClient.Http; using BPASmartClient.Message; using BPASmartClient.Model; using BPASmartClient.Model.小炒机; +using BPASmartClient.Model.调酒机; using Newtonsoft.Json; using System; using System.Collections.Concurrent; @@ -28,7 +29,9 @@ namespace BPASmartClient.Business { //订单队列 private ConcurrentDictionary> orders = new ConcurrentDictionary>(); - //运行标识 + /// + /// 运行标识 + /// private bool running = false; //设备管理 private DeviceMgr deviceMgr; @@ -73,15 +76,15 @@ namespace BPASmartClient.Business { if (!orders.ContainsKey(morkOrderpush.DeviceId)) { - + orders.TryAdd(morkOrderpush.DeviceId, new ConcurrentQueue()); StartTargetDeviceOrderJob(morkOrderpush.DeviceId); } - if( orders[morkOrderpush.DeviceId].FirstOrDefault(p=>p.SuborderId == morkOrderpush.SuborderId) == null) + if (orders[morkOrderpush.DeviceId].FirstOrDefault(p => p.SuborderId == morkOrderpush.SuborderId) == null) { orders[morkOrderpush.DeviceId].Enqueue(morkOrderpush); } - + } //辅料信息 else if (message is RecipeBoms recipe) @@ -113,11 +116,19 @@ namespace BPASmartClient.Business IDevice device = deviceMgr.GetDevices().FirstOrDefault(x => x.DeviceId == 28); new StirFryGoodsEvent() { DeviceId = device.DeviceId, - stirFrymessage =frybom + stirFrymessage = frybom }.Publish(); MessageLog.GetInstance.Show("接受到【MQTT】的小炒流程信息"); - - + } + else if (message is MORKMWPushMessage morkMWBom) + { + IDevice device = deviceMgr.GetDevices().FirstOrDefault(x => x.DeviceId == 113); + new MorkMWGoodsEvent() + { + DeviceId = device.DeviceId, + morkMWPushMessage = morkMWBom + }.Publish(); + MessageLog.GetInstance.Show("接收到【MQTT】获取的调酒机配方信息"); } }); diff --git a/BPASmartClient.MorkMW/Control_MorkMW.cs b/BPASmartClient.MorkMW/Control_MorkMW.cs index d315de47..88c89a44 100644 --- a/BPASmartClient.MorkMW/Control_MorkMW.cs +++ b/BPASmartClient.MorkMW/Control_MorkMW.cs @@ -14,8 +14,10 @@ using Org.BouncyCastle.Bcpg.OpenPgp; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Net.Http.Json; +using System.Reflection; using System.Threading; using System.Windows.Documents; using static BPASmartClient.EventBus.EventBus; @@ -24,18 +26,33 @@ namespace BPASmartClient.MorkMW { public class Control_MorkMW : BaseDevice { + int id = 0; ModbusTcp modbus; public override DeviceClientType DeviceType => DeviceClientType.MORKMW; GVL_MorkMW morkMW = new GVL_MorkMW(); public override void DoMain() { - + VaribleMonitorDis(); ConnectKlpRobot("192.168.0.100", 8001); ServerInit(); DataParse(); + ThreadManage.GetInstance().StartLong(new Action(() => { VariableMonitor();Thread.Sleep(5); }),"˱״̬߳",true); + } + private void VaribleMonitorDis() + { + PropertyInfo[] pros= morkMW.GetType().GetProperties(); + foreach (var item in pros) + { + var res= item.GetCustomAttribute(); + if(res!=null) + { + GVL_MorkMW.varibleInfos.Add(new VaribleModel { Id = id + 1, VaribleName = res.VarName,RobotAddress=res.RobotAddress,ModbusAddress=res.ModbusTcpAddress,Notes=res.Notes }); + id++; + } + } } - + private void ServerInit() { //䷽Ϣ @@ -44,14 +61,18 @@ namespace BPASmartClient.MorkMW if (@event == null) return; if (@event is MorkMWGoodsEvent recipe) { - listMorkMWGoods= recipe.morkMWPushMessage.MorkMWGoods; - DeviceProcessLogShow($"յƻ{listMorkMWGoods.Count}Ʒ䷽"); + listMorkMWGoods= recipe.morkMWPushMessage?.MorkMWGoods; + DeviceProcessLogShow($"յƻ{listMorkMWGoods?.Count}Ʒ䷽"); } }); } public override void MainTask() { + if (Json.Data.IsVerify) + IsHealth = modbus.Connected; + else + IsHealth = true;//ϱ ToGetWink(); ToMixWink(); ToPourWink(); @@ -70,6 +91,8 @@ namespace BPASmartClient.MorkMW morkMW.TaskLock = true; if (orderLocInfos.TryDequeue(out OrderLocInfo res)) { + morkMW.CurrentSuborderId = res.SuborderId; + OrderChange(res.SuborderId,ORDER_STATUS.COOKING); foreach (var item in res.mixWink) { switch (item.Loc) @@ -81,7 +104,6 @@ namespace BPASmartClient.MorkMW case 4: ToSpecifiedLocTakeWink(item.Loc, item.Qty); break; case 5: ToSpecifiedLocTakeWink(item.Loc, item.Qty); break; case 6: ToSpecifiedLocTakeWink(item.Loc, item.Qty); break; - } switch (item.Loc) { @@ -105,7 +127,7 @@ namespace BPASmartClient.MorkMW } else { - if (morkMW.RobotIdle && orderLocInfos.Count > 0 && !morkMW.TaskLock && !morkMW.PourWinkComplete && morkMW.CupSignal) + if (morkMW.RobotIdle && simOrderLocInfos.Count > 0 && !morkMW.TaskLock && !morkMW.PourWinkComplete && morkMW.CupSignal) { DeviceProcessLogShow("ʼ"); morkMW.TaskLock = true; @@ -229,6 +251,7 @@ namespace BPASmartClient.MorkMW { if (RTrig.GetInstance("AllComplete").Start(morkMW.ProcessComplete)) { + OrderChange(morkMW.CurrentSuborderId, ORDER_STATUS.COMPLETED_COOK); morkMW.PourWinkComplete = true; DeviceProcessLogShow("ɣȡߵþƱ"); } @@ -236,6 +259,7 @@ namespace BPASmartClient.MorkMW { if (TTrig.GetInstance("PoutWinkCom").Start(morkMW.CupSignal)) { + OrderChange(morkMW.CurrentSuborderId, ORDER_STATUS.COMPLETED_TAKE); DeviceProcessLogShow("ͻȡߵþƱ,ÿվƱԴ´ζ"); } if (RTrig.GetInstance("PoutWinkCom").Start(morkMW.CupSignal)) @@ -281,6 +305,8 @@ namespace BPASmartClient.MorkMW morkMW.TakeWinkSixComplete = modbus.ReadCoils(4611); morkMW.MixWinkComplte = modbus.ReadCoils(4612); morkMW.ProcessComplete = modbus.ReadCoils(4613); + + } else { @@ -288,6 +314,30 @@ namespace BPASmartClient.MorkMW } } + public void VariableMonitor() + { + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ArriveWinkOneLoc").CurrentValue = morkMW.ArriveWinkOneLoc; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ArriveWinkTwoLoc").CurrentValue = morkMW.ArriveWinkTwoLoc; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ArriveWinkThreeLoc").CurrentValue = morkMW.ArriveWinkThreeLoc; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ArriveWinkFourLoc").CurrentValue = morkMW.ArriveWinkFourLoc; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ArriveWinkFiveLoc").CurrentValue = morkMW.ArriveWinkFiveLoc; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ArriveWinkSixLoc").CurrentValue = morkMW.ArriveWinkSixLoc; + + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "RobotIdle").CurrentValue = morkMW.RobotIdle; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "CupSignal").CurrentValue = morkMW.CupSignal; + + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "TakeWinkOneComplete").CurrentValue = morkMW.TakeWinkOneComplete; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "TakeWinkTwoComplete").CurrentValue = morkMW.TakeWinkTwoComplete; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "TakeWinkThreeComplete").CurrentValue = morkMW.TakeWinkThreeComplete; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "TakeWinkFourComplete").CurrentValue = morkMW.TakeWinkFourComplete; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "TakeWinkFiveComplete").CurrentValue = morkMW.TakeWinkFiveComplete; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "TakeWinkSixComplete").CurrentValue = morkMW.TakeWinkSixComplete; + + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "MixWinkComplte").CurrentValue = morkMW.MixWinkComplte; + GVL_MorkMW.varibleInfos.FirstOrDefault(p => p.VaribleName == "ProcessComplete").CurrentValue = morkMW.ProcessComplete; + + } + public override void ResetProgram() { morkMW = null; @@ -347,25 +397,51 @@ namespace BPASmartClient.MorkMW if (@event != null && @event is DoOrderEvent order) { - var res= listMorkMWGoods.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.GoodsKey); + morkMW.doOrderEvents.Add(order); + if (listMorkMWGoods.Count == 0) return; + if (morkMW.historySuborderId.FirstOrDefault(p => p == order.MorkOrder.SuborderId) != null) return; + OrderCount++; + var res= listMorkMWGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.GoodsKey); if (res != null) { string guid = Guid.NewGuid().ToString(); orderLocInfos.Enqueue(new OrderLocInfo { mixWink = res.MorkMWBoms, SuborderId = order.MorkOrder.SuborderId }); - DeviceProcessLogShow($"յС򶩵š{order.MorkOrder.SuborderId}"); - + morkMW.historySuborderId.Add(order.MorkOrder.SuborderId); + OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT); + DeviceProcessLogShow($"յ{OrderCount}С򶩵ǰ{order.MorkOrder.GoodsName},š{order.MorkOrder.SuborderId}"); + } + else + { + DeviceProcessLogShow($"δҵӦƷš{order.MorkOrder.SuborderId}"); } } }); } - /// - /// ӿջ + /// ״̬ϱ /// - /// - /// - public void ConnectKlpRobot(string ip, int port) + /// + /// + private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) + { + var res = morkMW.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid); + string goodName = string.Empty; + string SortNum = string.Empty; + if (res != null) + { + goodName = res.MorkOrder.GoodsName; + SortNum = res.MorkOrder.SortNum.ToString(); + } + + EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); + } + /// + /// ӿջ + /// + /// + /// + public void ConnectKlpRobot(string ip, int port) { modbus = new ModbusTcp(); modbus.Show += new Action((s) => @@ -394,6 +470,8 @@ namespace BPASmartClient.MorkMW /// ƻ䷽ /// public List listMorkMWGoods = new List(); + + } } diff --git a/BPASmartClient.MorkMW/GVL_MorkMW.cs b/BPASmartClient.MorkMW/GVL_MorkMW.cs index 4a082c26..465ce02f 100644 --- a/BPASmartClient.MorkMW/GVL_MorkMW.cs +++ b/BPASmartClient.MorkMW/GVL_MorkMW.cs @@ -1,5 +1,9 @@ -using System; + +using BPASmartClient.Model; +using BPASmartClient.MorkMW.Model; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,42 +13,50 @@ namespace BPASmartClient.MorkMW public class GVL_MorkMW { #region 机器人信号 - + [Varibles("RobotIdle", "初始化位置", "M105", "4201")] /// /// 机器人空闲信号 /// public bool RobotIdle { get; set; } - + [Varibles("TakeWinkOneComplete", "1号接酒完成", "M510", "4606")] public bool TakeWinkOneComplete { get; set; } + [Varibles("TakeWinkTwoComplete", "2号接酒完成", "M511", "4607")] public bool TakeWinkTwoComplete { get; set; } + [Varibles("TakeWinkThreeComplete", "3号接酒完成", "M512", "4608")] public bool TakeWinkThreeComplete { get; set; } + [Varibles("TakeWinkFourComplete", "4号接酒完成", "M513", "4609")] public bool TakeWinkFourComplete { get; set; } + [Varibles("TakeWinkFiveComplete", "5号接酒完成", "M514", "4610")] public bool TakeWinkFiveComplete { get; set; } + [Varibles("TakeWinkSixComplete", "6号接酒完成", "M515", "4611")] public bool TakeWinkSixComplete { get; set; } - + [Varibles("ArriveWinkOneLoc", "到达1号接酒位置", "M520", "4616")] public bool ArriveWinkOneLoc { get; set; } - + [Varibles("ArriveWinkTwoLoc", "到达2号接酒位置", "M521", "4617")] public bool ArriveWinkTwoLoc { get; set; } - + [Varibles("ArriveWinkThreeLoc", "到达3号接酒位置", "M522", "4618")] public bool ArriveWinkThreeLoc { get; set; } - + [Varibles("ArriveWinkFourLoc", "到达4号接酒位置", "M523", "4619")] public bool ArriveWinkFourLoc { get; set; } - + [Varibles("ArriveWinkFiveLoc", "到达5号接酒位置", "M524", "4620")] public bool ArriveWinkFiveLoc { get; set; } - + [Varibles("ArriveWinkSixLoc", "到达6号接酒位置", "M525", "4621")] public bool ArriveWinkSixLoc { get; set; } + [Varibles("CupSignal", "放杯处传感器信号", "X0", "0")] /// /// 放杯处传感器信号 /// public bool CupSignal { get; set; } + [Varibles("MixWinkComplte", "摇酒完成信号", "M516", "4612")] /// /// 摇酒完成信号 /// public bool MixWinkComplte { get; set; } + [Varibles("ProcessComplete", "倒酒完成信号", "M517", "4613")] /// /// 机器人倒完酒并回到初始位的完成信号 /// @@ -71,7 +83,27 @@ namespace BPASmartClient.MorkMW /// public bool PourWinkComplete { get; set; } #endregion - + /// + /// 允许本地下单 + /// public static bool AllowLocalSimOrder { get; set; } + + /// + /// 订单集合 + /// + public List doOrderEvents { get; set; } = new List(); + /// + /// 历史订单号 + /// + public List historySuborderId = new List(); + /// + /// 当前订单号 + /// + public string CurrentSuborderId { get; set; } + + /// + /// + /// + public static ObservableCollection varibleInfos = new ObservableCollection(); } } diff --git a/BPASmartClient.MorkMW/Model/VaribleModel.cs b/BPASmartClient.MorkMW/Model/VaribleModel.cs new file mode 100644 index 00000000..69886603 --- /dev/null +++ b/BPASmartClient.MorkMW/Model/VaribleModel.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Documents; + +namespace BPASmartClient.MorkMW.Model +{ + public class VaribleModel:ObservableObject + { + private int _id; + public int Id { get { return _id; }set { _id = value; OnPropertyChanged(); } } + + private string _varibleName; + public string VaribleName { get { return _varibleName; } set { _varibleName = value;OnPropertyChanged(); } } + + private string _robotAddress; + public string RobotAddress { get { return _robotAddress; } set { _robotAddress = value; OnPropertyChanged(); } } + + private string _modbusAddress; + public string ModbusAddress { get { return _modbusAddress; }set { _modbusAddress = value;OnPropertyChanged(); } } + + private string _notes; + public string Notes { get { return _notes; } set { _notes = value; OnPropertyChanged(); } } + + private bool _currentValue; + public bool CurrentValue { get { return _currentValue; } set { _currentValue = value; OnPropertyChanged(); } } + } +} diff --git a/BPASmartClient.MorkMW/Model/VariblesAttribute.cs b/BPASmartClient.MorkMW/Model/VariblesAttribute.cs new file mode 100644 index 00000000..09d28449 --- /dev/null +++ b/BPASmartClient.MorkMW/Model/VariblesAttribute.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkMW.Model +{ + public class VariblesAttribute : Attribute + { + + public string VarName { get; set; } + public string Notes { get; set; } + public string RobotAddress { get; set; } + public string ModbusTcpAddress { get; set; } + /// + /// + /// + /// 变量名 + /// 描述 + /// 机器人地址 + /// modbustcp地址 + public VariblesAttribute(string name, string notes, string plcaddress, string modbustcpaddress) + { + VarName = name; + Notes = notes; + RobotAddress = plcaddress; + ModbusTcpAddress = modbustcpaddress; + } + + } +} diff --git a/BPASmartClient.MorkMW/View/MonitorView.xaml b/BPASmartClient.MorkMW/View/MonitorView.xaml new file mode 100644 index 00000000..c5b20632 --- /dev/null +++ b/BPASmartClient.MorkMW/View/MonitorView.xaml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.MorkMW/View/MonitorView.xaml.cs b/BPASmartClient.MorkMW/View/MonitorView.xaml.cs new file mode 100644 index 00000000..f2d0d227 --- /dev/null +++ b/BPASmartClient.MorkMW/View/MonitorView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.MorkMW.View +{ + /// + /// MonitorView.xaml 的交互逻辑 + /// + public partial class MonitorView : UserControl + { + public MonitorView() + { + InitializeComponent(); + } + } +} diff --git a/BPASmartClient.MorkMW/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkMW/ViewModel/DebugViewModel.cs index 71beb1fc..3797c893 100644 --- a/BPASmartClient.MorkMW/ViewModel/DebugViewModel.cs +++ b/BPASmartClient.MorkMW/ViewModel/DebugViewModel.cs @@ -33,13 +33,13 @@ namespace BPASmartClient.MorkMW.ViewModel }); AddMaterial = new RelayCommand(() => { - + SimRecipe.recipe.Insert(0, new MixWinkModel()); }); ClearMaterial = new RelayCommand(() => { - if(SimRecipe.recipe.Count>1) - SimRecipe.recipe.RemoveAt(SimRecipe.recipe.Count - 2); + if(SimRecipe.recipe.Count>0) + SimRecipe.recipe.RemoveAt(SimRecipe.recipe.Count - 1); }); StartLocalSim = new RelayCommand(() => { diff --git a/BPASmartClient.MorkMW/ViewModel/MonitorViewModel.cs b/BPASmartClient.MorkMW/ViewModel/MonitorViewModel.cs new file mode 100644 index 00000000..fc67bfec --- /dev/null +++ b/BPASmartClient.MorkMW/ViewModel/MonitorViewModel.cs @@ -0,0 +1,17 @@ +using BPASmartClient.MorkMW.Model; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkMW.ViewModel +{ + internal class MonitorViewModel:ObservableObject + { + public MonitorViewModel() { } + public ObservableCollection vars { get; set; } = GVL_MorkMW.varibleInfos; + } +}