Parcourir la source

攀华调试代码上传

样式分支
yahaha il y a 2 ans
Parent
révision
c21afa9642
11 fichiers modifiés avec 500 ajouts et 143 suppressions
  1. +2
    -0
      BPASmartClient.Business/Plugin/StatusMgr.cs
  2. +6
    -0
      BPASmartClient.Device/BaseDevice.cs
  3. +6
    -0
      BPASmartClient.Device/IDevice.cs
  4. +298
    -118
      BPASmartClient.MorkF/Control_MorkF.cs
  5. +21
    -1
      BPASmartClient.MorkF/Model/MaterialSurplus.cs
  6. +1
    -0
      BPASmartClient.MorkF/View/DebugView.xaml
  7. +1
    -1
      BPASmartClient.MorkF/View/DebugView.xaml.cs
  8. +10
    -3
      BPASmartClient.MorkF/View/LocalMenu.xaml
  9. +12
    -3
      BPASmartClient.MorkF/View/LocalMenu.xaml.cs
  10. +15
    -1
      BPASmartClient.MorkF/ViewModel/DebugViewModel.cs
  11. +128
    -16
      BPASmartClient.MorkF/ViewModel/LocalMenuViewModel.cs

+ 2
- 0
BPASmartClient.Business/Plugin/StatusMgr.cs Voir le fichier

@@ -56,8 +56,10 @@ namespace BPASmartClient.Business
foreach (var device in deviceMgr.GetDevices())
{
wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus();

deviceStatus.Healthy = device.IsHealth ? BPA.Message.Enum.DeviceHealthy.Health : BPA.Message.Enum.DeviceHealthy.UnHealth;
deviceStatus.DeviceType = device.DeviceType;
deviceStatus.BatchingInfo = device.BatchingInfos;
var msg = BPAPackage.Make(deviceStatus, device.DeviceId, device.DeviceType);
mqttMgr.Publish(TopicDefine.GetInstance().PushHeartbeatTopics[device.DeviceType], msg.Serialize());
}


+ 6
- 0
BPASmartClient.Device/BaseDevice.cs Voir le fichier

@@ -15,6 +15,7 @@ using System.Threading.Tasks;
using System.Collections.ObjectModel;
using BPASmartClient.Model.单片机;
using BPASmartClient.EventBus;
using BPA.Models;

