pry пре 2 година
родитељ
комит
a2d6bbb5bb
3 измењених фајлова са 79 додато и 84 уклоњено
  1. +44
    -3
      BPASmartClient.Business/Plugin/DeviceMgr.cs
  2. +25
    -76
      BPASmartClient.MorkS/Control.cs
  3. +10
    -5
      BPASmartClient/MainWindow.xaml.cs

+ 44
- 3
BPASmartClient.Business/Plugin/DeviceMgr.cs Прегледај датотеку

@@ -1,8 +1,12 @@
using BPASmartClient.Device;
using BPA.Message;
using BPASmartClient.Device;
using BPASmartClient.EventBus;
using BPASmartClient.Helper;
using BPASmartClient.Http;
using BPASmartClient.Message;
using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -68,8 +72,45 @@ namespace BPASmartClient.Business
this.devices.ForEach(device =>
{
device.StartMain();
//todo请求数据
new RecipeBomEvent() { Id = device.DeviceId}.Publish();

#region 获取物料数据
string result = string.Empty;
for (int i = 0; i < 2; i++)
{
try
{
int PushType = i;//0:主料 1:辅料
var jsondata = new { device.DeviceId, PushType };
string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt();
string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);

if (PushType == 1)
{
EventBus.EventBus.GetInstance().Publish(new RecipeBomEvent()
{
Id = device.DeviceId,
recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result)
});
MessageLog.GetInstance.Show("接收到辅料信息");
}
else if (PushType == 0)
{
EventBus.EventBus.GetInstance().Publish(new MaterialDeliveryEvent()
{
Id = device.DeviceId,
orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result)
});
MessageLog.GetInstance.Show("接收到物料信息");
}
}
catch (Exception ex)
{
MessageLog.GetInstance.ShowEx(ex.ToString());
}
}
#endregion

});
}



+ 25
- 76
BPASmartClient.MorkS/Control.cs Прегледај датотеку

@@ -32,6 +32,7 @@ namespace BPASmartClient.MorkS
bool Initing;
public override void StartMain()
{
ServerInit();
DataParse();
ReadPLCData();
Main();
@@ -43,6 +44,29 @@ namespace BPASmartClient.MorkS

}

private void ServerInit()
{
//物料信息
EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
{
if (@event == null) return;
if (@event is MaterialDeliveryEvent material)
{
orderMaterialDelivery = material.orderMaterialDelivery;
}
});

//配方数据信息
EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
{
if (@event == null) return;
if (@event is RecipeBomEvent recipe)
{
recipeBoms = recipe.recipeBoms;
}
});
}

private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
{
EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Id = DeviceId, Status = oRDER_STATUS, SubOrderId = subid });
@@ -165,7 +189,6 @@ namespace BPASmartClient.MorkS
MessageLog.GetInstance.Show($"接收到{OrderCount}次订单");
foreach (var item in order.MorkOrder.GoodBatchings)
{
//var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
if (res != null)
{
@@ -197,47 +220,6 @@ namespace BPASmartClient.MorkS
}
}
});





//if (order is MorkOrderPush morkOrderPush)
//{
// foreach (var item in morkOrderPush.GoodBatchings)
// {
// //var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
// var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
// if (res != null)
// {
// if (ushort.TryParse(res.BatchingLoc, out ushort loc))
// {
// if (loc >= 1 && loc <= 5)
// {
// if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == morkOrderPush.SuborderId) == null)
// mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(res.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = res.BatchingId });
// }
// else if (loc >= 10 && loc <= 11)
// {
// int index = 0;
// if (recipeBoms != null)
// {
// index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId);
// index++;
// }
// if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == morkOrderPush.SuborderId) == null)
// mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
// {
// Loc = ushort.Parse(res.BatchingLoc),
// SuborderId = morkOrderPush.SuborderId,
// RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
// });
// }
// }
// }
// }
//}

}


