终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Control_MORKJC.cs 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Collections.Concurrent;
  7. using System.Diagnostics;
  8. using System.Threading.Tasks;
  9. using BPASmartClient.Device;
  10. using BPA.Message.Enum;
  11. using BPA.Message;
  12. using BPASmartClient.Helper;
  13. using BPASmartClient.Model.咖啡机.Enum;
  14. using BPASmartClient.Model;
  15. using BPASmartClient.EventBus;
  16. using static BPASmartClient.EventBus.EventBus;
  17. using BPASmartClient.Model.PLC;
  18. using BPASmartClient.Model.单片机;
  19. namespace BPASmartClient.MorkTJuicer
  20. {
  21. /*
  22. * 冰淇淋咖啡机组合套装
  23. * 物料位置:
  24. * 1:冰淇料
  25. * 2:冰淇淋杯
  26. * 5:咖啡
  27. * 6:咖啡杯
  28. * 9: 茶
  29. * 10: 茶杯
  30. */
  31. public class Control_MORKJC : BaseDevice
  32. {
  33. GVL_MORKJC mORKD = new GVL_MORKJC();
  34. //物料存放位置
  35. private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
  36. //容器位置
  37. private string holderLoc;
  38. //主料位置
  39. private string mainMaterialLoc;
  40. //子订单ID
  41. private string subOrderId;
  42. private bool enableFunny = false;
  43. private DateTime lastRecvdOrder = DateTime.Now;
  44. private bool working = false;
  45. /// <summary>
  46. /// 果汁机做法,true:热饮,false:冷饮
  47. /// </summary>
  48. private bool GuMake = false;
  49. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  50. {
  51. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  52. }
  53. //private SerialPortClient commProxy;
  54. public void ConnectOk()
  55. {
  56. }
  57. ConcurrentQueue<MorkOrderPush> morkOrderPushes = new ConcurrentQueue<MorkOrderPush>();
  58. public void Init()
  59. {
  60. //构建所有商品物料信息
  61. batchings = PolymerBatching.BuildAll();
  62. Main();
  63. ReadData();
  64. ThreadManage.GetInstance().StartLong(new Action(() =>
  65. {
  66. while (morkOrderPushes.Count > 0)
  67. {
  68. while (enableFunny) { Thread.Sleep(10); }
  69. DeviceProcessLogShow("当前非自嗨模式,允许开工");
  70. working = true;
  71. if (morkOrderPushes.TryDequeue(out MorkOrderPush order))
  72. {
  73. DeviceProcessLogShow($"开始制作订单[{order.SortNum}]");
  74. //商品类型
  75. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  76. //子订单ID
  77. subOrderId = order.SuborderId;
  78. //遍历物料
  79. foreach (var item in order.GoodBatchings)
  80. {
  81. var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  82. if (res != null)
  83. {
  84. //获取主料和容器位置
  85. switch (batchings[res.BatchingLoc].BatchingClass)
  86. {
  87. case BATCHING_CLASS.HOLDER:
  88. holderLoc = res.BatchingLoc;
  89. break;
  90. case BATCHING_CLASS.MAIN_MATERIAL:
  91. // mainMaterialLoc ="1";
  92. mainMaterialLoc = res.BatchingLoc;
  93. //验证商品是咖啡还是冰淇淋
  94. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  95. {
  96. //获取当前物料所属商品类型
  97. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  98. }
  99. break;
  100. }
  101. }
  102. }
  103. //根据商品类型执行具体制作流程
  104. switch (currentGoodsType)
  105. {
  106. case GOODS_TYPE.JUICE:
  107. GuMake = order.MakeID == "2";
  108. DoJuicer();
  109. break;
  110. case GOODS_TYPE.NEITHER:
  111. DeviceProcessLogShow("未知的商品类型");
  112. break;
  113. }
  114. }
  115. working = false;
  116. lastRecvdOrder = DateTime.Now;
  117. }
  118. Thread.Sleep(1000);
  119. }), "订单制作");
  120. }
  121. public void Main()
  122. {
  123. //开始心跳刷新,根据咖啡机及冰淇淋机来判断
  124. //ThreadManage.GetInstance().StartLong(new Action(() =>
  125. //{
  126. // Thread.Sleep(100);
  127. //}), "MORK-IC心跳刷新");
  128. }
  129. public void DataParse<T>(T order)
  130. {
  131. if (order is MorkOrderPush morkOrderPush)
  132. {
  133. morkOrderPushes.Enqueue(morkOrderPush);
  134. }
  135. }
  136. /// <summary>
  137. ///
  138. /// </summary>
  139. /// <param name="batchingLoc">物料位置</param>
  140. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  141. {
  142. if (batchings.ContainsKey(batchingLoc))
  143. return batchings[batchingLoc].GoodsType;
  144. return GOODS_TYPE.NEITHER;
  145. }
  146. private AutoResetEvent are = new AutoResetEvent(false);
  147. private T GetStatus<T>(string key)
  148. {
  149. if (peripheralStatus.ContainsKey(key))
  150. {
  151. if (peripheralStatus[key] != null)
  152. {
  153. return (T)(peripheralStatus[key]);
  154. }
  155. }
  156. return default;
  157. }
  158. private void Wait(int value)
  159. {
  160. while (!((GetStatus<int>("Get_RobotAO1") == value) && GetStatus<int>("GetProgramStatus") == 0))//判断文件是否已经执行结束 且 文件末端变量值==文件名
  161. {
  162. Thread.Sleep(5);
  163. }
  164. }
  165. int[] devStatusBy = new int[2] { 0, 0 };
  166. /// <summary>
  167. /// 果汁机控制信号
  168. /// </summary>
  169. private byte JuicerNum;
  170. /// <summary>
  171. /// 做果汁
  172. /// </summary>
  173. private void DoJuicer()
  174. {
  175. #region 接果汁流程
  176. OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  177. try
  178. {
  179. int JuicerNum1 = int.Parse(mainMaterialLoc);
  180. switch (JuicerNum1)
  181. {
  182. case 52:
  183. if (GuMake)
  184. {
  185. JuicerNum = 0x00;
  186. }
  187. else
  188. {
  189. JuicerNum = 0x01;
  190. }
  191. break;
  192. case 53:
  193. if (GuMake)
  194. {
  195. JuicerNum = 0x02;
  196. }
  197. else
  198. {
  199. JuicerNum = 0x03;
  200. }
  201. break;
  202. case 54:
  203. if (GuMake)
  204. {
  205. JuicerNum = 0x04;
  206. }
  207. else
  208. {
  209. JuicerNum = 0x05;
  210. }
  211. break;
  212. case 55:
  213. if (GuMake)
  214. {
  215. JuicerNum = 0x06;
  216. }
  217. else
  218. {
  219. JuicerNum = 0x07;
  220. }
  221. break;
  222. default:
  223. JuicerNum = 0x00;
  224. break;
  225. }
  226. var devStatus = GetStatus<int[]>("GetDeviceStatus");
  227. var devStatus1 = Convert.ToString(devStatus[0], 2);
  228. var devStatus2 = devStatus[1];
  229. if (devStatus1.IndexOf("0") == 1 && devStatus2 == 0)
  230. {
  231. new WriteJuicer() { Value = JuicerNum }.Publish();
  232. Thread.Sleep(100);
  233. devStatusBy = GetStatus<int[]>("GetDeviceStatus");
  234. while (!(devStatusBy[1] == 0))
  235. {
  236. Thread.Sleep(100);
  237. devStatusBy = GetStatus<int[]>("GetDeviceStatus");
  238. while (devStatusBy.Length != 2)
  239. {
  240. Thread.Sleep(100);
  241. devStatusBy = GetStatus<int[]>("GetDeviceStatus");
  242. }
  243. }
  244. devStatusBy = GetStatus<int[]>("GetDeviceStatus");
  245. Thread.Sleep(5000);
  246. OrderChange(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. DeviceProcessLogShow("获取果汁机状态失败");
  252. }
  253. #endregion
  254. }
  255. public override DeviceClientType DeviceType => throw new NotImplementedException();
  256. private T McuRead<T>(string tagName, object par)
  257. {
  258. new ReadMcu() { DeviceId = DeviceId, TagName = tagName, ReadPar = par };
  259. if (peripheralStatus.ContainsKey(tagName))
  260. {
  261. if (peripheralStatus[tagName] != null)
  262. {
  263. return (T)peripheralStatus[tagName];
  264. }
  265. }
  266. return default;
  267. }
  268. public void SimOrder<T>(T simOrder)
  269. {
  270. }
  271. public override void DoMain()
  272. {
  273. }
  274. public override void Stop()
  275. {
  276. }
  277. public override void ReadData()
  278. {
  279. }
  280. public override void MainTask()
  281. {
  282. }
  283. public override void ResetProgram()
  284. {
  285. }
  286. public override void SimOrder()
  287. {
  288. }
  289. }
  290. }