namespace BPASmartClient.Device
{
@@ -88,6 +89,11 @@ namespace BPASmartClient.Device
/// </summary>
public List<object> Error { get; set; } = new List<object>();

/// <summary>
/// mork_F暂用余量列表
/// </summary>
public List<BatchingInfo> BatchingInfos { get; set; } = new List<BatchingInfo>();

/// <summary>
/// 设备变量监控
/// </summary>


+ 6
- 0
BPASmartClient.Device/IDevice.cs Voir le fichier

@@ -9,6 +9,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using BPA.Models;

namespace BPASmartClient.Device
{
@@ -53,6 +54,10 @@ namespace BPASmartClient.Device
/// </summary>
public List<object> Error { get; set; }
/// <summary>
/// mork_F暂用余量列表
/// </summary>
public List<BatchingInfo> BatchingInfos { get; set; }
/// <summary>
/// 设备变量信息
/// </summary>
ObservableCollection<VariableMonitor> variableMonitors { get; set; }
@@ -116,6 +121,7 @@ namespace BPASmartClient.Device
/// <param name="field"></param>
object GetPropertyValue(object info, string field);


Action<int, object> AddErrorAction { get; set; }
Action<int, object> DeleteErrorAction { get; set; }
}


+ 298
- 118
BPASmartClient.MorkF/Control_MorkF.cs Voir le fichier

@@ -15,6 +15,7 @@ using System.Collections.Concurrent;
using System.Windows.Documents;
using BPASmartClient.Business;
using Microsoft.CodeAnalysis;
using BPASmartClient.MorkF.ViewModel;

namespace BPASmartClient.MorkF
{
@@ -95,6 +96,16 @@ namespace BPASmartClient.MorkF
public AutoResetEvent minorReset = new AutoResetEvent(false);
public AutoResetEvent mainReset = new AutoResetEvent(false);

/// <summary>
/// 等待炒制数量
/// </summary>
private int StagingFryCount { get; set; }

/// <summary>
/// 正在炒制数量
/// </summary>
private int FryingCount { get; set; }

/// <summary>
/// 炒锅编号与炒锅实例
/// </summary>
@@ -141,6 +152,17 @@ namespace BPASmartClient.MorkF
///
/// </summary>
private List<StatsModel> statsModels = new List<StatsModel>();

/// <summary>
/// 暂存使用菜品量
/// </summary>
private List<GoodBatchings> stagingGoodBatchings = new List<GoodBatchings>();
/// <summary>
/// 是否为本地炒菜模式,默认为联网的
/// </summary>
private bool isLocalFryingMode { get; set; } = false;

/// <summary>
/// 入口
/// </summary>
@@ -162,6 +184,9 @@ namespace BPASmartClient.MorkF
Task2ReadMaterialData();

ScreenDataServer();
Json<MaterialAndFryingTime>.Read();
//更新菜品余量
UpdateMaterialSurplus();

//读取坐标系
MaterialCoordinate materialCoordinate = ReadMaterialCoordinate();
@@ -194,6 +219,7 @@ namespace BPASmartClient.MorkF
MainProcessMaterial();
//MinorProcessExcute();
//SingleProcess();

}

private static object saveMaterialLock = new object();
@@ -256,12 +282,12 @@ namespace BPASmartClient.MorkF
{
if (isInitialArrive == false)
{
MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false");
//MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false");
isInitialArrive = true;
}
else
{
MessageLog.GetInstance.Show("到达上升沿为true");
//MessageLog.GetInstance.Show("到达上升沿为true");
ml_morkf.ArriveComplete = true;
isInitialArrive = true;
}
@@ -361,6 +387,13 @@ namespace BPASmartClient.MorkF
ActionManage.GetInstance.Register(StartOrderMain, "开始下单");
ActionManage.GetInstance.Register(StartLocalOrder, "StartLocalOrder");
ActionManage.GetInstance.Register(StopLocalOrder, "StopLocalOrder");
ActionManage.GetInstance.Register(new Action<object>((o) =>
{
if (o is string materialName)
{
NewStartLocalOrder(materialName);
}
}), "NewStartLocalOrder");
#endregion

#region 菜品库
@@ -372,6 +405,10 @@ namespace BPASmartClient.MorkF
}), "FoodLibInit");
}), "FoodLibInit");
ActionManage.GetInstance.Register(new Action(() =>
{
isLocalFryingMode = !isLocalFryingMode;
}), "ModeChange");
ActionManage.GetInstance.Register(new Action(() =>
{
ThreadManage.GetInstance().Start(new Action(() =>
{
@@ -705,7 +742,7 @@ namespace BPASmartClient.MorkF

private void StartLocalOrder()
{
if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
{
StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
@@ -718,6 +755,43 @@ namespace BPASmartClient.MorkF
}
}

private void NewStartLocalOrder(string materialName)
{
//if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
//if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
//{
// StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
// {
// SuborderId = Guid.NewGuid().ToString(),
// StirPotActions = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions,
// GoodName = "本地菜品"
// });
// MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
//}
if (Json<MaterialAndFryingTime>.Data.materials.Count > 0)
{
if (!Json<MaterialAndFryingTime>.Data.materials.ContainsKey(materialName))
{
return;
}

List<PotActions> potActions = new List<PotActions>();

foreach(var item in Json<MaterialAndFryingTime>.Data.materials[materialName])
{
potActions.Add(item);
}

StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
{
SuborderId = Guid.NewGuid().ToString(),
StirPotActions = potActions,
GoodName = materialName
});
MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
}
}

/// <summary>
/// 停止本地菜单炒制
/// </summary>
@@ -938,7 +1012,7 @@ namespace BPASmartClient.MorkF
return false;
}

MessageLog.GetInstance.Show("爪子去到1号位");
//MessageLog.GetInstance.Show("爪子去到1号位");
MaterailLibrary_Write("M1.0", true);

Thread.Sleep(500);
@@ -955,7 +1029,7 @@ namespace BPASmartClient.MorkF

Thread.Sleep(300);

MessageLog.GetInstance.Show("爪子去到1号位完成");
//MessageLog.GetInstance.Show("爪子去到1号位完成");
return true;
}

@@ -967,7 +1041,7 @@ namespace BPASmartClient.MorkF
return false;
}

MessageLog.GetInstance.Show("爪子去到2号位");
//MessageLog.GetInstance.Show("爪子去到2号位");
MaterailLibrary_Write("M1.1", true);

Thread.Sleep(500);
@@ -984,7 +1058,7 @@ namespace BPASmartClient.MorkF

Thread.Sleep(300);

MessageLog.GetInstance.Show("爪子去到2号位完成");
//MessageLog.GetInstance.Show("爪子去到2号位完成");
return true;
}

@@ -996,7 +1070,7 @@ namespace BPASmartClient.MorkF
return false;
}

MessageLog.GetInstance.Show("爪子去到3号位");
//MessageLog.GetInstance.Show("爪子去到3号位");
MaterailLibrary_Write("M1.2", true);

Thread.Sleep(500);
@@ -1013,7 +1087,7 @@ namespace BPASmartClient.MorkF

Thread.Sleep(300);

MessageLog.GetInstance.Show("爪子去到3号位完成");
//MessageLog.GetInstance.Show("爪子去到3号位完成");
return true;
}

@@ -1029,8 +1103,8 @@ namespace BPASmartClient.MorkF
MaterailLibrary_Write("M0.3", false);
Thread.Sleep(3000);

MessageLog.GetInstance.Show("1号测距开启完成");
MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");
//MessageLog.GetInstance.Show("1号测距开启完成");
//MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");

ActionManage.GetInstance.Send("GetDistanceCallBack", new List<string> { "1",ml_morkf.LaserDistance.ToString() });//通知获取测距界面

@@ -1048,8 +1122,8 @@ namespace BPASmartClient.MorkF
MaterailLibrary_Write("M0.4", false);
Thread.Sleep(3000);

MessageLog.GetInstance.Show("2号测距开启完成");
MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");
//MessageLog.GetInstance.Show("2号测距开启完成");
//MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");

