From 675180b29b40e7a06ede3b40b626d1a505b16b37 Mon Sep 17 00:00:00 2001 From: taoye Date: Mon, 30 May 2022 17:43:39 +0800 Subject: [PATCH] =?UTF-8?q?MorM=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmartClient.MorkF.csproj | 4 + BPASmartClient.MorkF/Control_MorkF.cs | 90 ++-- BPASmartClient.MorkF/GVL_MorkF.cs | 8 +- BPASmartClient.MorkF/View/DebugView.xaml | 45 ++ BPASmartClient.MorkF/View/DebugView.xaml.cs | 30 ++ .../ViewModel/DebugViewModel.cs | 55 +++ .../BPASmartClient.MorkM.csproj | 9 +- BPASmartClient.MorkM/Control_MORKM.cs | 390 +++++------------- BPASmartClient.MorkM/Model/GeneralConfig.cs | 16 + BPASmartClient.MorkM/View/Debug.xaml | 32 -- BPASmartClient.MorkM/View/DebugView.xaml | 154 +++++++ .../View/{Debug.xaml.cs => DebugView.xaml.cs} | 10 +- .../View/SimOrderConfitView.xaml | 206 +++++++++ .../View/SimOrderConfitView.xaml.cs | 56 +++ .../ViewModel/DebugViewModel.cs | 128 +++++- .../ViewModel/MonitorViewModel.cs | 15 +- .../ViewModel/ParSetViewModel.cs | 13 +- .../ViewModel/SimOrderConfitViewModel.cs | 90 ++++ BPASmartClient/App.config | 8 +- BPASmartClient/BPASmartClient.csproj | 1 + BPASmartClient/DeviceInfo.xml | 20 +- BPASmartClient/MainWindow.xaml.cs | 4 +- 22 files changed, 994 insertions(+), 390 deletions(-) create mode 100644 BPASmartClient.MorkF/View/DebugView.xaml create mode 100644 BPASmartClient.MorkF/View/DebugView.xaml.cs create mode 100644 BPASmartClient.MorkF/ViewModel/DebugViewModel.cs create mode 100644 BPASmartClient.MorkM/Model/GeneralConfig.cs delete mode 100644 BPASmartClient.MorkM/View/Debug.xaml create mode 100644 BPASmartClient.MorkM/View/DebugView.xaml rename BPASmartClient.MorkM/View/{Debug.xaml.cs => DebugView.xaml.cs} (69%) create mode 100644 BPASmartClient.MorkM/View/SimOrderConfitView.xaml create mode 100644 BPASmartClient.MorkM/View/SimOrderConfitView.xaml.cs create mode 100644 BPASmartClient.MorkM/ViewModel/SimOrderConfitViewModel.cs diff --git a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj index feae8a16..dd2bae25 100644 --- a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj +++ b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 292ac789..290e39d4 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -30,7 +30,7 @@ namespace BPASmartClient.MorkF CommandRegist();//调试 ServerInit(); DataParse();//数据解析 - MessageLog.GetInstance.Show("MORKF 设备初始化完成"); + DeviceProcessLogShow("MORKF 设备初始化完成"); } #region 调试代码 public void CommandRegist() @@ -324,7 +324,7 @@ namespace BPASmartClient.MorkF // //配方数据地址范围:VW2000 - VW2278 // WriteData("VW2000", recipeBoms.ToArray()); //} - //else { MessageLog.GetInstance.Show("配方数据为空"); } + //else {DeviceProcessLogShow("配方数据为空"); } } /// @@ -339,7 +339,7 @@ namespace BPASmartClient.MorkF { if (order.MorkOrder.GoodBatchings == null) return; OrderCount++; - MessageLog.GetInstance.Show($"接收到{OrderCount}次订单"); + DeviceProcessLogShow($"接收到{OrderCount}次订单"); foreach (var item in order.MorkOrder.GoodBatchings) { var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId); @@ -347,7 +347,7 @@ namespace BPASmartClient.MorkF { if (ushort.TryParse(res.BatchingLoc, out ushort loc)) { - + //if (morkF.TakeMaterialQueue.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null) //将一个商品的ABC料位置存入队列 morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = order.MorkOrder.SuborderId, BatchingId = res.BatchingId, MaterialLoc = ushort.Parse(res.BatchingLoc) }); @@ -405,7 +405,7 @@ namespace BPASmartClient.MorkF morkF.listStirBom.RemoveAt(0); foreach (var res in bom.StirFryActions) { - MessageLog.GetInstance.Show($"执行流程{res.Time}"); + DeviceProcessLogShow($"执行流程{res.Time}"); //机器人线程 Task taskRobot = Task.Run(new Action(() => { @@ -524,7 +524,7 @@ namespace BPASmartClient.MorkF morkF.listStirBom.RemoveAt(0); foreach (var res in bom.StirFryActions)//遍历所有流程 { - MessageLog.GetInstance.Show($"执行流程{res.Time}"); + DeviceProcessLogShow($"执行流程{res.Time}"); //机器人线程 Task taskRobot = Task.Run(new Action(() => { @@ -635,7 +635,7 @@ namespace BPASmartClient.MorkF { - //出餐完成,相应变量复位 + //主流程出餐完成,相应变量复位 if (morkF.MainOutMealComplete) { morkF.TakePlateLock = false; @@ -643,7 +643,7 @@ namespace BPASmartClient.MorkF morkF.MainProcessExcuteLock = false; morkF.MainOrderMaterialCom = false; } - + //辅流程出餐完成,相应变量复位 if (morkF.MinorOutMealComplete) { morkF.TakePlateLock = false; @@ -669,11 +669,11 @@ namespace BPASmartClient.MorkF // if (ushort.TryParse(result[0].BatchingLoc, out ushort loc)) // { // TurnMaterialStore(loc); - // MessageLog.GetInstance.Show($"转台转到【{loc}】位置"); + // DeviceProcessLogShow($"转台转到【{loc}】位置"); // morkF.TurnTableLock = true; //取料完成后置false // } // } - // else MessageLog.GetInstance.Show("未找到可用的物料信息"); + // elseDeviceProcessLogShow("未找到可用的物料信息"); //} //调试代码 @@ -684,12 +684,15 @@ namespace BPASmartClient.MorkF { TurnMaterialStore(resultorder[0]); - MessageLog.GetInstance.Show($"转台转到【{resultorder[0]}】位置"); + DeviceProcessLogShow($"转台转到【{resultorder[0]}】位置"); resultorder.RemoveAt(0); morkF.TurnTableLock = true; //取料完成后置false } - else MessageLog.GetInstance.Show("未找到可用的物料信息"); + else + { + DeviceProcessLogShow("未找到可用的物料信息"); + } } } @@ -707,12 +710,15 @@ namespace BPASmartClient.MorkF if (morkF.TakePlateQueue.TryDequeue(out OrderLocInfo order)) { StartTakePlate(); - morkF.CurrentOrderId = order.SuborderId; + if (morkF.MainProcessStatus) + morkF.MainCurrentOrderId = order.SuborderId; + if (morkF.MinorProessStatus) + morkF.MinorCurrentOrderId = order.SuborderId; morkF.TakePlateLock = true; //订单完成后置false morkF.MainOutMealComplete = false; morkF.MinorOutMealComplete = false; // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING); - MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取碗控制"); + DeviceProcessLogShow($"订单【{order.SuborderId}】执行取碗控制"); } } } @@ -727,7 +733,7 @@ namespace BPASmartClient.MorkF //{ // Task.Delay(5).Wait(); //} - while (!(!morkF.CleanModule||!morkF.SecondCleanModule)&&(!morkF.KitchenOneStatus||!morkF.KitchenSecondStatus)&&(morkF.CleanComplete|| morkF.SecondCleanComplete))//等待取锅条件满足 + while (!(!morkF.CleanModule || !morkF.SecondCleanModule) && (!morkF.KitchenOneStatus || !morkF.KitchenSecondStatus) && (morkF.CleanComplete || morkF.SecondCleanComplete))//等待取锅条件满足 { Task.Delay(5).Wait(); } @@ -738,7 +744,11 @@ namespace BPASmartClient.MorkF TakePotToKitchen(); WriteData("M1.5", false);//清洗模组1完成复位 WriteData("M2.0", false);//清洗模组2完成复位 - MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取锅到灶台控制"); + if (morkF.MainProcessStatus) + DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制"); + if (morkF.MinorProessStatus) + DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); + while (!morkF.PutPotToKitchenComlete) { Task.Delay(5).Wait(); @@ -783,7 +793,7 @@ namespace BPASmartClient.MorkF TakeBurden(loc); TurnReset(loc);//转台复位 - MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料"); + DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行到转台{loc}位置取料"); } //等待取料完成 while (!morkF.TakeMaterialComplete) @@ -810,7 +820,7 @@ namespace BPASmartClient.MorkF int loc = order.MaterialLoc; TakeBurden(loc); TurnReset(loc);//转台复位 - MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,执行取B料"); + DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行取B料"); } //等待取料完成 while (!morkF.TakeMaterialComplete) @@ -841,9 +851,9 @@ namespace BPASmartClient.MorkF int loc = order.MaterialLoc; TakeBurden(loc); TurnReset(loc);//转台复位 - MessageLog.GetInstance.Show($"订单【{ order.SuborderId}】,执行取C料"); + DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行取C料"); } - MessageLog.GetInstance.ShowEx($"剩余配料数量{morkF.TakeMaterialQueue.Count}"); + DeviceProcessLogShow($"剩余配料数量{morkF.TakeMaterialQueue.Count}"); //等待取料完成 while (!morkF.TakeMaterialComplete) { @@ -873,14 +883,17 @@ namespace BPASmartClient.MorkF { Task.Delay(5).Wait(); } - + if (morkF.TakePlateQueue.Count == 0) { WriteData("M0.7", false);//无订单关闭抽风机 } RobotOutMeal(); WriteData("M1.2", false);//供盘复位 - MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】正在出餐"); + if (morkF.MainProcessStatus) + DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制"); + if (morkF.MinorProessStatus) + DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); } @@ -893,7 +906,10 @@ namespace BPASmartClient.MorkF { Task.Delay(5).Wait(); } - MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】出餐完成"); + if (morkF.MainProcessStatus) + DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制"); + if (morkF.MinorProessStatus) + DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); WriteData("M14.2", false);//机器人出餐完成复位 //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK); CleanModuleControl("Start"); @@ -946,7 +962,7 @@ namespace BPASmartClient.MorkF Task.Delay(5).Wait(); } WriteData("M8.3", false);//下降完成复位 - MessageLog.GetInstance.Show($"翻转机下降完成"); + DeviceProcessLogShow($"翻转机下降完成"); //if (morkF.MaterialCount == 3 && morkF.MainProcessStatus) //{ // morkF.MainProcessWait = true; @@ -991,9 +1007,9 @@ namespace BPASmartClient.MorkF } morkF.MainOrderMaterialCom = true; - MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】,配料倒料完成"); + DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】,配料倒料完成"); } - else //主流程准备阻塞 + else //辅程准备阻塞 { morkF.MainProcessWait = true; } @@ -1017,15 +1033,15 @@ namespace BPASmartClient.MorkF } morkF.MinorOrderMaterialCom = true; - MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】,配料倒料完成"); + DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】,配料倒料完成"); } - else //辅流程准备阻塞 + else //主流程准备阻塞 { morkF.MinorProcessWait = true; } } - MessageLog.GetInstance.Show("翻转机上升完成"); + DeviceProcessLogShow("翻转机上升完成"); } private void GetStatus(string key, Action action) @@ -1088,8 +1104,10 @@ namespace BPASmartClient.MorkF break; } - MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】,加热档位调至{number}挡"); - + if (morkF.MainProcessStatus) + DeviceProcessLogShow($"订单【{ morkF.MainCurrentOrderId}】执行取锅到灶台控制"); + if (morkF.MinorProessStatus) + DeviceProcessLogShow($"订单【{ morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); } public void TurnMaterialStore(int loc) { @@ -1151,12 +1169,12 @@ namespace BPASmartClient.MorkF WriteData("M2.7", true);//加油 WriteData("M0.7", true);//打开抽风机 - MessageLog.GetInstance.Show("开始注油"); + DeviceProcessLogShow("开始注油"); while (!morkF.FallOilComplete) { Task.Delay(5).Wait(); } - MessageLog.GetInstance.Show("注油完成"); + DeviceProcessLogShow("注油完成"); } /// @@ -1171,7 +1189,7 @@ namespace BPASmartClient.MorkF // case "Middle": WriteData("", 1); break; case "Down": WriteData("M8.2", true); break; } - MessageLog.GetInstance.Show($"翻转机执行{orientation}操作"); + DeviceProcessLogShow($"翻转机执行{orientation}操作"); } /// /// 翻转机档位控制 @@ -1189,7 +1207,7 @@ namespace BPASmartClient.MorkF case 2: WriteData("M7.2", true); break;//翻炒机2挡 case 3: WriteData("M7.3", true); break;//翻炒机3挡 } - MessageLog.GetInstance.Show($"翻转机档位调至{gear}挡"); + DeviceProcessLogShow($"翻转机档位调至{gear}挡"); } /// /// 取A,B,C料 @@ -1211,7 +1229,7 @@ namespace BPASmartClient.MorkF { WriteData("M1.4", false); } - MessageLog.GetInstance.Show($"清洗模组执行【{status}】操作"); + DeviceProcessLogShow($"清洗模组执行【{status}】操作"); } public override void Stop() diff --git a/BPASmartClient.MorkF/GVL_MorkF.cs b/BPASmartClient.MorkF/GVL_MorkF.cs index 773f54ed..2c656889 100644 --- a/BPASmartClient.MorkF/GVL_MorkF.cs +++ b/BPASmartClient.MorkF/GVL_MorkF.cs @@ -91,9 +91,13 @@ namespace BPASmartClient.MorkF /// public ConcurrentQueue TakePlateQueue = new ConcurrentQueue(); /// - /// 存放当前订单唯一ID + /// 存放主流程当前订单唯一ID /// - public string CurrentOrderId { get; set; } + public string MainCurrentOrderId { get; set; } + /// + /// 存放辅流程当前订单唯一ID + /// + public string MinorCurrentOrderId { get; set; } /// /// PLC上升沿初始化触发信号 /// diff --git a/BPASmartClient.MorkF/View/DebugView.xaml b/BPASmartClient.MorkF/View/DebugView.xaml new file mode 100644 index 00000000..af377ca3 --- /dev/null +++ b/BPASmartClient.MorkF/View/DebugView.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.MorkF/View/DebugView.xaml.cs b/BPASmartClient.MorkF/View/DebugView.xaml.cs new file mode 100644 index 00000000..2812751f --- /dev/null +++ b/BPASmartClient.MorkF/View/DebugView.xaml.cs @@ -0,0 +1,30 @@ +using BPASmartClient.MorkF.ViewModel; +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.MorkF.View +{ + /// + /// DebugView.xaml 的交互逻辑 + /// + public partial class DebugView : UserControl + { + public DebugView() + { + InitializeComponent(); + this.DataContext = new DebugViewModel(); + } + } +} diff --git a/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs new file mode 100644 index 00000000..ddbc8129 --- /dev/null +++ b/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs @@ -0,0 +1,55 @@ +using BPASmartClient.Helper; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkF.ViewModel +{ + internal class DebugViewModel : ObservableObject + { + + public RelayCommand PlcInite { get; set; } + public RelayCommand SimulateOrder { get; set; } + public RelayCommand TakePot { get; set; } + public RelayCommand TakePotReset { get; set; } + public RelayCommand TempTurnOff { get; set; } + public RelayCommand OneBlock { get; set; } + public RelayCommand TwoBlock { get; set; } + public RelayCommand ThreeBlock { get; set; } + + public RelayCommand OverTurnOff { get; set; } + public RelayCommand OverOneBlock { get; set; } + public RelayCommand OverTwoBlock { get; set; } + public RelayCommand OverThreeBlock { get; set; } + public RelayCommand OverGoOn { get; set; } + public RelayCommand OverGoDown { get; set; } + public RelayCommand ShreddCabbage { get; set; } + public RelayCommand FryPork { get; set; } + public RelayCommand XingBaoGu { get; set; } + public DebugViewModel() + { + PlcInite = new RelayCommand(() => { ActionManage.GetInstance.Send("InitCommand"); }); + SimulateOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("SimultaorOrder"); }); + TakePot = new RelayCommand(() => { ActionManage.GetInstance.Send("TakePot"); }); + TakePotReset = new RelayCommand(() => { ActionManage.GetInstance.Send("TakePotReset"); }); + TempTurnOff = new RelayCommand(() => { ActionManage.GetInstance.Send("TakeOff"); }); + OneBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OneBlock"); }); + TwoBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("TwoBlock"); }); + ThreeBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("ThreeBlock"); }); + OverTurnOff = new RelayCommand(() => { ActionManage.GetInstance.Send("OverTurnOff"); }); + OverOneBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OverOneBlock"); }); + OverTwoBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OverTwoBlock"); }); + OverThreeBlock = new RelayCommand(() => { ActionManage.GetInstance.Send("OverThreeBlock"); }); + OverGoOn = new RelayCommand(() => { ActionManage.GetInstance.Send("OverGoOn"); }); + OverGoDown = new RelayCommand(() => { ActionManage.GetInstance.Send("OverGoDown"); }); + ShreddCabbage = new RelayCommand(() => { ActionManage.GetInstance.Send("ShreddCabbage"); }); + FryPork = new RelayCommand(() => { ActionManage.GetInstance.Send("FryPork"); }); + XingBaoGu = new RelayCommand(() => { ActionManage.GetInstance.Send("XingBaoGu"); }); + } + + } +} diff --git a/BPASmartClient.MorkM/BPASmartClient.MorkM.csproj b/BPASmartClient.MorkM/BPASmartClient.MorkM.csproj index 7eaf6836..69d03903 100644 --- a/BPASmartClient.MorkM/BPASmartClient.MorkM.csproj +++ b/BPASmartClient.MorkM/BPASmartClient.MorkM.csproj @@ -7,13 +7,12 @@ + + - - Code - Code @@ -23,10 +22,6 @@ - - $(DefaultXamlRuntime) - Designer - $(DefaultXamlRuntime) Designer diff --git a/BPASmartClient.MorkM/Control_MORKM.cs b/BPASmartClient.MorkM/Control_MORKM.cs index 69357e64..c521ac8a 100644 --- a/BPASmartClient.MorkM/Control_MORKM.cs +++ b/BPASmartClient.MorkM/Control_MORKM.cs @@ -11,231 +11,81 @@ using BPA.Message.Enum; using BPASmartClient.Model; using BPASmartClient.EventBus; using static BPASmartClient.EventBus.EventBus; -using BPASmartClient.MorkS.ViewModel; using BPASmartClient.MorkM.Model; using System.Collections.ObjectModel; using BPASmartClient.Model.PLC; +using BPASmartClient.MorkM.ViewModel; namespace BPASmartClient.MorkM { public class Control_MORKM : BaseDevice { - + public override DeviceClientType DeviceType => DeviceClientType.MORKM; GVL_MORKM mORKS = new GVL_MORKM(); Alarm alarm = new Alarm(); HardwareStatus hardwareStatus = new HardwareStatus(); - public void Init() - { - ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); - ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); - } - //public void ConnectOk() - //{ - // WriteRecipeBoms(); - // ReadData(); - // Main(); - // ResetProgram(); - // ActionManage.GetInstance.Register(new Action(() => - // { - // Random rd = new Random(); - // ThreadManage.GetInstance().StartLong(new Action(() => - // { - // int NoodleLoc = rd.Next(1, 6); - // int BowlLoc = rd.Next(10, 11); - // string guid = new Guid().ToString(); - - // mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid }); - // DeviceProcessLogShow($"添加订单:面条位置【{NoodleLoc}】"); - - // mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid }); - // DeviceProcessLogShow($"添加订单:碗位置【{BowlLoc}】"); - // Thread.Sleep(60000); - // }), "ForOrder"); - // }), "EnableForOrder"); - - // ActionManage.GetInstance.Register(new Action(() => - // { - // ThreadManage.GetInstance.StopTask("ForOrder", new Action(() => - // { - // mORKS.RBTakeNoodleTask.Clear(); - // mORKS.TakeBowlTask.Clear(); - // })); - // }), "StopForOrder"); - - // DeviceProcessLogShow("MORKM 设备初始化完成"); - //} - - //private void ResetProgram() - //{ - // ThreadManage.GetInstance.StartLong(new Action(() => - // { - // if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing)) - // { - // ThreadManage.GetInstance.StopTask("MainTask", new Action(() => - // { - // ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => - // { - // mORKS = null; - // mORKS = new GVL_MORKM(); - // ActionManage.GetInstance.Send("ResetProgram"); - // ActionManage.GetInstance.Send("ClearOrders"); - // ReadData(); - // Main(); - // })); - // })); - // } - - // Thread.Sleep(10); - // }), "ResetProgram"); - //} - - /// - /// 数据读取 - /// - //public void ReadData() - //{ - // ThreadManage.GetInstance.StartLong(new Action(() => - // { - // ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action((bools) => - // { - // mORKS.RobotTakeNoodle = bools[0]; - // mORKS.RobotOutMeal = bools[1]; - // mORKS.MoveTurntable = bools[2]; - // })); - - // ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action((bools) => - // { - // mORKS.InitComplete = bools[0]; - // mORKS.TakeBowlIdle = bools[1]; - // mORKS.TemperatureReached = bools[2]; - // mORKS.AllowFallNoodle = bools[3]; - // mORKS.RbTakeNoodleComplete = bools[4]; - // mORKS.RbFallNoodleComplete = bools[5]; - // mORKS.RbOutMealComplete = bools[6]; - // mORKS.RobotIdle = bools[7]; - // mORKS.TakeMealDetect = bools[8]; - // mORKS.MissingBowl = bools[9]; - // DeviceData.Initing = bools[10]; - // mORKS.TurntableLowerLimit = bools[11]; - // mORKS.MissingBowlSignal2 = bools[12]; - // mORKS.TurntableUpLimit = bools[13]; - // mORKS.FeedComplete = bools[14]; - // mORKS.TurntableMoveInPlace = bools[15]; - // })); - - // var errorStatus = ModbusTcpHelper.GetInstance.Read((ushort)ModbusTcpHelper.GetInstance.GetBoolAddress("M235.0"), ReadType.Coils, 1); - // if (errorStatus != null && errorStatus is bool error) mORKS.Error = error; - - // ModbusTcpHelper.GetInstance.Readbool(1136, 7, new Action((bools) => - // { - // for (int i = 0; i < 6; i++) - // { - // mORKS.NoodleCookerStatus[i] = bools[i]; - // } - // mORKS.Feeding = bools[6]; - // })); - - // ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action((bools) => - // { - // for (int i = 0; i < 6; i++) - // { - // mORKS.CookNoodlesComplete[i] = bools[i]; - // } - // })); - - // ModbusTcpHelper.GetInstance.Readbool(1570, 20, new Action((bools) => - // { - // alarm.MachineLeftLowTemperature = bools[0]; - // alarm.MachineRightLowTemperature = bools[1]; - // alarm.Supply1_LossBowl = bools[2]; - // alarm.Supply2_LossBowl = bools[3]; - // alarm.Supply1_ErrorOutBowl = bools[4]; - // alarm.Supply2_ErrorOutBowl = bools[5]; - // alarm.PushBowlCylinderError = bools[6]; - // alarm.NoodleMacCommunicateError = bools[7]; - // alarm.DosingMacCommunicateError = bools[8]; - // alarm.RobotMacCommunicateError = bools[9]; - // alarm.RobotInitError = bools[11]; - // alarm.RobotUrgentStop = bools[12]; - // alarm.RobotNotInRemoteMode = bools[13]; - // alarm.RobotNotInReady = bools[14]; - // alarm.RobotSelfInException = bools[15]; - // })); - - - // var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters); - // if (ResLoc != null) - // { - // if (ResLoc is ushort loc) - // { - // mORKS.TurntableFeedbackloc = loc; - // } - // } - // Thread.Sleep(500); - // }), "ReadPLCData"); - //} - //public void SimOrder(T simOrder) - //{ + public void SimOrder(T simOrder) + { - // if (simOrder != null) - // { + if (simOrder != null) + { - // if (simOrder is List locs) - // { - // OrderInformation newOrder = new OrderInformation();//新加 - // List orders = new List(); - // string subId = Guid.NewGuid().ToString(); - // foreach (var item in locs) - // { - // if (item >= 1 && item <= 5) - // { - // orders.Add(new OrderLocInfo() { Loc = item, SuborderId = subId, MakeType = false }); - // //mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId }); - // //DeviceProcessLogShow($"添加订单:面条位置【{item}】"); - // } - // if (item >= 10 && item <= 11) - // { - // mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId, MakeType = false }); - // DeviceProcessLogShow($"添加订单:碗位置【{item}】"); - // } - // } - // mORKS.DishNumber = orders.Count;//订单中配菜的数量 - // while (orders.Count > 0) - // { - // for (int i = 0; i < orders.Count; i++) - // { - // var res = orders.FirstOrDefault(p => p.Loc % 2 != 0); - // if (res != null) - // { - // //if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == res.SuborderId) == null) - // mORKS.RBTakeNoodleTask.Enqueue(res); + if (simOrder is List locs) + { + OrderInformation newOrder = new OrderInformation();//新加 + List orders = new List(); + string subId = Guid.NewGuid().ToString(); + foreach (var item in locs) + { + if (item >= 1 && item <= 5) + { + orders.Add(new OrderLocInfo() { Loc = item, SuborderId = subId, MakeType = false }); + //mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId }); + //DeviceProcessLogShow($"添加订单:面条位置【{item}】"); + } + if (item >= 10 && item <= 11) + { + mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId, MakeType = false }); + DeviceProcessLogShow($"添加订单:碗位置【{item}】"); + } + } + mORKS.DishNumber = orders.Count;//订单中配菜的数量 + while (orders.Count > 0) + { + for (int i = 0; i < orders.Count; i++) + { + var res = orders.FirstOrDefault(p => p.Loc % 2 != 0); + if (res != null) + { + //if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == res.SuborderId) == null) + mORKS.RBTakeNoodleTask.Enqueue(res); - // orders.Remove(res); + orders.Remove(res); - // } - // else - // { - // //if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == orders[i].SuborderId) == null) - // mORKS.RBTakeNoodleTask.Enqueue(orders[i]); - // mORKS.VegtabNum++; - // orders.RemoveAt(i); + } + else + { + //if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == orders[i].SuborderId) == null) + mORKS.RBTakeNoodleTask.Enqueue(orders[i]); + mORKS.VegtabNum++; + orders.RemoveAt(i); - // } - // } - // } - // Dictionary dic = new Dictionary(); - // newOrder.DishNum = mORKS.DishNumber; - // newOrder.VegatableNumber = mORKS.VegtabNum; - // dic.Add(subId, newOrder); - // mORKS.Conqueue.Enqueue(dic); - // mORKS.VegtabNum = 0; - // mORKS.DishNumber = 0; - // } - // } - //} + } + } + } + Dictionary dic = new Dictionary(); + newOrder.DishNum = mORKS.DishNumber; + newOrder.VegatableNumber = mORKS.VegtabNum; + dic.Add(subId, newOrder); + mORKS.Conqueue.Enqueue(dic); + mORKS.VegtabNum = 0; + mORKS.DishNumber = 0; + } + } + } ///// ///// IOT 广播消息命令 @@ -282,9 +132,6 @@ namespace BPASmartClient.MorkM //} int OrderCount = 0; - - public override DeviceClientType DeviceType => DeviceClientType.MORKM; - ///// ///// 数据解析 ///// @@ -378,26 +225,25 @@ namespace BPASmartClient.MorkM }); } - public void Main() + public override void MainTask() { - //ThreadManage.GetInstance.StartLong(new Action(() => - //{ - // mORKS.AllowRun = mORKS.InitComplete; - // GeneralConfig.Healthy = mORKS.Error && mORKS.InitComplete && !GeneralConfig.EnableLocalSimOrder; - // //GeneralConfig.Healthy = true; - // TakeBowlTask(); - - // TakeNoodleTask(); + mORKS.AllowRun = mORKS.InitComplete; + if (Json.Data.IsVerify) + IsHealth = mORKS.Error && mORKS.InitComplete; + else + IsHealth = true; - // OutNoodleTask(); + //if (mORKS.AllowRun) + //{ + TakeBowlTask(); - // SingleDetect(); + TakeNoodleTask(); - // TurntableControl(); + OutNoodleTask(); - // Thread.Sleep(100); + SingleDetect(); - //}), "MainTask"); + TurntableControl(); } /// @@ -425,24 +271,24 @@ namespace BPASmartClient.MorkM /// private void TurntableControl() { - //if (GeneralConfig.EnableLocalSimOrder) - //{ - // //不做轮询,直接取面,模拟订单使用 - // if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0) - // { - // if (mORKS.TurntableLowerLimit) - // { - // TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc); - // if (mORKS.RBTakeNoodleTask.ElementAt(0).Loc == mORKS.TurntableFeedbackloc) - // { - // mORKS.TurntableLocLists.Clear(); - // mORKS.AllowTakeNoodle = true; - // DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面"); - // } - // } - // } - //} - //else + if (GeneralConfig.EnableLocalSimOrder) + { + //不做轮询,直接取面,模拟订单使用 + if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0) + { + if (mORKS.TurntableLowerLimit) + { + TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc); + if (mORKS.RBTakeNoodleTask.ElementAt(0).Loc == mORKS.TurntableFeedbackloc) + { + mORKS.TurntableLocLists.Clear(); + mORKS.AllowTakeNoodle = true; + DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面"); + } + } + } + } + else { //正常轮询 if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0) @@ -453,7 +299,6 @@ namespace BPASmartClient.MorkM var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString()); if (mORKS.TurntableLowerLimit && res != null) { - //if (mORKS.RBTakeNoodleTask.ElementAt(0).Loc != mORKS.TurntableFeedbackloc) TurntableStart(mORKS.TurntableFeedbackloc); mORKS.TurntableLocLists.Clear(); mORKS.AllowTakeNoodle = true; @@ -532,7 +377,6 @@ namespace BPASmartClient.MorkM { values.Add(2);//分 values.Add(0);//秒 - // //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (loc * 6)}"), WriteType.HoldingRegisters, values.ToArray()); EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address =$"VW{ 116 + (loc * 6) }" , Value = values.ToArray() }); } else //荤菜 @@ -780,8 +624,8 @@ namespace BPASmartClient.MorkM private void WriteRecipeBoms() { List recipeBoms = new List(); - if (Json.Data.recipeBoms == null) return; - foreach (var item in Json.Data.recipeBoms.RecipeIds) + if (this.recipeBoms == null) return; + foreach (var item in this.recipeBoms.RecipeIds) { foreach (var rec in item.Recipes) { @@ -790,10 +634,9 @@ namespace BPASmartClient.MorkM } if (recipeBoms.Count > 0) { - //if (//ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray())) - //{ - // DeviceProcessLogShow("成功写入配方数据"); - //} + //配方数据地址范围:VW2000 - VW2278 + WriteData("VW2000", recipeBoms.ToArray()); + DeviceProcessLogShow("写配方成功"); } else { DeviceProcessLogShow("配方数据为空"); } } @@ -803,7 +646,7 @@ namespace BPASmartClient.MorkM /// private void TakeNoodleCompleteReset() { - ////ModbusTcpHelper.GetInstance.Write(1124, WriteType.Coils, false); + WriteData("M100.4", false); } /// @@ -814,8 +657,7 @@ namespace BPASmartClient.MorkM { if (num >= 1 && num <= 6) { - ushort addRess = (ushort)(1136 + num - 1); - //ModbusTcpHelper.GetInstance.Write(addRess, WriteType.Coils, false); + WriteData($"102.{num - 1}", false); DeviceProcessLogShow($"{num}号煮面口占用复位"); } @@ -827,7 +669,7 @@ namespace BPASmartClient.MorkM /// private void SetRecipeNumber(ushort num) { - //ModbusTcpHelper.GetInstance.Write(100, WriteType.HoldingRegisters, num); + WriteData("VW0", num); } /// @@ -839,8 +681,8 @@ namespace BPASmartClient.MorkM mORKS.CurrentLoc = loc; mORKS.TurntableInterlock = true; mORKS.TurntableLocLists.Add(loc); - //ModbusTcpHelper.GetInstance.Write(101, WriteType.HoldingRegisters, loc); - //ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true); + WriteData("VW2", loc); + WriteData("M0.5", true); } /// @@ -849,7 +691,7 @@ namespace BPASmartClient.MorkM /// private void SetFallNoodleLoc(ushort loc) { - //ModbusTcpHelper.GetInstance.Write(102, WriteType.HoldingRegisters, loc); + WriteData("VW4", loc); } /// @@ -858,7 +700,7 @@ namespace BPASmartClient.MorkM /// private void SetTakeNoodleLoc(ushort loc) { - //ModbusTcpHelper.GetInstance.Write(103, WriteType.HoldingRegisters, loc); + WriteData("VW6", loc); } /// @@ -869,11 +711,11 @@ namespace BPASmartClient.MorkM { if (loc == 10)//小碗 { - //ModbusTcpHelper.GetInstance.Write(321, WriteType.Coils, true); + WriteData("M0.1", true); } else if (loc == 11)//大碗 { - //ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true); + WriteData("M0.2", true); } } @@ -882,7 +724,7 @@ namespace BPASmartClient.MorkM /// private void RobotTakeNoodle() { - //ModbusTcpHelper.GetInstance.Write(323, WriteType.Coils, true); + WriteData("M0.3", true); } /// @@ -890,13 +732,7 @@ namespace BPASmartClient.MorkM /// private void RobotOutMeal() { - // ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true); - // var result = ModbusTcpHelper.GetInstance.Read(324, ReadType.Coils); - //if (result is bool res) - // while (!res) - // { - //ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true); - // } + WriteData("M0.4", true); } /// @@ -904,7 +740,7 @@ namespace BPASmartClient.MorkM /// private void ResetCookComplete() { - //ModbusTcpHelper.GetInstance.Write(1126, WriteType.Coils, false); + WriteData("M100.6", false); } /// @@ -912,7 +748,7 @@ namespace BPASmartClient.MorkM /// private void ResetAllowFallNoodle() { - //ModbusTcpHelper.GetInstance.Write(1123, WriteType.Coils, false); + WriteData("M100.3", false); } /// @@ -920,9 +756,9 @@ namespace BPASmartClient.MorkM /// public async void DeviceInit() { - //ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, true); + WriteData("M0.0", true); await Task.Delay(1000); - //ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, false); + WriteData("M0.0", false); } @@ -1000,7 +836,9 @@ namespace BPASmartClient.MorkM { if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); }), "WriteBools"); - ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice"); + ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");//设备初始化注册 + ActionManage.GetInstance.Register(new Action((o) => {SimOrder(o); }), "SimOrder");//模拟订单委托注册 + } private void WriteData(string address, object value) { @@ -1039,7 +877,7 @@ namespace BPASmartClient.MorkM public override void Stop() { - throw new NotImplementedException(); + } public override void ReadData() @@ -1149,11 +987,7 @@ namespace BPASmartClient.MorkM })); } - public override void MainTask() - { - throw new NotImplementedException(); - } - + #endregion diff --git a/BPASmartClient.MorkM/Model/GeneralConfig.cs b/BPASmartClient.MorkM/Model/GeneralConfig.cs new file mode 100644 index 00000000..bbc76b18 --- /dev/null +++ b/BPASmartClient.MorkM/Model/GeneralConfig.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkM.Model +{ + internal class GeneralConfig + { + /// + /// 激活本地模拟订单 + /// + public static bool EnableLocalSimOrder { get; set; } + } +} diff --git a/BPASmartClient.MorkM/View/Debug.xaml b/BPASmartClient.MorkM/View/Debug.xaml deleted file mode 100644 index 456ec5dc..00000000 --- a/BPASmartClient.MorkM/View/Debug.xaml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - -