终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

175 líneas
5.9 KiB

  1. using BPA.Message;
  2. using BPA.Message.Enum;
  3. using BPASmartClient.Device;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.Message;
  7. using BPASmartClient.Model;
  8. using BPASmartClient.Model.PLC;
  9. using BPASmartClient.MorkTM.Model;
  10. using System.Collections.Concurrent;
  11. using static BPASmartClient.EventBus.EventBus;
  12. namespace BPASmartClient.MorkTM
  13. {
  14. public class Control_MorkTM : BaseDevice
  15. {
  16. public override DeviceClientType DeviceType => throw new NotImplementedException();
  17. GVL_MorkTM morkTM = new GVL_MorkTM();
  18. public override void DoMain()
  19. {
  20. ServerInit();
  21. DataParse();
  22. ActionManage.GetInstance.Register(new Action<object>((o) =>
  23. {
  24. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  25. }), "WriteVW");
  26. ActionManage.GetInstance.Register(new Action<object>((o) =>
  27. {
  28. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  29. }), "WriteBools");
  30. DeviceProcessLogShow("设备初始化完成");
  31. }
  32. private void ServerInit()
  33. {
  34. //物料信息
  35. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  36. {
  37. if (@event == null) return;
  38. if (@event is MaterialDeliveryEvent material)
  39. {
  40. orderMaterialDelivery = material.orderMaterialDelivery;
  41. }
  42. });
  43. //配方数据信息
  44. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  45. {
  46. if (@event == null) return;
  47. if (@event is RecipeBomEvent recipe)
  48. {
  49. recipeBoms = recipe.recipeBoms;
  50. }
  51. });
  52. }
  53. private void DataParse()
  54. {
  55. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  56. {
  57. if(@event == null) return;
  58. if(@event is DoOrderEvent order)
  59. {
  60. if (order.MorkOrder.GoodBatchings == null) return;
  61. OrderCount++;
  62. OrderChange(order.MorkOrder, ORDER_STATUS.WAIT);
  63. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  64. Dictionary<string, int> OrderPushes = new Dictionary<string, int>();
  65. foreach (var item in order.MorkOrder.GoodBatchings)
  66. {
  67. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  68. if (res != null)
  69. {
  70. OrderPushes.TryAdd(res.BatchingLoc, item.BatchingCount);
  71. }
  72. }
  73. morkTM.morkOrderPushesTeaWithMilk.Enqueue(new OrderLocInfo()
  74. {
  75. GoodName = order.MorkOrder.GoodsName,
  76. SuborderId = order.MorkOrder.SuborderId,
  77. GoodPushes = OrderPushes
  78. });
  79. }
  80. });
  81. }
  82. private void OrderChange(MorkOrderPush orderPush, ORDER_STATUS oRDER_STATUS)
  83. {
  84. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent()
  85. {
  86. SortNum = orderPush.SortNum.ToString(),
  87. GoodName = orderPush.GoodsName,
  88. Status = oRDER_STATUS,
  89. SubOrderId = orderPush.SuborderId,
  90. deviceClientType = DeviceType
  91. });
  92. }
  93. public override void MainTask()
  94. {
  95. IsHealth = true;
  96. MakeTeaWithMilkProcess();
  97. }
  98. private void MakeTeaWithMilkProcess()
  99. {
  100. if(morkTM.morkOrderPushesTeaWithMilk.Count > 0)
  101. {
  102. if(morkTM.morkOrderPushesTeaWithMilk.TryDequeue(out OrderLocInfo orderLoc))
  103. {
  104. morkTM.RecipesPushes.Clear();
  105. morkTM.RecipesPushes = orderLoc.GoodPushes;
  106. foreach(var item in morkTM.RecipesPushes)
  107. {
  108. WriteData(item.Key,item.Value);
  109. while (!RTrig.GetInstance("OutMaterialComplete").Start(morkTM.OutMaterialComplete))
  110. {
  111. Thread.Sleep(100);
  112. }
  113. DeviceProcessLogShow($"奶茶{orderLoc.GoodName}:配料{item.Key}:添加量{item.Value}");
  114. }
  115. }
  116. }
  117. }
  118. public override void ReadData()
  119. {
  120. throw new NotImplementedException();
  121. }
  122. public override void ResetProgram()
  123. {
  124. morkTM = null;
  125. morkTM = new GVL_MorkTM();
  126. }
  127. private void WriteData(string address, object value)
  128. {
  129. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  130. }
  131. private void GetStatus(string key, Action<object> action)
  132. {
  133. if (peripheralStatus.ContainsKey(key))
  134. {
  135. if (peripheralStatus[key] != null)
  136. {
  137. action?.Invoke(peripheralStatus[key]);
  138. }
  139. }
  140. }
  141. public override void SimOrder()
  142. {
  143. ActionManage.GetInstance.Register(new Action<object>((o) =>
  144. {
  145. if (o is string goodName)
  146. {
  147. }
  148. }), "");
  149. }
  150. public override void Stop()
  151. {
  152. throw new NotImplementedException();
  153. }
  154. }
  155. }