ActionManage.GetInstance.Send("GetDistanceCallBack", new List<string> { "2", ml_morkf.LaserDistance.ToString() });//通知获取测距界面

@@ -1067,14 +1141,24 @@ namespace BPASmartClient.MorkF
MaterailLibrary_Write("M0.5", false);
Thread.Sleep(3000);

MessageLog.GetInstance.Show("3号测距开启完成");
MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");
//MessageLog.GetInstance.Show("3号测距开启完成");
//MessageLog.GetInstance.Show($"传感器的距离{ml_morkf.LaserDistance}");

ActionManage.GetInstance.Send("GetDistanceCallBack", new List<string> { "3", ml_morkf.LaserDistance.ToString() });//通知获取测距界面

return true;
}

/// <summary>
/// 写入传感器距离
/// </summary>
/// <param name="speed"></param>
public void WriteSpeed(int speed)
{
MaterailLibrary_Write("VD808", speed);
Thread.Sleep(400);
}

/// <summary>
/// 写入传感器距离
/// </summary>
@@ -1100,7 +1184,7 @@ namespace BPASmartClient.MorkF

Thread.Sleep(400);

//获取传感器1的距离
////获取传感器1的距离
ret &= GetDistance_1();
}
//是否在第二层菜品库
@@ -1157,7 +1241,7 @@ namespace BPASmartClient.MorkF

Thread.Sleep(200);

MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]");
//MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]");

//到达置为false
ml_morkf.ArriveComplete = false;
@@ -1183,7 +1267,7 @@ namespace BPASmartClient.MorkF
}
}

MessageLog.GetInstance.Show("机械臂移动操作完成");
//MessageLog.GetInstance.Show("机械臂移动操作完成");

Thread.Sleep(500);

@@ -1200,7 +1284,7 @@ namespace BPASmartClient.MorkF
//取反
x -= 2 * x;
y -= 2 * y;
MessageLog.GetInstance.Show($"设置机械臂当前坐标为[{x},{y}]");
//MessageLog.GetInstance.Show($"设置机械臂当前坐标为[{x},{y}]");
MaterailLibrary_Write("VD828", x);
Thread.Sleep(200);
MaterailLibrary_Write("VD832", y);
@@ -1300,6 +1384,8 @@ namespace BPASmartClient.MorkF
return false;
}

WriteSpeed(10000);

//关闭电磁阀
Electromagnetism(new List<bool> { true });
Thread.Sleep(500);
@@ -1357,8 +1443,13 @@ namespace BPASmartClient.MorkF
return false;
}

//收缩爪子
PawShrink();
WriteSpeed(50000);

ThreadManage.GetInstance().Start(new Action(() =>
{
//收缩爪子
PawShrink();
}), "GetMaterialPawShrink");

//判断炒锅是否可以放盒
for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++)
@@ -1366,7 +1457,7 @@ namespace BPASmartClient.MorkF
Thread.Sleep(materialSleepTime);
if (i >= materialSleepCount - 1)
{
MessageLog.GetInstance.Show("等待炒锅允许放盒超时");
MessageLog.GetInstance.ShowEx("等待炒锅允许放盒超时");
return false;
}
}
@@ -1616,11 +1707,11 @@ namespace BPASmartClient.MorkF
}

//盒子高度为45,但是需要考虑到误差,不足35,则认为为空
int boxCount = heightDifferent / 35;
int boxCount = (heightDifferent + 5) / 35;
count = boxCount;
if (count == 0)
{
MessageLog.GetInstance.Show("菜品库为空");
MessageLog.GetInstance.ShowEx("菜品库为空");
return Laser2CoordinateState.MaterialEmpty;
}
else if(count > 6)
@@ -1632,47 +1723,6 @@ namespace BPASmartClient.MorkF
{
return Laser2CoordinateState.MaterialNormal;
}
//if (heightDifferent <= 20)
//{
// MessageLog.GetInstance.ShowEx("错误:菜品量为空");
// return Laser2CoordinateState.MaterialEmpty;
//}

////菜盒放多了
//if (distance < 6)
//{
// return Laser2CoordinateState.MaterialOverdo;
//}
//else if (distance >= 6 && distance < 10)
//{
// count = 5;
// return Laser2CoordinateState.MaterialNormal;
//}
//else if (distance >= 10 && distance < 14)
//{
// count = 4;
// return Laser2CoordinateState.MaterialNormal;
//}
//else if (distance >= 14 && distance < 19)
//{
// count = 3;
// return Laser2CoordinateState.MaterialNormal;
//}
//else if (distance >= 19 && distance < 23)
//{
// count = 2;
// return Laser2CoordinateState.MaterialNormal;
//}
//else if (distance >= 23 && distance < 28)
//{
// count = 1;
// return Laser2CoordinateState.MaterialNormal;
//}
//else
//{
// count = 0;
// return Laser2CoordinateState.MaterialEmpty;
//}
}
catch (Exception ex)
{
@@ -1697,10 +1747,6 @@ namespace BPASmartClient.MorkF
MessageLog.GetInstance.ShowEx($"炒锅{materialOperation.fryNum}获取菜品[{materialOperation.materialInfo.Name}]失败,找不到对应位置");
return;
}
lock (lock_Materail)
{
ml_morkf.MaterailIsWorking = true;
}
//取菜操作
ret = GetMaterail(myCoordinate.X, myCoordinate.Y, materialOperation.fryNum);
}
@@ -1710,16 +1756,32 @@ namespace BPASmartClient.MorkF
}
finally
{
lock (lock_Materail)
//本地炒制不进行菜品数量检查
if(!isLocalFryingMode)
{
ml_morkf.MaterailIsWorking = false;
}
if (ret == true)
{
//指定位置菜品减一
MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc);
SaveMaterialData();
GoodBatchings goodBatchings = stagingGoodBatchings.Find(o => o.BatchingId == materialOperation.materialInfo.Key);
if (ret == true)
{
if (true)
{
if (goodBatchings != null)
{
//指定位置菜品减一
MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc, goodBatchings.BatchingCount);
}
}
else
{
//指定位置菜品减一
MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc);
}