@@ -247,7 +229,6 @@ namespace BPASmartClient.MorkS
{
mORKS.AllowRun = mORKS.InitComplete;
IsHealth = mORKS.Error && mORKS.InitComplete;
//GeneralConfig.Healthy = mORKS.Error && mORKS.InitComplete && !GeneralConfig.EnableLocalSimOrder;

TakeBowlTask();

@@ -308,14 +289,12 @@ namespace BPASmartClient.MorkS
//正常轮询
if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
{
//var result = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
if (result != null)
{
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;
@@ -465,12 +444,6 @@ namespace BPASmartClient.MorkS
TakeNoodleCompleteReset();
}

//转台到位检测
//if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace))
//{
// mORKS.TurntableInterlock = false;
//}

int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0);
@@ -513,7 +486,7 @@ namespace BPASmartClient.MorkS
private void TakeNoodleCompleteReset()
{
WriteData("M100.4", false);
//ModbusTcpHelper.GetInstance.Write(1124, WriteType.Coils, false);
}

/// <summary>
@@ -524,11 +497,7 @@ namespace BPASmartClient.MorkS
{
if (num >= 1 && num <= 6)
{
//ushort addRess = (ushort)(1136 + num - 1);

WriteData($"102.{num - 1}", false);

//ModbusTcpHelper.GetInstance.Write(addRess, WriteType.Coils, false);
MessageLog.GetInstance.Show($"{num}号煮面口占用复位");
}

@@ -541,7 +510,6 @@ namespace BPASmartClient.MorkS
private void SetRecipeNumber(ushort num)
{
WriteData("VW0", num);
//ModbusTcpHelper.GetInstance.Write(100, WriteType.HoldingRegisters, num);
}

/// <summary>
@@ -555,8 +523,6 @@ namespace BPASmartClient.MorkS
mORKS.TurntableLocLists.Add(loc);
WriteData("VW0", loc);
WriteData("M0.5", true);
//ModbusTcpHelper.GetInstance.Write(101, WriteType.HoldingRegisters, loc);
//ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true);
}

/// <summary>
@@ -566,7 +532,6 @@ namespace BPASmartClient.MorkS
private void SetFallNoodleLoc(ushort loc)
{
WriteData("VW4", loc);
//ModbusTcpHelper.GetInstance.Write(102, WriteType.HoldingRegisters, loc);
}

/// <summary>
@@ -576,7 +541,6 @@ namespace BPASmartClient.MorkS
private void SetTakeNoodleLoc(ushort loc)
{
WriteData("VW6", loc);
//ModbusTcpHelper.GetInstance.Write(103, WriteType.HoldingRegisters, loc);
}

/// <summary>
@@ -588,12 +552,10 @@ namespace BPASmartClient.MorkS
if (loc == 10)//小碗
{
WriteData("M0.1", true);
//ModbusTcpHelper.GetInstance.Write(321, WriteType.Coils, true);
}
else if (loc == 11)//大碗
{
WriteData("M0.2", true);
//ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true);
}
}

@@ -603,7 +565,6 @@ namespace BPASmartClient.MorkS
private void RobotTakeNoodle()
{
WriteData("M0.3", true);
//ModbusTcpHelper.GetInstance.Write(323, WriteType.Coils, true);
}

/// <summary>
@@ -612,13 +573,6 @@ namespace BPASmartClient.MorkS
private void RobotOutMeal()
{
WriteData("M0.4", true);
//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);
// }
}

/// <summary>
@@ -627,7 +581,6 @@ namespace BPASmartClient.MorkS
private void ResetCookComplete()
{
WriteData("M100.6", false);
//ModbusTcpHelper.GetInstance.Write(1126, WriteType.Coils, false);
}

/// <summary>
@@ -636,7 +589,6 @@ namespace BPASmartClient.MorkS
private void ResetAllowFallNoodle()
{
WriteData("M100.3", false);
//ModbusTcpHelper.GetInstance.Write(1123, WriteType.Coils, false);
}

/// <summary>
@@ -645,11 +597,8 @@ namespace BPASmartClient.MorkS
public async void DeviceInit()
{
WriteData("M0.0", true);
//ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, true);
await Task.Delay(1000);
//ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, false);
WriteData("M0.0", false);

}
#endregion



+ 10
- 5
BPASmartClient/MainWindow.xaml.cs Прегледај датотеку

@@ -1,5 +1,6 @@
using BPASmartClient.Business;
using BPASmartClient.EventBus;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using BPASmartClient.Model.冰淇淋.Enum;
using BPASmartClient.Model.咖啡机.Enum;
@@ -28,8 +29,8 @@ namespace BPASmartClient
public MainWindow()
{
InitializeComponent();
this.ButClose.Click += (o,e) => { this.Close(); };
this.br.MouseLeftButtonDown += (o,e) =>
this.ButClose.Click += (o, e) => { this.Close(); };
this.br.MouseLeftButtonDown += (o, e) =>
{
if (e.ClickCount > 1)
{
@@ -40,14 +41,18 @@ namespace BPASmartClient
}
this.DragMove();
};
new MainConsole().Start();
ThreadManage.GetInstance().Start(new Action(() =>
{
new MainConsole().Start();
}), "启动主控制台");

}

private void Button_Click(object sender, RoutedEventArgs e)
{
new Demo_MakeCoffeeEvent() { Id = 1 }.Publish();
new DRCoffee_MakeCoffeeEvent() { Id = 1, DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish();
new DRCoffee_CoffeeCommCmdEvent() { Id = 1,CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish();
new DRCoffee_MakeCoffeeEvent() { Id = 1, DrinkCode = DrCoffeeDrinksCode.两杯意式浓缩 }.Publish();
new DRCoffee_CoffeeCommCmdEvent() { Id = 1, CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令 }.Publish();

}
}


Loading…
Откажи
Сачувај