终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Control_Morks.cs 38 KiB

2 år sedan
1 år sedan
2 år sedan
1 år sedan
1 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
1 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
1 år sedan
1 år sedan
1 år sedan
2 år sedan
1 år sedan
2 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
1 år sedan
1 år sedan
2 år sedan
2 år sedan
2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. using System;
  2. using System.Collections.Generic;
  3. using BPA.Message.Enum;
  4. using BPASmartClient.Device;
  5. using BPASmartClient.Model;
  6. using BPASmartClient.Peripheral;
  7. using BPA.Helper;
  8. using System.Threading;
  9. using BPA.Message;
  10. using System.Linq;
  11. using BPASmartClient.Model.PLC;
  12. using System.Threading.Tasks;
  13. using System.Reflection;
  14. using BPASmartClient.MorkS.Model;
  15. using System.Collections.ObjectModel;
  16. using BPASmartClient.MorkS.ViewModel;
  17. using BPASmartClient.Business;
  18. using BPASmartClient.Model.小炒机;
  19. using BPA.Models;
  20. using System.Speech.Synthesis;
  21. using System.Windows.Forms;
  22. using System.Media;
  23. using BPASmartClient.CustomResource;
  24. using static BPA.Helper.EventBus;
  25. namespace BPASmartClient.MorkS
  26. {
  27. public class Control_Morks : BaseDevice
  28. {
  29. public override DeviceClientType DeviceType => DeviceClientType.MORKS;
  30. GVL_MORKS mORKS = new GVL_MORKS();
  31. Alarm alarm = new Alarm();
  32. public override void DoMain()
  33. {
  34. MonitorViewModel.DeviceId = DeviceId;
  35. ServerInit();
  36. DataParse();
  37. Json<MorksPar>.Read();
  38. Json<OrderStatistics>.Read();
  39. if (Json<MorksPar>.Data.parSets == null) Json<MorksPar>.Data.parSets = new ObservableCollection<ParSet>();
  40. if (Json<MorksPar>.Data.parSets.Count < 6)
  41. {
  42. Json<MorksPar>.Data.parSets.Clear();
  43. for (int i = 0; i < 6; i++)
  44. {
  45. Json<MorksPar>.Data.parSets.Add(new ParSet()
  46. {
  47. CheckBoxContext = $"煮面口{i + 1}屏蔽",
  48. Minute = 1,
  49. Second = 0,
  50. IsShield = false,
  51. TextBlockContext = $"煮面口{i + 1}时间设定"
  52. });
  53. }
  54. }
  55. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  56. {
  57. if (o.Length > 0)
  58. {
  59. Random rd = new Random();
  60. TaskManage.GetInstance.StartLong(new Action(() =>
  61. {
  62. int NoodleLoc = (int)o[0] == 0 ? rd.Next(1, 6) : (int)o[0];
  63. int BowlLoc = (int)o[1] == 0 ? rd.Next(10, 12) : (int)o[1];
  64. string guid = new Guid().ToString();
  65. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid });
  66. MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】");
  67. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid });
  68. MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】");
  69. Thread.Sleep(60000);
  70. }), "ForOrder");
  71. }
  72. }), "EnableForOrder");
  73. ActionManage.GetInstance.Register(new Action<object>((o) =>
  74. {
  75. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  76. }), "WriteVW");
  77. ActionManage.GetInstance.Register(new Action<object>((o) =>
  78. {
  79. if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value);
  80. }), "WriteBools");
  81. ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");
  82. }
  83. public override void ResetProgram()
  84. {
  85. mORKS = null;
  86. mORKS = new GVL_MORKS();
  87. }
  88. public override void Stop()
  89. {
  90. }
  91. private void ServerInit()
  92. {
  93. //物料信息
  94. EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  95. {
  96. if (@event == null) return;
  97. if (@event is MaterialDeliveryEvent material)
  98. {
  99. orderMaterialDelivery = material.orderMaterialDelivery;
  100. }
  101. });
  102. //配方数据信息
  103. EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  104. {
  105. if (@event == null) return;
  106. if (@event is RecipeBomEvent recipe)
  107. {
  108. recipeBoms = recipe.recipeBoms;
  109. WriteRecipeBoms();
  110. }
  111. });
  112. }
  113. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  114. {
  115. var res = mORKS.doOrderEvents.FirstOrDefault(p => p.MorkOrder.SuborderId == subid);
  116. string goodName = string.Empty;
  117. string SortNum = string.Empty;
  118. if (res != null)
  119. {
  120. goodName = res.MorkOrder.GoodsName;
  121. SortNum = res.MorkOrder.SortNum.ToString();
  122. }
  123. //if (mORKS.doe.ContainsKey(subid))
  124. //{
  125. //goodName = mORKS.doe[subid].MorkOrder.GoodsName;
  126. //SortNum = mORKS.doe[subid].MorkOrder.SortNum.ToString();
  127. if (!string.IsNullOrEmpty(goodName) && !string.IsNullOrEmpty(SortNum))
  128. {
  129. EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { SortNum = SortNum, GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  130. var index = DataServer.GetInstance.morkS.MakeOrder.FindIndex(p => p.SortNum == SortNum);
  131. if (index >= 0 && index < DataServer.GetInstance.morkS.MakeOrder.Count)
  132. {
  133. if (oRDER_STATUS == ORDER_STATUS.COMPLETED_COOK)
  134. {
  135. DataServer.GetInstance.morkS.MakeOrder.RemoveAt(index);
  136. DataServer.GetInstance.morkS.MakeOrderOver.Add(new OrderMakeModel()
  137. {
  138. Status = oRDER_STATUS,
  139. GoodName = goodName,
  140. SortNum = SortNum,
  141. StopTime = DateTime.Now.ToString("HH:mm:ss")
  142. });
  143. }
  144. else if (oRDER_STATUS == ORDER_STATUS.COMPLETED_TAKE)
  145. {
  146. var temp = DataServer.GetInstance.morkS.MakeOrderOver.FirstOrDefault(p => p.SortNum == SortNum);
  147. if (temp != null) DataServer.GetInstance.morkS.MakeOrderOver.Remove(temp);
  148. }
  149. else
  150. {
  151. DataServer.GetInstance.morkS.MakeOrder.ElementAt(index).Status = oRDER_STATUS;
  152. }
  153. }
  154. else
  155. {
  156. DataServer.GetInstance.morkS.MakeOrder.Add(new OrderMakeModel()
  157. {
  158. Status = oRDER_STATUS,
  159. GoodName = goodName,
  160. SortNum = SortNum,
  161. StartTime = DateTime.Now.ToString("HH:mm:ss")
  162. });
  163. }
  164. //mORKS.doe.Remove(subid, out _);
  165. }
  166. //}
  167. }
  168. private void GetStatus(string key, Action<object> action)
  169. {
  170. if (peripheralStatus.ContainsKey(key))
  171. {
  172. if (peripheralStatus[key] != null)
  173. {
  174. action?.Invoke(peripheralStatus[key]);
  175. }
  176. }
  177. }
  178. public override void ReadData()
  179. {
  180. DataServer.GetInstance.morkS.Alarm.Clear();
  181. alarms.ForEach(item =>
  182. {
  183. DataServer.GetInstance.morkS.Alarm.Add(new AlarmModel()
  184. {
  185. AlarmTime = $"{item.Date} {item.Time}",
  186. AlarmMs = item.Info
  187. });
  188. });
  189. GetStatus("M230.0", new Action<object>((obj) =>
  190. {
  191. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24)
  192. {
  193. alarm.MachineLeftLowTemperature = bools[0];
  194. alarm.MachineRightLowTemperature = bools[1];
  195. alarm.Supply1_LossBowl = bools[2];
  196. alarm.Supply2_LossBowl = bools[3];
  197. alarm.Supply1_ErrorOutBowl = bools[4];
  198. alarm.Supply2_ErrorOutBowl = bools[5];
  199. alarm.PushBowlCylinderError = bools[6];
  200. alarm.NoodleMacCommunicateError = bools[7];
  201. alarm.DosingMacCommunicateError = bools[8];
  202. alarm.RobotMacCommunicateError = bools[9];
  203. alarm.DeviceEstop = bools[10];
  204. alarm.RobotInitError = bools[11];
  205. alarm.RobotUrgentStop = bools[12];
  206. alarm.RobotNotInRemoteMode = bools[13];
  207. alarm.RobotNotInReady = bools[14];
  208. alarm.RobotSelfInException = bools[15];
  209. alarm.LeftLackWater = bools[16];
  210. alarm.RightLackWater = bools[17];
  211. alarm.SvrewInitFail = bools[18];
  212. alarm.TurntableInitFail = bools[19];
  213. alarm.RobotInitFail = bools[20];
  214. alarm.NoodleCookerInitFail = bools[21];
  215. alarm.PushBowlInitFail1 = bools[22];
  216. alarm.PushBowlInitFail2 = bools[23];
  217. }
  218. }));
  219. GetStatus("M0.3", new Action<object>((obj) =>
  220. {
  221. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 3)
  222. {
  223. mORKS.RobotTakeNoodle = bools[0];
  224. mORKS.RobotOutMeal = bools[1];
  225. mORKS.MoveTurntable = bools[2];
  226. }
  227. }));
  228. GetStatus("M100.0", new Action<object>((obj) =>
  229. {
  230. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 16)
  231. {
  232. mORKS.InitComplete = bools[0];
  233. mORKS.TakeBowlIdle = bools[1];
  234. mORKS.TemperatureReached = bools[2];
  235. mORKS.AllowFallNoodle = bools[3];
  236. mORKS.RbTakeNoodleComplete = bools[4];
  237. mORKS.RbFallNoodleComplete = bools[5];
  238. mORKS.RbOutMealComplete = bools[6];
  239. mORKS.RobotIdle = bools[7];
  240. mORKS.TakeMealDetect = bools[8];
  241. mORKS.MissingBowl = bools[9];
  242. Initing = bools[10];
  243. mORKS.TurntableLowerLimit = bools[11];
  244. mORKS.MissingBowlSignal2 = bools[12];
  245. mORKS.TurntableUpLimit = bools[13];
  246. mORKS.FeedComplete = bools[14];
  247. mORKS.TurntableMoveInPlace = bools[15];
  248. DataServer.GetInstance.morkS.MorkS_Temp = mORKS.TemperatureReached;
  249. DataServer.GetInstance.morkS.Morks_SiloMeasUp = mORKS.TurntableUpLimit;
  250. DataServer.GetInstance.morkS.Morks_SiloMeasDown = mORKS.TurntableLowerLimit;
  251. DataServer.GetInstance.morkS.MorkS_NoBowMeas1 = mORKS.MissingBowl;
  252. DataServer.GetInstance.morkS.MorkS_NoBowMeas2 = mORKS.MissingBowlSignal2;
  253. }
  254. }));
  255. GetStatus("M235.0", new Action<object>((obj) =>
  256. {
  257. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
  258. {
  259. mORKS.Error = bools[0];
  260. }
  261. }));
  262. GetStatus("M102.0", new Action<object>((obj) =>
  263. {
  264. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
  265. {
  266. for (int i = 0; i < 6; i++)
  267. {
  268. mORKS.NoodleCookerStatus[i] = bools[i];
  269. }
  270. mORKS.Feeding = bools[6];
  271. }
  272. }));
  273. GetStatus("M103.0", new Action<object>((obj) =>
  274. {
  275. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6)
  276. {
  277. for (int i = 0; i < 6; i++)
  278. {
  279. mORKS.CookNoodlesComplete[i] = bools[i];
  280. DataServer.GetInstance.morkS.Morks_NoodleUpOrDown[i] = bools[i];
  281. }
  282. }
  283. }));
  284. GetStatus("VW372", new Action<object>((obj) =>
  285. {
  286. if (obj is ushort[] UshortValue && UshortValue.Length > 0 && UshortValue.Length <= 1)
  287. mORKS.TurntableFeedbackloc = UshortValue[0];
  288. DataServer.GetInstance.morkS.MorkS_BinLocation = mORKS.TurntableFeedbackloc;
  289. }));
  290. }
  291. /// <summary>
  292. /// 数据解析
  293. /// </summary>
  294. private void DataParse()
  295. {
  296. EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  297. {
  298. if (@event == null) return;
  299. if (@event is DoOrderEvent order)
  300. {
  301. mORKS.doOrderEvents.Add(order);
  302. //mORKS.doe.TryAdd(order.MorkOrder.SuborderId, order);
  303. DeviceProcessLogShow($"接收到{order.MorkOrder.SortNum}号订单");
  304. if (order.MorkOrder.GoodBatchings == null) return;
  305. if (mORKS.HistorySuborderId.Contains(order.MorkOrder.SuborderId)) return;
  306. OrderCount++;
  307. if (DateTime.Now.Subtract(Json<OrderStatistics>.Data.StatisticsTime).Days != 0)
  308. Json<OrderStatistics>.Data.Count = 0;
  309. Json<OrderStatistics>.Data.StatisticsTime = DateTime.Now;
  310. Json<OrderStatistics>.Data.Count++;
  311. Json<OrderStatistics>.Save();
  312. OrderChange(order.MorkOrder.SuborderId, ORDER_STATUS.WAIT);
  313. if (order.MorkOrder.GoodBatchings.Count <= 1)
  314. {
  315. DeviceProcessLogShow($"数据解析失败,商品物料信息为空,请检查后台配置!");
  316. return;
  317. }
  318. DeviceProcessLogShow($"接收到{OrderCount}次订单,订单ID:{order.MorkOrder.SuborderId}");
  319. mORKS.HistorySuborderId.Add(order.MorkOrder.SuborderId);
  320. foreach (var item in order.MorkOrder.GoodBatchings)
  321. {
  322. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  323. if (res != null)
  324. {
  325. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  326. {
  327. if (loc >= 1 && loc <= 5)
  328. {
  329. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  330. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo()
  331. {
  332. GoodName = order.MorkOrder.GoodsName,
  333. Loc = ushort.Parse(res.BatchingLoc),
  334. SuborderId = order.MorkOrder.SuborderId,
  335. SortNum = order.MorkOrder.SortNum,
  336. BatchingId = res.BatchingId
  337. });
  338. }
  339. else if (loc >= 10 && loc <= 11)
  340. {
  341. int index = 0;
  342. if (recipeBoms != null)
  343. {
  344. index = Array.FindIndex(recipeBoms.RecipeIds?.ToArray(), p => p.RecipeId == order.MorkOrder.RecipeId);
  345. index++;
  346. }
  347. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  348. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  349. {
  350. BatchingId = res.BatchingId,
  351. GoodName = order.MorkOrder.GoodsName,
  352. Loc = ushort.Parse(res.BatchingLoc),
  353. SuborderId = order.MorkOrder.SuborderId,
  354. SortNum = order.MorkOrder.SortNum,
  355. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  356. });
  357. }
  358. }
  359. }
  360. else
  361. {
  362. DeviceProcessLogShow($"数据解析失败,未找到商品信息,请检查后台配置!");
  363. }
  364. }
  365. }
  366. });
  367. }
  368. public override void MainTask()
  369. {
  370. mORKS.AllowRun = mORKS.InitComplete;
  371. if (Json<KeepDataBase>.Data.IsVerify)
  372. IsHealth = mORKS.Error && mORKS.InitComplete;
  373. else
  374. IsHealth = true;
  375. TakeBowlTask();
  376. TakeNoodleTask();
  377. OutNoodleTask();
  378. SingleDetect();
  379. TurntableControl();
  380. var data = new List<bool>();
  381. for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++)
  382. {
  383. data.Add(Json<MorksPar>.Data.parSets.ElementAt(i).IsShield);
  384. }
  385. WriteControl("M260.0", data.ToArray());
  386. }
  387. private void BowlControl(OrderLocInfo orderLocInfo)
  388. {
  389. if (orderLocInfo.Loc >= 10 && orderLocInfo.Loc <= 11)
  390. {
  391. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  392. mORKS.TakeBowName = orderLocInfo.GoodName;
  393. mORKS.TakeBowSortNum = orderLocInfo.SortNum;
  394. TakeBowlControl(orderLocInfo.Loc);
  395. SetRecipeNumber(orderLocInfo.RecipeNumber);
  396. OrderChange(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  397. DeviceProcessLogShow($"订单【{mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  398. mORKS.TakeBowlInterlock = true;
  399. }
  400. }
  401. /// <summary>
  402. /// 取碗控制
  403. /// </summary>
  404. private void TakeBowlTask()
  405. {
  406. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
  407. {
  408. DeviceProcessLogShow("开始取碗流程");
  409. ushort BowLoc = 0;
  410. var res = orderMaterialDelivery?.BatchingInfo?.Where(p => p.BatchingId == mORKS.TakeBowlTask.ElementAt(0).BatchingId).ToList();
  411. if (res == null || res?.Count == 0)
  412. {
  413. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo)) BowlControl(orderLocInfo);
  414. }
  415. else
  416. {
  417. foreach (var item in res)
  418. {
  419. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  420. {
  421. //DeviceProcessLogShow($"位置:={loc},检测开关1:{alarm.Supply1_LossBowl},检测开关1:{alarm.Supply2_LossBowl}");
  422. if (loc == 10 && !alarm.Supply1_LossBowl)
  423. {
  424. BowLoc = loc;
  425. break;
  426. }
  427. else if (loc == 11 && !alarm.Supply2_LossBowl)
  428. {
  429. BowLoc = loc;
  430. break;
  431. }
  432. }
  433. }
  434. if (BowLoc >= 10 && BowLoc <= 11)
  435. {
  436. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  437. {
  438. orderLocInfo.Loc = BowLoc;
  439. BowlControl(orderLocInfo);
  440. }
  441. }
  442. }
  443. }
  444. }
  445. /// <summary>
  446. /// 转台控制
  447. /// </summary>
  448. private void TurntableControl()
  449. {
  450. if (Global.EnableLocalSimOrder)
  451. {
  452. //不做轮询,直接取面,模拟订单使用
  453. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  454. {
  455. if (mORKS.TurntableLowerLimit)
  456. {
  457. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  458. mORKS.TurntableLocLists.Clear();
  459. mORKS.AllowTakeNoodle = true;
  460. DeviceProcessLogShow($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  461. }
  462. }
  463. }
  464. else
  465. {
  466. //正常轮询
  467. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  468. {
  469. var result = orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  470. if (result != null)
  471. {
  472. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString());
  473. if (mORKS.TurntableLowerLimit && res != null)
  474. {
  475. TurntableStart(mORKS.TurntableFeedbackloc);
  476. mORKS.TurntableLocLists.Clear();
  477. mORKS.AllowTakeNoodle = true;
  478. DeviceProcessLogShow($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
  479. }
  480. else
  481. {
  482. if (!mORKS.TurntableInterlock)
  483. {
  484. foreach (var item in result)
  485. {
  486. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  487. {
  488. if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  489. {
  490. if (!mORKS.TurntableLowerLimit)
  491. {
  492. WriteData("M32.7", false);
  493. DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  494. }
  495. TurntableStart(loc);
  496. DeviceProcessLogShow($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  497. break;
  498. }
  499. else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  500. }
  501. }
  502. }
  503. }
  504. }
  505. else DeviceProcessLogShow("未找到可用的物料信息");
  506. }
  507. }
  508. //if (DelayRTrig.GetInstance("互锁信号复位").Start(!mORKS.TurntableLowerLimit && mORKS.TurntableMoveInPlace, 2))
  509. //{
  510. // if (!mORKS.TurntableLowerLimit)
  511. // {
  512. // WriteData("M32.7", false);
  513. // DeviceProcessLogShow($"执行了转台启动互锁信号复位");
  514. // }
  515. //}
  516. //补料中检测
  517. if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
  518. {
  519. mORKS.AllowTakeNoodle = false;
  520. mORKS.TakeNoodleInterlock = false;
  521. }
  522. //转台到位检测
  523. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
  524. {
  525. mORKS.CurrentLoc = 0;
  526. mORKS.TurntableInterlock = false;
  527. DeviceProcessLogShow("转台到位检测");
  528. }
  529. //补料完成检测
  530. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  531. {
  532. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  533. {
  534. mORKS.TurntableLocLists.Clear();
  535. mORKS.TurntableInterlock = false;
  536. DeviceProcessLogShow("补料完成检测");
  537. }
  538. }
  539. }
  540. /// <summary>
  541. /// 取面任务
  542. /// </summary>
  543. private void TakeNoodleTask()
  544. {
  545. //取面控制
  546. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  547. {
  548. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  549. if (loc >= 0 && loc <= 5)
  550. {
  551. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  552. {
  553. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  554. SetFallNoodleLoc((ushort)(loc + 1));
  555. //机器人开始取面
  556. RobotTakeNoodle();
  557. OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  558. DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  559. //写入煮面时间
  560. List<ushort> values = new List<ushort>();
  561. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Minute);
  562. values.Add(Json<MorksPar>.Data.parSets.ElementAt(loc).Second);
  563. WriteData($"VW{116 + (loc * 6)}", values.ToArray());
  564. mORKS.TakeNoodleInterlock = true;
  565. }
  566. }
  567. }
  568. }
  569. /// <summary>
  570. /// 出餐控制
  571. /// </summary>
  572. private void OutNoodleTask()
  573. {
  574. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  575. {
  576. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  577. if (loc >= 0 && loc <= 5)
  578. {
  579. if (mORKS.CookNoodlesComplete[loc])
  580. {
  581. SetTakeNoodleLoc((ushort)(loc + 1));
  582. RobotOutMeal();
  583. CookNoodleStatusReset((ushort)(loc + 1));
  584. ResetAllowFallNoodle();
  585. //新增,待测试
  586. if (mORKS.RbOutMealComplete)
  587. {
  588. ResetCookComplete();
  589. mORKS.CookCompleteFlatBit = false;
  590. DeviceProcessLogShow("取餐过程中复位出餐完成信号");
  591. }
  592. if (!string.IsNullOrEmpty(mORKS.OutMealId)) OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  593. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  594. mORKS.OutMealName = mORKS.IngredientsCompleteName;
  595. mORKS.OutMealSortNum = mORKS.IngredientsCompleteSortNum;
  596. mORKS.IngredientsCompleteId = string.Empty;
  597. mORKS.CookNodelId[loc] = string.Empty;
  598. DeviceProcessLogShow($"{loc + 1} 号位置出餐控制,订单ID:{mORKS.OutMealId}");
  599. mORKS.OutNoodleing = true;
  600. }
  601. }
  602. }
  603. }
  604. /// <summary>
  605. /// 信号检测
  606. /// </summary>
  607. private void SingleDetect()
  608. {
  609. //允许倒面信号检测
  610. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  611. {
  612. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  613. mORKS.IngredientsCompleteName = mORKS.TakeBowName;
  614. mORKS.IngredientsCompleteSortNum = mORKS.TakeBowSortNum;
  615. mORKS.TakeBowlId = string.Empty;
  616. mORKS.TakeBowName = string.Empty;
  617. mORKS.TakeBowSortNum = 0;
  618. DeviceProcessLogShow($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  619. mORKS.TakeBowlInterlock = false;
  620. }
  621. //出餐完成信号检测
  622. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  623. {
  624. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  625. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】制作完成");
  626. mORKS.CookCompleteFlatBit = true;
  627. mORKS.OutNoodleing = false;
  628. }
  629. //加汤
  630. /*if (Delay.GetInstance("加汤延时判断").Start(mORKS.TakeMealDetect && mORKS.CookCompleteFlatBit, 1))
  631. {
  632. AddSoup();
  633. }*/
  634. //取餐完成逻辑处理
  635. if (Delay.GetInstance("CompleteChange1").Start(!mORKS.TakeMealDetect, 1) && mORKS.CookCompleteFlatBit == true)
  636. {
  637. OrderChange(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  638. DeviceProcessLogShow($"订单【{mORKS.OutMealId}】取餐完成");
  639. ResetCookComplete();
  640. DeviceProcessLogShow($"出餐订单【{mORKS.OutMealSortNum.ToString()}】");
  641. DeviceProcessLogShow($"出餐订单序号【{mORKS.OutMealSortNum}】");
  642. VoiceAPI.Speak(mORKS.OutMealSortNum.ToString());
  643. //DeviceProcessLogShow($"叫号系统通知主题【MORKS/VoiceCall/{DeviceId}】");
  644. //Plugin.GetInstance().GetPlugin<MQTTMgr>().Publish($"MORKS/VoiceCall/{DeviceId}", mORKS.OutMealSortNum.ToString());
  645. mORKS.CookCompleteFlatBit = false;
  646. mORKS.OutMealId = string.Empty;
  647. mORKS.OutMealName = string.Empty;
  648. mORKS.OutMealSortNum = 0;
  649. }
  650. //机器人取面完成信号检测
  651. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
  652. {
  653. mORKS.TakeNoodleInterlock = false;
  654. mORKS.AllowTakeNoodle = false;
  655. mORKS.TurntableInterlock = false;
  656. DeviceProcessLogShow("机器人取面完成信号检测");
  657. TakeNoodleCompleteReset();
  658. }
  659. int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
  660. int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
  661. int index = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId);
  662. bool isok = index >= 0 && index < mORKS.CookNoodlesComplete.Length && mORKS.CookNoodlesComplete[index];
  663. mORKS.PriorityJudgment = Delay.GetInstance("取餐优先级判断").Start(mORKS.TurntableLocLists.Count > 0 && !mORKS.TurntableLowerLimit, 4);
  664. //mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment);
  665. mORKS.InvertedNoodlesOpenBusy = Json<MorksPar>.Data.InvertedNoodles_OpenBusyNum;
  666. mORKS.RobotTaskInterlock = isok && mORKS.AllowFallNoodle && (mlCount >= mORKS.InvertedNoodlesOpenBusy || mORKS.RBTakeNoodleTask.Count == 0 || mORKS.PriorityJudgment) && !mORKS.TakeMealDetect;//加个取餐口检测判断是否去面
  667. }
  668. ///// <summary>
  669. ///// 语音提醒取餐
  670. ///// </summary>
  671. ///// <param name="meal"></param>
  672. //private void WaitMeaLSpeak(string meal)
  673. //{
  674. // VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
  675. // Thread.Sleep(1000);
  676. // if (meal != null) mORKS.speech.Speak(meal);
  677. // VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
  678. //}
  679. #region PLC 控制函数
  680. private void WriteData(string address, object value)
  681. {
  682. EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  683. }
  684. /// <summary>
  685. /// 写入配方数据到 PLC
  686. /// </summary>
  687. private void WriteRecipeBoms()
  688. {
  689. List<ushort> recipeBoms = new List<ushort>();
  690. if (this.recipeBoms == null) return;
  691. foreach (var item in this.recipeBoms.RecipeIds)
  692. {
  693. foreach (var rec in item.Recipes)
  694. {
  695. recipeBoms.Add((ushort)rec);
  696. }
  697. }
  698. if (recipeBoms.Count > 0)
  699. {
  700. //配方数据地址范围:VW2000 - VW2278
  701. WriteData("VW2000", recipeBoms.ToArray());
  702. DeviceProcessLogShow("写配方成功");
  703. }
  704. else { DeviceProcessLogShow("配方数据为空"); }
  705. }
  706. /// <summary>
  707. /// 取面完成复位
  708. /// </summary>
  709. private void TakeNoodleCompleteReset()
  710. {
  711. WriteData("M100.4", false);
  712. }
  713. /// <summary>
  714. /// 指定煮面口状态复位
  715. /// </summary>
  716. /// <param name="num"></param>
  717. private void CookNoodleStatusReset(int num)
  718. {
  719. if (num >= 1 && num <= 6)
  720. {
  721. WriteData($"102.{num - 1}", false);
  722. DeviceProcessLogShow($"{num}号煮面口占用复位");
  723. }
  724. }
  725. /// <summary>
  726. /// 写配方编号
  727. /// </summary>
  728. /// <param name="num"></param>
  729. private void SetRecipeNumber(ushort num)
  730. {
  731. WriteData("VW0", num);
  732. }
  733. /// <summary>
  734. /// 启动转台
  735. /// </summary>
  736. /// <param name="loc"></param>
  737. private void TurntableStart(ushort loc)
  738. {
  739. mORKS.CurrentLoc = loc;
  740. mORKS.TurntableInterlock = true;
  741. mORKS.TurntableLocLists.Add(loc);
  742. WriteData("VW2", loc);
  743. WriteData("M0.5", true);
  744. }
  745. /// <summary>
  746. /// 设置倒面位置
  747. /// </summary>
  748. /// <param name="loc"></param>
  749. private void SetFallNoodleLoc(ushort loc)
  750. {
  751. WriteData("VW4", loc);
  752. }
  753. /// <summary>
  754. /// 设置取面位置
  755. /// </summary>
  756. /// <param name="loc"></param>
  757. private void SetTakeNoodleLoc(ushort loc)
  758. {
  759. WriteData("VW6", loc);
  760. }
  761. /// <summary>
  762. /// 加汤控制
  763. /// </summary>
  764. private async void AddSoup()
  765. {
  766. //M0.6
  767. WriteData("M0.6", true);
  768. await Task.Delay(Convert.ToInt32(Json<MorksPar>.Data.AddSoupTime * 1000));
  769. WriteData("M0.6", false);
  770. }
  771. /// <summary>
  772. /// 取碗控制
  773. /// </summary>
  774. /// <param name="loc"></param>
  775. private void TakeBowlControl(ushort loc)
  776. {
  777. if (loc == 10)//小碗
  778. {
  779. WriteData("M0.1", true);
  780. }
  781. else if (loc == 11)//大碗
  782. {
  783. WriteData("M0.2", true);
  784. }
  785. }
  786. /// <summary>
  787. /// 机器人取面
  788. /// </summary>
  789. private void RobotTakeNoodle()
  790. {
  791. WriteData("M0.3", true);
  792. }
  793. /// <summary>
  794. /// 机器人取餐
  795. /// </summary>
  796. private void RobotOutMeal()
  797. {
  798. WriteData("M0.4", true);
  799. }
  800. /// <summary>
  801. /// 制作完成信号复位
  802. /// </summary>
  803. private void ResetCookComplete()
  804. {
  805. WriteData("M100.6", false);
  806. }
  807. /// <summary>
  808. /// 复位允许取面信号
  809. /// </summary>
  810. private void ResetAllowFallNoodle()
  811. {
  812. WriteData("M100.3", false);
  813. }
  814. /// <summary>
  815. /// 设备初始化
  816. /// </summary>
  817. public async void DeviceInit()
  818. {
  819. WriteData("M0.0", true);
  820. await Task.Delay(1000);
  821. WriteData("M0.0", false);
  822. }
  823. public override void SimOrder()
  824. {
  825. EventBus.GetInstance().Subscribe<MorksSimorderModel>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  826. {
  827. if (@event != null && @event is MorksSimorderModel msm)
  828. {
  829. string guid = Guid.NewGuid().ToString();
  830. if (msm.NoodleLoc >= 1 && msm.NoodleLoc <= 5)
  831. {
  832. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.NoodleLoc, SuborderId = guid });
  833. MessageLog.GetInstance.Show($"添加订单:面条位置【{(ushort)msm.NoodleLoc}】");
  834. }
  835. if (msm.Bowloc >= 10 && msm.Bowloc <= 11)
  836. {
  837. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)msm.Bowloc, SuborderId = guid });
  838. MessageLog.GetInstance.Show($"添加订单:碗位置【{(ushort)msm.Bowloc}】");
  839. }
  840. }
  841. });
  842. }
  843. #endregion
  844. }
  845. }