SaveMaterialData();
}
//移出占用菜品
stagingGoodBatchings.Remove(goodBatchings);
}
ml_morkf.MaterailIsWorking = false;
}

}), $"菜品库操作");
@@ -1877,6 +1939,7 @@ namespace BPASmartClient.MorkF
public bool OutFood(int num,out string error,bool isMaterial = false)
{
bool ret = true;
error = string.Empty;

if (!morkFs.ContainsKey(num))
{
@@ -1890,17 +1953,19 @@ namespace BPASmartClient.MorkF
if (isMaterial)
{
//判断是否完成取菜
for (i = 0; i < materialSleepCount && !morkFs[num].GetMaterialComplete; i++)
for (i = 0; i < materialSleepCount*2 && !morkFs[num].GetMaterialComplete; i++)
{
if (i == 10)
{
//停止搅拌
StopStir(num);
//StopStir(num);
//搅拌设置为1档
SetStir(new List<int> { 1 }, i);
//火力设置为2档
SetFire(new List<int> { 2 }, num);
SetFire(new List<int> { 1 }, num);
}
Thread.Sleep(materialSleepTime);
if (i >= materialSleepCount - 1)
if (i >= materialSleepCount * 2 - 1)
{
error = $"炒锅{num}倒菜超时:未能等到取菜完成,请检查菜品库是否正常运行";
MessageLog.GetInstance.ShowEx($"炒锅{num}倒菜超时:未能等到取菜完成");
@@ -1911,14 +1976,21 @@ namespace BPASmartClient.MorkF
if (i > 9)
{
//开启搅拌
StartStir(num);
//StartStir(num);
//搅拌设置为原本搅拌档位
SetStir(new List<int> { morkFs[num].Stir }, i);
//火力设置回原本火力
SetFire(new List<int> { morkFs[num].Fire }, num);
}
}

if(!ret)
{
return ret;
}

FirePot_Write("LB3", true, num);
MessageLog.GetInstance.Show("倒菜启动");
//MessageLog.GetInstance.Show("倒菜启动");

Thread.Sleep(500);

@@ -1935,9 +2007,8 @@ namespace BPASmartClient.MorkF

FirePot_Write("LB3", false, num);
Thread.Sleep(200);
MessageLog.GetInstance.Show("倒菜完成");
//MessageLog.GetInstance.Show("倒菜完成");
morkFs[num].GetMaterialComplete = false;
error = string.Empty;
return ret;
}
//搅拌臂去原点位
@@ -1949,7 +2020,7 @@ namespace BPASmartClient.MorkF
}

FirePot_Write("LB5", true, num);
MessageLog.GetInstance.Show("搅拌臂去原点位");
//MessageLog.GetInstance.Show("搅拌臂去原点位");

for (int i = 0; i < sleepCount && !morkFs[num].ArmOnOrigin; i++)
{
@@ -1962,7 +2033,7 @@ namespace BPASmartClient.MorkF

FirePot_Write("LB5", false, num);
Thread.Sleep(200);
MessageLog.GetInstance.Show("搅拌臂到达原点位");
//MessageLog.GetInstance.Show("搅拌臂到达原点位");
}

//搅拌臂去炒制位
@@ -1979,7 +2050,7 @@ namespace BPASmartClient.MorkF
if (!morkFs[num].ArmOnWorking/* && morkFs[num].PotOnOrigin*/)
{
FirePot_Write("LB6", true, num);
MessageLog.GetInstance.Show("搅拌臂去工作位");
//MessageLog.GetInstance.Show("搅拌臂去工作位");

for (int i = 0; i < sleepCount && !morkFs[num].ArmOnWorking; i++)
{
@@ -1999,7 +2070,7 @@ namespace BPASmartClient.MorkF

FirePot_Write("LB6", false, num);
Thread.Sleep(200);
MessageLog.GetInstance.Show("搅拌臂到达工作位");
//MessageLog.GetInstance.Show("搅拌臂到达工作位");
return ret;
}

@@ -2022,7 +2093,7 @@ namespace BPASmartClient.MorkF
return;
}
FirePot_Write("LB4", true, num);
Thread.Sleep(200);
Thread.Sleep(500);
FirePot_Write("LB4", false, num);
}
//加热挡位设定
@@ -2274,7 +2345,7 @@ namespace BPASmartClient.MorkF
}

