Browse Source

初始化时增加菜品库相关数据的读取。

样式分支
yahaha 2 years ago
parent
commit
5d057000ed
5 changed files with 202 additions and 130 deletions
  1. +174
    -126
      BPASmartClient.MorkF/Control_MorkF.cs
  2. +23
    -2
      BPASmartClient.MorkF/Model/MaterialCoordinate.cs
  3. +2
    -2
      BPASmartClient.MorkF/Model/MaterialSurplus.cs
  4. +1
    -0
      BPASmartClient.MorkF/View/DebugView.xaml
  5. +2
    -0
      BPASmartClient.MorkF/ViewModel/DebugViewModel.cs

+ 174
- 126
BPASmartClient.MorkF/Control_MorkF.cs View File

@@ -154,7 +154,15 @@ namespace BPASmartClient.MorkF
//FoodLibInit();
Task2ReadMaterialData();

//Json<MaterialSurplus>.Read();
//读取坐标系
MaterialCoordinate materialCoordinate = ReadMaterialCoordinate();
if(materialCoordinate != null)
{
MaterialCoordinate.GetInstance().dicNoMaterialCoordinate = materialCoordinate.dicNoMaterialCoordinate;
MaterialCoordinate.GetInstance().MLCoordinateList = materialCoordinate.MLCoordinateList;
}
////菜品库编号与坐标系对象存储
//SaveMaterialCoordinate();
}

/// <summary>
@@ -170,6 +178,50 @@ namespace BPASmartClient.MorkF
//SingleProcess();
}

private static object saveMaterialLock = new object();
private void SaveMaterialData()
{
lock (saveMaterialLock)
{
Json<MaterialSurplus>.Data = MaterialSurplusOperation.GetInstance().materialSurplus;
Json<MaterialSurplus>.Save();
}
}

private static object saveMaterialCoordinateLock = new object();
/// <summary>
/// 保存当前的坐标系
/// </summary>
public void SaveMaterialCoordinate()
{
lock (saveMaterialLock)
{
Json<MaterialCoordinate>.Data = MaterialCoordinate.GetInstance();
Json<MaterialCoordinate>.Save();
}
}

/// <summary>
/// 读取坐标系
/// </summary>
/// <returns></returns>
private MaterialCoordinate ReadMaterialCoordinate()
{
try
{
lock (saveMaterialLock)
{
Json<MaterialCoordinate>.Read();
MaterialCoordinate materialCoordinate = Json<MaterialCoordinate>.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<object>((o) =>
{
ThreadManage.GetInstance().Start(new Action(() =>
@@ -728,7 +790,8 @@ namespace BPASmartClient.MorkF

#endregion

#region 菜品库PLC操作方法
#region 菜品库方法
#region PLC操作
/// <summary>
/// 菜品库数据写入
/// </summary>
@@ -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<MaterialSurplus>.Data = MaterialSurplusOperation.GetInstance().materialSurplus;
Json<MaterialSurplus>.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();
}
}

}
});
}


+ 23
- 2
BPASmartClient.MorkF/Model/MaterialCoordinate.cs View File

@@ -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<MaterialCoordinate>
{
public List<string> MLNumberList = new List<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"
public List<string> MLNumberList { get; set; } = new List<string>() { "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<Coordinate> MLCoordinateList = new List<Coordinate>()
public List<Coordinate> MLCoordinateList { get;set;} = new List<Coordinate>()
{ 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
}
}
}

/// <summary>
/// 更新键值对
/// </summary>
/// <param name="mlNumber"></param>
/// <param name="coordinate"></param>
/// <returns></returns>
public bool UpdateMLCoordinateList(string mlNumber,Coordinate coordinate)
{
if(dicNoMaterialCoordinate.ContainsKey(mlNumber))
{
dicNoMaterialCoordinate[mlNumber] = coordinate;
return true;
}
else
{
return false;
}
}

/// <summary>
/// 每个取菜点的编号与坐标字典
/// </summary>


+ 2
- 2
BPASmartClient.MorkF/Model/MaterialSurplus.cs View File

@@ -19,10 +19,10 @@ namespace BPASmartClient.MorkF
/// </summary>
/// <param name="number">编号</param>
/// <param name="surplus">余量</param>
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;


+ 1
- 0
BPASmartClient.MorkF/View/DebugView.xaml View File

@@ -76,6 +76,7 @@
<TextBox Text="{Binding RealY}" Width="70" Margin="5,0" VerticalAlignment="Top" IsReadOnly="True"/>
<TextBlock Text="{Binding PawPosition}" Margin="10,0,5,0"/>
<Button Content="菜品库初始化" Margin="10,0,5,0" Command="{Binding FoodLibInit}"/>
<Button Content="菜品库余量检测" Margin="10,0,5,0" Command="{Binding SurplusCheck}"/>
<Button Content="电磁阀启动" Margin="10,0,5,0" Command="{Binding StartElectromagnetism}"/>
<Button Content="电磁阀停止" Margin="10,0,5,0" Command="{Binding StopElectromagnetism}"/>
</WrapPanel>


+ 2
- 0
BPASmartClient.MorkF/ViewModel/DebugViewModel.cs View File

@@ -86,6 +86,7 @@ namespace BPASmartClient.MorkF.ViewModel

public RelayCommand SetNowPosition { get; set; }//设置机械臂当前坐标
public RelayCommand FoodLibInit { get; set; }//初始化
public RelayCommand SurplusCheck { get; set; }//初始化
public RelayCommand StartElectromagnetism { get; set; }//电磁阀启动
public RelayCommand StopElectromagnetism { get; set; }
public RelayCommand SetSpeed { get; set; }//速度设定
@@ -206,6 +207,7 @@ namespace BPASmartClient.MorkF.ViewModel
#region 菜品控制

FoodLibInit = new RelayCommand(() => { ActionManage.GetInstance.Send("FoodLibInit"); });//菜品库初始化
SurplusCheck = new RelayCommand(() => { ActionManage.GetInstance.Send("SurplusCheck"); });//菜品库初始化
StartElectromagnetism = new RelayCommand(() => { ActionManage.GetInstance.Send("Electromagnetism", new List<bool> { false }); });//电磁阀启动
StopElectromagnetism = new RelayCommand(() => { ActionManage.GetInstance.Send("Electromagnetism", new List<bool> { true });});//电磁阀关闭
SetSpeed = new RelayCommand(() =>


Loading…
Cancel
Save