|
- using BPA.Message;
- using BPA.Message.Enum;
- using BPASmartClient.Device;
- using BPASmartClient.EventBus;
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Model.PLC;
- using BPASmartClient.MorkTM.Model;
- using System.Collections.Concurrent;
- using static BPASmartClient.EventBus.EventBus;
-
- namespace BPASmartClient.MorkTM
- {
- public class Control_MorkTM : BaseDevice
- {
- public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.TMC_MT; } }
-
- GVL_MorkTM morkTM = new GVL_MorkTM();
- public override void DoMain()
- {
- ServerInit();
- DataParse();
- PolymerBatching.GetMaterialInfo();
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
- }), "WriteVW");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
- }), "WriteBools");
-
- DeviceProcessLogShow("设备初始化完成");
-
- }
- 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 DataParse()
- {
- EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if(@event == null) return;
- if(@event is DoOrderEvent order)
- {
- if (order.MorkOrder.GoodBatchings == null) return;
- OrderCount++;
- OrderChange(order.MorkOrder, ORDER_STATUS.WAIT);
- DeviceProcessLogShow($"接收到{OrderCount}次订单");
- Dictionary<string, int> OrderPushes = new Dictionary<string, int>();
- foreach (var item in order.MorkOrder.GoodBatchings)
- {
- var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
- if (res != null)
- {
- OrderPushes.TryAdd(res.BatchingLoc, item.BatchingCount);
- }
- }
-
- morkTM.morkOrderPushesTeaWithMilk.Enqueue(new OrderLocInfo()
- {
- GoodName = order.MorkOrder.GoodsName,
- SuborderId = order.MorkOrder.SuborderId,
- GoodPushes = OrderPushes
- });
- }
- });
- }
- private void OrderChange(MorkOrderPush orderPush, ORDER_STATUS oRDER_STATUS)
- {
- EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent()
- {
- SortNum = orderPush.SortNum.ToString(),
- GoodName = orderPush.GoodsName,
- Status = oRDER_STATUS,
- SubOrderId = orderPush.SuborderId,
- deviceClientType = DeviceType
- });
- }
-
-
- public override void MainTask()
- {
- IsHealth = true;
- MakeTeaWithMilkProcess();
- }
-
- private void MakeTeaWithMilkProcess()
- {
- if(morkTM.morkOrderPushesTeaWithMilk.Count > 0)
- {
- if(morkTM.morkOrderPushesTeaWithMilk.TryDequeue(out OrderLocInfo orderLoc))
- {
- morkTM.RecipesPushes.Clear();
- morkTM.RecipesPushes = orderLoc.GoodPushes;
- foreach(var item in morkTM.RecipesPushes)
- {
- WriteData(item.Key,item.Value);
- while (!RTrig.GetInstance("OutMaterialComplete").Start(morkTM.OutMaterialComplete))
- {
- Thread.Sleep(100);
- }
- DeviceProcessLogShow($"奶茶{orderLoc.GoodName}:配料{item.Key}:添加量{item.Value}");
- }
- }
- }
- }
-
-
-
- public override void ReadData()
- {
- throw new NotImplementedException();
- }
-
- public override void ResetProgram()
- {
- morkTM = null;
- morkTM = new GVL_MorkTM();
- }
-
- private void WriteData(string address, object value)
- {
- EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
- }
-
- private void GetStatus(string key, Action<object> action)
- {
- if (peripheralStatus.ContainsKey(key))
- {
- if (peripheralStatus[key] != null)
- {
- action?.Invoke(peripheralStatus[key]);
- }
- }
- }
-
- public override void SimOrder()
- {
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o is string goodName)
- {
-
- }
- }), "");
- }
-
- public override void Stop()
- {
- throw new NotImplementedException();
- }
- }
- }
|