/// <summary>
/// 数据解析
/// 订单数据解析
/// </summary>
private void DataParse()
{
@@ -2293,24 +2364,65 @@ namespace BPASmartClient.MorkF
DeviceProcessLogShow($"接收到{OrderCount}次订单");
Enum.GetNames(typeof(StirFryPotActionEnum));

if(true)
{

var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.GoodsKey);//匹配订单对应制作流程
if(order.MorkOrder.GoodBatchings.Count <= 0)
{
return;
}

if(order.MorkOrder.DeviceId != DeviceId)
MaterialSurplus materialSurplus = MaterialSurplusOperation.GetInstance().materialSurplus;

if (order.MorkOrder.DeviceId != DeviceId)
{
return;
}

///遍历并增加到待用菜品库
foreach(var goodBatching in order.MorkOrder.GoodBatchings)
{
MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Find( o => o.Key == goodBatching.BatchingId);
if (materialInfo != null)
{
//if
if(Convert.ToInt32(materialInfo.Qty) - goodBatching.BatchingCount < 0)
{
MessageLog.GetInstance.ShowEx($"{materialInfo.Name}不够,请更新菜品库,并点击检测");
return;
}
else
{
//查找是否有该菜品
GoodBatchings existingGoodBatchings = stagingGoodBatchings.Find( o => o.BatchingId== goodBatching.BatchingId );
//判断是否存在
if (existingGoodBatchings != null)
{
existingGoodBatchings.BatchingCount += goodBatching.BatchingCount;
}
else
{
stagingGoodBatchings.Add(goodBatching);
}
}
}
else
{
MessageLog.GetInstance.ShowEx($"ID为{goodBatching.BatchingId}的菜品无法找到,请联系售后人员");
return;
}
}

//var res = LocalstirFryGoods[0];
if (res != null)
{
/* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
//添加到带炒小炒队列
//添加到带炒小炒队列
if (StirFryGoodsQuenes.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
{
//待炒数量+1
StagingFryCount++;
lock (lock_MainProcessExcute)
{
StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
@@ -2323,6 +2435,11 @@ namespace BPASmartClient.MorkF
}
}

}
else
{
NewStartLocalOrder("莲白回锅");
}
////暂时使用本地菜单
//StartLocalOrder();
}
@@ -2333,6 +2450,11 @@ namespace BPASmartClient.MorkF

private object lock_MainProcessExcute = new object();
/// <summary>
/// 倒菜锁
/// </summary>
private object lock_OutMeal = new object();

/// <summary>
/// 炒锅主流程
/// </summary>
@@ -2344,7 +2466,7 @@ namespace BPASmartClient.MorkF
//遍历炒锅,找到合适、空闲的炒锅
for(int i = 0;i<morkFs.Count;i++)
{
if (/*morkFs[i].AutoMode && morkFs[i].FryPot1_InitialComplete && ml_morkf.InitialComplete &&*/
if (morkFs[i].AutoMode && morkFs[i].FryPot1_InitialComplete && ml_morkf.InitialComplete &&
!morkFs[i].FryWorking)//炒锅在自动状态&&初始化完成&&菜品库初始化&&是否在炒菜中
{
Thread.Sleep(5000);
@@ -2367,6 +2489,10 @@ namespace BPASmartClient.MorkF
{
try
{
//待炒数量-1
StagingFryCount--;
//正在炒制数量+1
FryingCount++;
int testi = 0;
string error = string.Empty;
//初始化大屏
@@ -2390,7 +2516,7 @@ namespace BPASmartClient.MorkF
if(ret == false)
{
MessageLog.GetInstance.ShowEx("上一步操作未成功");
//break;
break;
}

////调试大屏用代码
@@ -2467,28 +2593,14 @@ namespace BPASmartClient.MorkF
//炒锅取菜状态置为未取到
morkFs[i].GetMaterialComplete = false;

if (true)
if (isLocalFryingMode)
{
///测试用代码
if (testi % 2 == 0)
{
MaterialInfo materialInfo = new MaterialInfo();
materialInfo.Loc = "5";
materialInfo.Qty = 10;
materialInfo.Name = "肉片";
materialInfo.Id = "1232131";
materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
}
else
{
MaterialInfo materialInfo = new MaterialInfo();
materialInfo.Loc = "24";
materialInfo.Qty = 10;
materialInfo.Name = "青椒";
materialInfo.Id = "1232131";
materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
}
testi++;
MaterialInfo materialInfo = new MaterialInfo();
materialInfo.Loc = potActions.SeasoningLists[0].Loc.ToString();
materialInfo.Id = "1232131";
materialInfo.Name = "本地炒制未知菜品";
materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
//testi++;
}
else
{
@@ -2536,6 +2648,12 @@ namespace BPASmartClient.MorkF
MessageLog.GetInstance.Show(potActions.Actions);
break;
case nameof(StirFryPotActionEnum.出餐启动):
//停止搅拌
StopStir(i);
//回原点位
StirArmGoOrigin(i);
//出餐启动
OutMeal(i);
MessageLog.GetInstance.Show(potActions.Actions);
break;
case nameof(StirFryPotActionEnum.道菜启动):
@@ -2553,7 +2671,11 @@ namespace BPASmartClient.MorkF
MessageLog.GetInstance.Show(potActions.Actions);
break;
case nameof(StirFryPotActionEnum.搅拌臂炒制位):
ret = StirArmGoWork(i,out error);
//出餐时,不允许搅拌臂去炒制位
lock (lock_OutMeal)
{
ret = StirArmGoWork(i, out error);
}
if (ret == false)
{
alarmModel.Add(new AlarmModel() { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = error });
@@ -2574,6 +2696,16 @@ namespace BPASmartClient.MorkF
//回原点位
StirArmGoOrigin(i);

//同时只能允许有一个出餐
lock(lock_OutMeal)
{
//出餐启动
OutMeal(i);
//等待25s出餐完毕
Thread.Sleep(25000);

}

MessageLog.GetInstance.Show($"菜品{res.GoodName}完成");

//菜品统计数量+1
@@ -2604,6 +2736,8 @@ namespace BPASmartClient.MorkF
}
finally
{
//正在炒制数量-1
FryingCount--;
nowStirFryGood[i] = null;
//炒完后出队列
morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue);
@@ -2620,6 +2754,51 @@ namespace BPASmartClient.MorkF
}
}

/// <summary>
/// 更新菜品库的余量
/// </summary>
private void UpdateMaterialSurplus()
{
ThreadManage.GetInstance().StartLong(new Action(() => {

List<MaterialInfo> listSurplus = MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus;

if (listSurplus == null)
{
return;
}

foreach (var surplus in listSurplus)
{
//找到已有的余量表
var batchingInfo = BatchingInfos.Find(o => o.BatchingId == surplus.Key);
//从当前下单
var stagingGoodBatching = stagingGoodBatchings.Find(o => o.BatchingId == surplus.Key);

//暂存的数量
int stagingCount = 0;

if(stagingGoodBatching != null)
{
stagingCount = stagingGoodBatching.BatchingCount;
}

if (batchingInfo == null)
{
//为空就新增
BatchingInfos.Add(new BatchingInfo() { BatchingCount = Convert.ToInt32(surplus.Qty) - stagingCount, BatchingLoc = surplus.Loc, BatchingId = surplus.Key });
}
else
{
batchingInfo.BatchingLoc = surplus.Loc;
batchingInfo.BatchingCount = Convert.ToInt32(surplus.Qty) - stagingCount;
}
}
Thread.Sleep(1000);
return;
}), "UpdateMaterialSurplus", true);
}

/// <summary>
/// 菜品库主流程
/// </summary>
@@ -2633,6 +2812,7 @@ namespace BPASmartClient.MorkF
//待菜品库操作列出队列
if (materialOperationQuenes.TryDequeue(out var res))
{
Thread.Sleep(1000);

ml_morkf.MaterailIsWorking = true;
MessageLog.GetInstance.Show("开始操作菜品库");
@@ -2691,7 +2871,7 @@ namespace BPASmartClient.MorkF
LocalMqtt.GetInstance.Publish(maxWok);
Thread.Sleep(1000);

}), "大屏数据上报");
}), "大屏数据上报",true);

}



