diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 64b09331..b5c2d38e 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -154,7 +154,15 @@ namespace BPASmartClient.MorkF //FoodLibInit(); Task2ReadMaterialData(); - //Json.Read(); + //读取坐标系 + MaterialCoordinate materialCoordinate = ReadMaterialCoordinate(); + if(materialCoordinate != null) + { + MaterialCoordinate.GetInstance().dicNoMaterialCoordinate = materialCoordinate.dicNoMaterialCoordinate; + MaterialCoordinate.GetInstance().MLCoordinateList = materialCoordinate.MLCoordinateList; + } + ////菜品库编号与坐标系对象存储 + //SaveMaterialCoordinate(); } /// @@ -170,6 +178,50 @@ namespace BPASmartClient.MorkF //SingleProcess(); } + private static object saveMaterialLock = new object(); + private void SaveMaterialData() + { + lock (saveMaterialLock) + { + Json.Data = MaterialSurplusOperation.GetInstance().materialSurplus; + Json.Save(); + } + } + + private static object saveMaterialCoordinateLock = new object(); + /// + /// 保存当前的坐标系 + /// + public void SaveMaterialCoordinate() + { + lock (saveMaterialLock) + { + Json.Data = MaterialCoordinate.GetInstance(); + Json.Save(); + } + } + + /// + /// 读取坐标系 + /// + /// + private MaterialCoordinate ReadMaterialCoordinate() + { + try + { + lock (saveMaterialLock) + { + Json.Read(); + MaterialCoordinate materialCoordinate = Json.Data; + return materialCoordinate; + } + } + catch(Exception ex) + { + return null; + } + } + private void Task2ReadMaterialData() { ThreadManage.GetInstance().StartLong(new Action(() => { @@ -301,6 +353,16 @@ namespace BPASmartClient.MorkF FoodLibInit(); }), "FoodLibInit"); }), "FoodLibInit"); + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + if(!UpdateMaterialLibraryStock()) + { + MessageLog.GetInstance.Show("菜品库检测余量失败"); + } + }), "SurplusCheck"); + }), "SurplusCheck"); ActionManage.GetInstance.Register(new Action((o) => { ThreadManage.GetInstance().Start(new Action(() => @@ -728,7 +790,8 @@ namespace BPASmartClient.MorkF #endregion - #region 菜品库PLC操作方法 + #region 菜品库方法 + #region PLC操作 /// /// 菜品库数据写入 /// @@ -971,8 +1034,8 @@ namespace BPASmartClient.MorkF } //取反 - x -= 2 * x; - y -= 2 * y; + x = 0 - Math.Abs(x); + y = 0 - Math.Abs(y); if (x > 0 || y > 0) { MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]非法"); @@ -1073,6 +1136,7 @@ namespace BPASmartClient.MorkF MaterailLibrary_Write("M5.6", startOrStop); Thread.Sleep(200); } + #endregion //菜品库锁 object lock_Materail = new object(); @@ -1236,13 +1300,20 @@ namespace BPASmartClient.MorkF { try { - //判断是否初始化 - if(!ml_morkf.InitialComplete) + ////判断是否初始化 + //if (!ml_morkf.InitialComplete) + //{ + // MessageLog.GetInstance.Show("更新菜品库存量出错,菜品库未初始化"); + // return false; + //} + + if (MaterialCoordinate.GetInstance().dicNoMaterialCoordinate == null || MaterialCoordinate.GetInstance().dicNoMaterialCoordinate.Count != 27) { - MessageLog.GetInstance.Show("更新菜品库存量出错,菜品库未初始化"); + MessageLog.GetInstance.Show("更新菜品库存量出错,菜品库坐标系数据未建立"); return false; } + //遍历坐标系与位置,并根据位置更新菜品余量 foreach(var item in MaterialCoordinate.GetInstance().dicNoMaterialCoordinate) { //设置到抓菜处 @@ -1276,6 +1347,7 @@ namespace BPASmartClient.MorkF return false; } } + return true; } catch(Exception ex) @@ -1771,16 +1843,6 @@ namespace BPASmartClient.MorkF } #endregion - private static object saveMaterialLock = new object(); - private void SaveMaterialData() - { - lock(saveMaterialLock) - { - Json.Data = MaterialSurplusOperation.GetInstance().materialSurplus; - Json.Save(); - } - } - bool isInitialArrive = false; bool isInitialPaw = false; @@ -1832,122 +1894,108 @@ namespace BPASmartClient.MorkF }); } } - if(stirFry.stirFrymessage.materials.Count > 0) - { - MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials); - //foreach (var item in stirFry.stirFrymessage.materials) - //{ - // MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Add(new MaterialInfo - // { - // Id = item.Id, - // Key = item.Key, - // Name = item.Name, - // Loc = item.Loc, - // Qty = item.Qty, - // }); - //} - SaveMaterialData(); - } - } - MessageLog.GetInstance.Show("接收到小炒流程信息"); - //流程解析 - foreach (var item in LocalstirFryGoods) - { - MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}"); - // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程 - string MenuStep = "菜单步骤:"; - foreach (var items in item.StirPotActions) + MessageLog.GetInstance.Show("接收到小炒流程信息"); + //流程解析 + foreach (var item in LocalstirFryGoods) { - switch (items.Actions) + MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}"); + // morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程 + string MenuStep = "菜单步骤:"; + foreach (var items in item.StirPotActions) { - case nameof(StirFryPotActionEnum.加热开启): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位1): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位2): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位3): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位4): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位5): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位6): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位7): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位8): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位9): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置加热挡位10): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.停止加热): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.加调料): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.取原料): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.开启搅拌): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位1): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位2): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.设置搅拌挡位3): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.关闭搅拌): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.出餐启动): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.道菜启动): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.炒制菜品): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.搅拌臂原点位): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.搅拌臂炒制位): - MenuStep += items.Actions + ","; - break; - case nameof(StirFryPotActionEnum.洗锅): - MenuStep += items.Actions + ","; - break; - default: - break; - + switch (items.Actions) + { + case nameof(StirFryPotActionEnum.加热开启): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位1): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位2): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位3): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位4): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位5): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位6): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位7): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位8): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位9): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置加热挡位10): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.停止加热): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.加调料): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.取原料): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.开启搅拌): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位1): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位2): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.设置搅拌挡位3): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.关闭搅拌): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.出餐启动): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.道菜启动): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.炒制菜品): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.搅拌臂原点位): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.搅拌臂炒制位): + MenuStep += items.Actions + ","; + break; + case nameof(StirFryPotActionEnum.洗锅): + MenuStep += items.Actions + ","; + break; + default: + break; + + } } - - + MessageLog.GetInstance.Show(MenuStep); } - MessageLog.GetInstance.Show(MenuStep); - - + if (stirFry.stirFrymessage.materials.Count > 0) + { + MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials); + SaveMaterialData(); + } } + } }); } diff --git a/BPASmartClient.MorkF/Model/MaterialCoordinate.cs b/BPASmartClient.MorkF/Model/MaterialCoordinate.cs index 11f50db7..ab00316e 100644 --- a/BPASmartClient.MorkF/Model/MaterialCoordinate.cs +++ b/BPASmartClient.MorkF/Model/MaterialCoordinate.cs @@ -1,4 +1,5 @@ using BPA.Helper; +using Org.BouncyCastle.Asn1.X509; using System; using System.Collections.Generic; using System.Linq; @@ -9,10 +10,10 @@ namespace BPASmartClient.MorkF.Model { internal class MaterialCoordinate : Singleton { - public List MLNumberList = new List() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" + public List MLNumberList { get; set; } = new List() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" , "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27" }; - public List MLCoordinateList = new List() + public List MLCoordinateList { get;set;} = new List() { new Coordinate() { X = 34500, Y = 0 }, new Coordinate() { X = 34500, Y = 9000 } , new Coordinate() { X = 34500, Y = 0 } , //第1层 new Coordinate(){ X = 34500,Y=0} , new Coordinate() { X = 34500, Y = 83000 }, new Coordinate(){ X = 34500,Y=0}, //第1层 new Coordinate(){ X = 34500,Y=0} , new Coordinate() { X = 34500, Y = 0 }, new Coordinate(){ X = 34500,Y=0}, //第1层 @@ -38,6 +39,26 @@ namespace BPASmartClient.MorkF.Model } } } + + /// + /// 更新键值对 + /// + /// + /// + /// + public bool UpdateMLCoordinateList(string mlNumber,Coordinate coordinate) + { + if(dicNoMaterialCoordinate.ContainsKey(mlNumber)) + { + dicNoMaterialCoordinate[mlNumber] = coordinate; + return true; + } + else + { + return false; + } + } + /// /// 每个取菜点的编号与坐标字典 /// diff --git a/BPASmartClient.MorkF/Model/MaterialSurplus.cs b/BPASmartClient.MorkF/Model/MaterialSurplus.cs index f323ca9c..dc9d0e18 100644 --- a/BPASmartClient.MorkF/Model/MaterialSurplus.cs +++ b/BPASmartClient.MorkF/Model/MaterialSurplus.cs @@ -19,10 +19,10 @@ namespace BPASmartClient.MorkF /// /// 编号 /// 余量 - public bool UpdateSurplus(string id, int surplus) + public bool UpdateSurplus(string loc, int surplus) { //找到所有id对应的 - MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Id == id); + MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Loc == loc); if(material == null) { return false; diff --git a/BPASmartClient.MorkF/View/DebugView.xaml b/BPASmartClient.MorkF/View/DebugView.xaml index 9b3ad9a5..d38f9db3 100644 --- a/BPASmartClient.MorkF/View/DebugView.xaml +++ b/BPASmartClient.MorkF/View/DebugView.xaml @@ -76,6 +76,7 @@