终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

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