+ 21
- 1
BPASmartClient.MorkF/Model/MaterialSurplus.cs Voir le fichier

@@ -116,6 +116,26 @@ namespace BPASmartClient.MorkF
}
}

/// <summary>
/// 余量减少
/// </summary>
/// <param name="loc">菜品位置</param>
/// <param name="count">菜品减少数量</param>
/// <returns></returns>
public bool ReduceSurplus(string loc,int count)
{
MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
if (materialInfo != null)
{
materialInfo.Qty -= count;
return true;
}
else
{
return false;
}
}

/// <summary>
/// 余量增加
/// </summary>
@@ -192,7 +212,7 @@ namespace BPASmartClient.MorkF
/// <summary>
/// 余量字典,key:菜品库编号,value:余量
/// </summary>
public List<MaterialInfo> dicSurplus = new List<MaterialInfo>();
public List<MaterialInfo> dicSurplus { get; set; } = new List<MaterialInfo>();

//public MaterialSurplus()
//{


+ 1
- 0
BPASmartClient.MorkF/View/DebugView.xaml Voir le fichier

@@ -59,6 +59,7 @@
<Button Content="本地模拟流程配置" Click="Button_Click"/>
<Button Content="本地模拟流程下单" Margin="10,0" Command="{Binding StartLocalOrder}" Cursor="Hand"/>
<Button Content="停止炒菜" Margin="10,0" Command="{Binding StopLocalOrder}" Cursor="Hand"/>
<Button Content="{Binding ModeButten}" Margin="10,0" Command="{Binding ModeChange}" Cursor="Hand"/>
</WrapPanel>
</Grid>



+ 1
- 1
BPASmartClient.MorkF/View/DebugView.xaml.cs Voir le fichier

@@ -30,9 +30,9 @@ namespace BPASmartClient.MorkF.View

}

LocalMenu localMenu = new LocalMenu();
private void Button_Click(object sender, RoutedEventArgs e)
{
LocalMenu localMenu = new LocalMenu();
localMenu.ShowDialog();
}
}


+ 10
- 3
BPASmartClient.MorkF/View/LocalMenu.xaml Voir le fichier

@@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:BPASmartClient.MorkF.View"
xmlns:vm="clr-namespace:BPASmartClient.MorkF.ViewModel"
mc:Ignorable="d"
@@ -49,9 +50,15 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="增加步骤" Command="{Binding AddFryTime}" Width="120" Height="40" Margin="10,0"/>
<Button Content="保存" Command="{Binding Save}" Width="120" Height="40" Margin="10,0"/>
<Button Content="退出" Click="Button_Click" Width="120" Height="40" Margin="10,0"/>
<ComboBox Name="Materials" SelectionChanged="Materials_SelectionChanged" ItemsSource="{Binding MaterialNames}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBox Text="{Binding MaterialName}" Width="80" Height="40" Margin="10,0"/>
<Button Content="增加菜谱" Command="{Binding AddMaterial}" Width="80" Height="40" Margin="10,0"/>
<Button Content="下单" Command="{Binding NewStartLocalMaterial}" Width="80" Height="40" Margin="10,0"/>
<!--<Button Content="菜谱重命名" Command="{Binding RenameMaterial}" Width="80" Height="40" Margin="10,0"/>
<Button Content="删除菜谱" Command="{Binding DeleteMaterial}" Width="80" Height="40" Margin="10,0"/>-->
<Button Content="增加步骤" Command="{Binding AddFryTime}" Width="80" Height="40" Margin="10,0"/>
<Button Content="保存" Command="{Binding Save}" Width="80" Height="40" Margin="10,0"/>
<Button Content="退出" Click="Button_Click" Width="80" Height="40" Margin="10,0"/>
</StackPanel>
<Grid Grid.Row="1" Width="600" HorizontalAlignment="Center" VerticalAlignment="Center">


+ 12
- 3
BPASmartClient.MorkF/View/LocalMenu.xaml.cs Voir le fichier

@@ -46,13 +46,13 @@ namespace BPASmartClient.MorkF.View
ActionManage.GetInstance.CancelRegister ("LocalMenuClose");
ActionManage.GetInstance.Register(new Action(() =>
{
this.Close();
this.Hide();
}), "LocalMenuClose");
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
this.Hide();
}

private int GetCurrentIndex(GetPositionDelegate getPosition)
@@ -231,7 +231,16 @@ namespace BPASmartClient.MorkF.View
this.DragMove();
}

private void Materials_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string str = Materials.SelectedValue.ToString();
if(str != string.Empty)
{
ActionManage.GetInstance.Send("LoacMenuSelectMaterial", str);
}
}



/// <summary>
/// 移动效果


+ 15
- 1
BPASmartClient.MorkF/ViewModel/DebugViewModel.cs Voir le fichier

@@ -35,6 +35,7 @@ namespace BPASmartClient.MorkF.ViewModel
public RelayCommand StartOrder { get; set; }
public RelayCommand StartLocalOrder { get; set; }
public RelayCommand StopLocalOrder { get; set; }
public RelayCommand ModeChange { get; set; }


#endregion
@@ -83,7 +84,9 @@ namespace BPASmartClient.MorkF.ViewModel

public string ArmButtonName { get { return _ArmButtonName; } set { _ArmButtonName = value; OnPropertyChanged(); } }
private string _ArmButtonName = "启动";

public string ModeButten { get { return _ModeButten; } set { _ModeButten = value; OnPropertyChanged(); } }
private string _ModeButten = "联网模式";
public RelayCommand SetNowPosition { get; set; }//设置机械臂当前坐标
public RelayCommand FoodLibInit { get; set; }//初始化
public RelayCommand SurplusCheck { get; set; }//初始化
@@ -204,6 +207,17 @@ namespace BPASmartClient.MorkF.ViewModel
StartOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StartOrder", FoodMenuID); });
StartLocalOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StartLocalOrder"); });
StopLocalOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StopLocalOrder"); });
ModeChange = new RelayCommand(() => {
ActionManage.GetInstance.Send("ModeChange");
if(ModeButten == "联网模式")
{
ModeButten = "本地模式";
}
else
{
ModeButten = "联网模式";
}
});
#endregion

#region 菜品控制


+ 128
- 16
BPASmartClient.MorkF/ViewModel/LocalMenuViewModel.cs Voir le fichier

@@ -9,21 +9,35 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace BPASmartClient.MorkF.ViewModel
{
partial class LocalMenuViewModel:ObservableObject
{
public ObservableCollection<PotActions> PotActionStep { get; set; } = new ObservableCollection<PotActions>();
public ObservableCollection<PotActions> PotActionStep { get { return _PotActionStep; }
set { _PotActionStep = value; OnPropertyChanged(); } }
private ObservableCollection<PotActions> _PotActionStep = new ObservableCollection<PotActions>();

public ObservableCollection<string> strPotActions { get; set; } = new ObservableCollection<string>();
public string MaterialName { get; set; }

public string SelectMaterialName { get; set; }

public ObservableCollection<string> MaterialNames { get; set; } = new ObservableCollection<string>();


public ObservableCollection<string> strPotActions { get; set; } = new ObservableCollection<string>();

public MaterialAndFryingTime materialAndFryingTime { get; set; } = new MaterialAndFryingTime();

public RelayCommand<object> Delete { get; set; }
public RelayCommand AddFryTime { get; set; }
public RelayCommand NewStartLocalMaterial { get; set; }
public RelayCommand AddMaterial { get; set; }
public RelayCommand DeleteMaterial { get; set; }
public RelayCommand RenameMaterial { get; set; }
public RelayCommand Save { get; set; }

private void Deleted(object o)
@@ -42,30 +56,108 @@ namespace BPASmartClient.MorkF.ViewModel

public LocalMenuViewModel()
{
if(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
//if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
//{
// PotActionStep.Clear();
// PotActionStep = new ObservableCollection<PotActions>(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions);
//}
Json<MaterialAndFryingTime>.Read();
if (Json<MaterialAndFryingTime>.Data.materials.Count > 0)
{
PotActionStep.Clear();
PotActionStep = new ObservableCollection<PotActions>(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions);
MaterialNames.Clear();
materialAndFryingTime.materials = Json<MaterialAndFryingTime>.Data.materials;
foreach (var item in materialAndFryingTime.materials)
{
MaterialNames.Add(item.Key);
//if (MaterialNames.Count == 1)
//{
// MaterialName = item.Key;
// PotActionStep.Clear();
// foreach (var item2 in item.Value)
// {
// PotActionStep.Add(item2);
// }
//}
}
}
Delete = new RelayCommand<object>(Deleted);
AddFryTime = new RelayCommand(() =>
{
List<SeasoningList> seasoningLists = new List<SeasoningList>();
seasoningLists.Add(new SeasoningList { Loc = 0,Qty = 0});
PotActionStep.Add(new BPA.Models.PotActions
seasoningLists.Add(new SeasoningList { Loc = 0, Qty = 0 });
PotActionStep.Add(new BPA.Models.PotActions
{
FryTime = PotActionStep.Count +1,
During =0,
FryTime = PotActionStep.Count + 1,
During = 0,
SeasoningLists = seasoningLists,
});
});

NewStartLocalMaterial = new RelayCommand(() =>
{
ActionManage.GetInstance.Send("NewStartLocalOrder", SelectMaterialName);
});
AddMaterial = new RelayCommand(() =>
{
//尝试是否能找到
if(MaterialNames.FirstOrDefault(o=>o == MaterialName) == MaterialName)
{
MessageBox.Show("该菜品已经添加");
}
else
{
MaterialNames.Add(MaterialName);
}
});
DeleteMaterial = new RelayCommand(() =>
{
//尝试是否能找到
if (MaterialNames.FirstOrDefault(o => o == SelectMaterialName) == SelectMaterialName)
{
MaterialNames.Remove(SelectMaterialName);
if(materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
{
materialAndFryingTime.materials.Remove(SelectMaterialName);
}
}
});
RenameMaterial = new RelayCommand(() =>
{
//尝试是否能找到
if (MaterialNames.FirstOrDefault(o => o == SelectMaterialName) == SelectMaterialName)
{
MaterialNames.Remove(SelectMaterialName);
MaterialNames.Add(MaterialName);
if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
{
materialAndFryingTime.materials.Add(MaterialName, materialAndFryingTime.materials[SelectMaterialName]);
materialAndFryingTime.materials.Remove(SelectMaterialName);
}
}
});
Save = new RelayCommand(new Action(() =>
{
Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey = 11;
Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions = new List<PotActions>(PotActionStep);
Json<LocalPotStep>.Save();
ActionManage.GetInstance.Send("LocalMenuClose");
if(PotActionStep.Count > 0)
{
ObservableCollection<PotActions> newPotActionSteps = new ObservableCollection<PotActions>();
foreach (var step in PotActionStep)
{
newPotActionSteps.Add(step);
}
if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
{
materialAndFryingTime.materials[SelectMaterialName] = newPotActionSteps;
}
else
{
materialAndFryingTime.materials.Add(SelectMaterialName, newPotActionSteps);
}
}
//Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey = 11;
//Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions = new List<PotActions>(PotActionStep);
//Json<LocalPotStep>.Save();
Json<MaterialAndFryingTime>.Data.materials = materialAndFryingTime.materials;
Json<MaterialAndFryingTime>.Save();
//ActionManage.GetInstance.Send("LocalMenuClose");
}));

foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum)))
@@ -98,7 +190,27 @@ namespace BPASmartClient.MorkF.ViewModel

}), "PotActionStep");

ActionManage.GetInstance.Register(new Action<object>(o =>
{
if (o is string str)
{
SelectMaterialName = str;
PotActionStep.Clear();
if (materialAndFryingTime.materials.ContainsKey(str))
{
foreach (var item2 in materialAndFryingTime.materials[str])
{
PotActionStep.Add(item2);
}
}
}
}), "LoacMenuSelectMaterial",true);

}
}

partial class MaterialAndFryingTime
{
public Dictionary<string, ObservableCollection<PotActions>> materials { get; set; } = new Dictionary<string, ObservableCollection<PotActions>>();
}
}

Chargement…
Annuler
Enregistrer