You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

699 lines
26 KiB

  1. //#define test
  2. using BPA.Message;
  3. using HBLConsole.Communication;
  4. using HBLConsole.Factory;
  5. using HBLConsole.Interface;
  6. using HBLConsole.Model;
  7. using HBLConsole.Service;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using BPA.Message.Enum;
  15. using HBLConsole.GVL;
  16. using BPA.Models;
  17. using BPA.Message.IOT;
  18. using HBLConsole.Abstract;
  19. namespace HBLConsole.MORKS
  20. {
  21. public class Control_MORKS : IControl
  22. {
  23. GVL_MORKS mORKS = new GVL_MORKS();
  24. public void Init()
  25. {
  26. ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom");
  27. ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand");
  28. }
  29. public void ConnectOk()
  30. {
  31. ReadData();
  32. Main();
  33. ResetProgram();
  34. ActionManage.GetInstance.Register(new Action(() =>
  35. {
  36. Random rd = new Random();
  37. ThreadManage.GetInstance.StartLong(new Action(() =>
  38. {
  39. int NoodleLoc = rd.Next(1, 6);
  40. int BowlLoc = rd.Next(10, 11);
  41. string guid = new Guid().ToString();
  42. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = (ushort)NoodleLoc, SuborderId = guid });
  43. MessageLog.GetInstance.Show($"添加订单:面条位置【{NoodleLoc}】");
  44. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)BowlLoc, SuborderId = guid });
  45. MessageLog.GetInstance.Show($"添加订单:碗位置【{BowlLoc}】");
  46. Thread.Sleep(60000);
  47. }), "ForOrder");
  48. }), "EnableForOrder");
  49. ActionManage.GetInstance.Register(new Action(() =>
  50. {
  51. ThreadManage.GetInstance.StopTask("ForOrder", new Action(() =>
  52. {
  53. mORKS.RBTakeNoodleTask.Clear();
  54. mORKS.TakeBowlTask.Clear();
  55. }));
  56. }), "StopForOrder");
  57. MessageLog.GetInstance.Show("MORKS 设备初始化完成");
  58. }
  59. private void ResetProgram()
  60. {
  61. ThreadManage.GetInstance.StartLong(new Action(() =>
  62. {
  63. if (RTrig.GetInstance("ResetProgram").Start(DeviceData.Initing))
  64. {
  65. ThreadManage.GetInstance.StopTask("MainTask", new Action(() =>
  66. {
  67. ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() =>
  68. {
  69. mORKS = null;
  70. mORKS = new GVL_MORKS();
  71. ActionManage.GetInstance.Send("ResetProgram");
  72. ReadData();
  73. Main();
  74. }));
  75. }));
  76. }
  77. Thread.Sleep(10);
  78. }), "ResetProgram");
  79. }
  80. /// <summary>
  81. /// 数据读取
  82. /// </summary>
  83. public void ReadData()
  84. {
  85. ThreadManage.GetInstance.StartLong(new Action(() =>
  86. {
  87. ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action<bool[]>((bools) =>
  88. {
  89. mORKS.RobotTakeNoodle = bools[0];
  90. mORKS.RobotOutMeal = bools[1];
  91. mORKS.MoveTurntable = bools[2];
  92. }));
  93. ModbusTcpHelper.GetInstance.Readbool(1120, 16, new Action<bool[]>((bools) =>
  94. {
  95. mORKS.InitComplete = bools[0];
  96. mORKS.TakeBowlIdle = bools[1];
  97. mORKS.TemperatureReached = bools[2];
  98. mORKS.AllowFallNoodle = bools[3];
  99. mORKS.RbTakeNoodleComplete = bools[4];
  100. mORKS.RbFallNoodleComplete = bools[5];
  101. mORKS.RbOutMealComplete = bools[6];
  102. mORKS.RobotIdle = bools[7];
  103. mORKS.TakeMealDetect = bools[8];
  104. mORKS.MissingBowl = bools[9];
  105. DeviceData.Initing = bools[10];
  106. mORKS.TurntableLowerLimit = bools[11];
  107. mORKS.MissingBowlSignal2 = bools[12];
  108. mORKS.TurntableUpLimit = bools[13];
  109. mORKS.TurntableMoveInPlace = bools[15];
  110. }));
  111. ModbusTcpHelper.GetInstance.Readbool(1136, 6, new Action<bool[]>((bools) =>
  112. {
  113. for (int i = 0; i < 6; i++)
  114. {
  115. mORKS.NoodleCookerStatus[i] = bools[i];
  116. }
  117. }));
  118. ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action<bool[]>((bools) =>
  119. {
  120. for (int i = 0; i < 6; i++)
  121. {
  122. mORKS.CookNoodlesComplete[i] = bools[i];
  123. }
  124. }));
  125. var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters);
  126. if (ResLoc != null)
  127. {
  128. if (ResLoc is ushort loc)
  129. {
  130. mORKS.TurntableFeedbackloc = loc;
  131. }
  132. }
  133. Thread.Sleep(500);
  134. }), "ReadPLCData");
  135. }
  136. public void SimOrder<T>(T simOrder)
  137. {
  138. if (simOrder != null)
  139. {
  140. if (simOrder is List<ushort> locs)
  141. {
  142. string subId = Guid.NewGuid().ToString();
  143. foreach (var item in locs)
  144. {
  145. if (item >= 1 && item <= 5)
  146. {
  147. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId });
  148. MessageLog.GetInstance.Show($"添加订单:面条位置【{item}】");
  149. }
  150. if (item >= 10 && item <= 11)
  151. {
  152. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId });
  153. MessageLog.GetInstance.Show($"添加订单:碗位置【{item}】");
  154. }
  155. }
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// IOT 广播消息命令
  161. /// </summary>
  162. public void IotBroadcast<T>(T broadcast)
  163. {
  164. if (broadcast != null && broadcast is IOTCommandModel iOTCommand)
  165. {
  166. MessageLog.GetInstance.Show($"IOT 广播消息命令 {iOTCommand.deviceName} 设备命令 {iOTCommand.CommandName} 控制变量{iOTCommand.CommandValue.Keys.First()}{iOTCommand.CommandValue[iOTCommand.CommandValue.Keys.First()]}");
  167. switch (iOTCommand.CommandName)
  168. {
  169. case 0://控制类
  170. if (iOTCommand.CommandValue != null)
  171. {
  172. if (iOTCommand.CommandValue.ContainsKey("order"))
  173. {
  174. List<ushort> vs = new List<ushort>();
  175. vs.Add((ushort)(new Random().Next(1, 5)));
  176. vs.Add(ushort.Parse(iOTCommand.CommandValue["order"]));
  177. SimOrder(vs);
  178. }
  179. else if (iOTCommand.CommandValue.ContainsKey("init"))
  180. {
  181. DeviceInit();
  182. }
  183. else if (iOTCommand.CommandValue.ContainsKey("stop"))
  184. {
  185. }
  186. else if (iOTCommand.CommandValue.ContainsKey("start"))
  187. {
  188. }
  189. }
  190. break;
  191. case 1://设置属性
  192. break;
  193. case 2://通知消息
  194. break;
  195. default:
  196. break;
  197. }
  198. }
  199. }
  200. int OrderCount = 0;
  201. /// <summary>
  202. /// 数据解析
  203. /// </summary>
  204. public void DataParse<T>(T order)
  205. {
  206. OrderCount++;
  207. MessageLog.GetInstance.Show($"接收到{OrderCount}次订单");
  208. if (order is MorkOrderPush morkOrderPush)
  209. {
  210. foreach (var item in morkOrderPush.GoodBatchings)
  211. {
  212. var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  213. if (res != null)
  214. {
  215. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  216. {
  217. if (loc >= 1 && loc <= 5)
  218. {
  219. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(res.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = res.BatchingId });
  220. }
  221. else if (loc >= 10 && loc <= 11)
  222. {
  223. int index = 0;
  224. if (Json<BatchingInfoPar>.Data.recipeBoms != null)
  225. {
  226. index = Array.FindIndex(Json<BatchingInfoPar>.Data.recipeBoms?.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId);
  227. index++;
  228. }
  229. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  230. {
  231. Loc = ushort.Parse(res.BatchingLoc),
  232. SuborderId = morkOrderPush.SuborderId,
  233. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  234. });
  235. }
  236. }
  237. }
  238. }
  239. }
  240. }
  241. public void Main()
  242. {
  243. ThreadManage.GetInstance.StartLong(new Action(() =>
  244. {
  245. mORKS.AllowRun = mORKS.InitComplete;
  246. //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached;
  247. GeneralConfig.Healthy = true;
  248. //GeneralConfig.Healthy = mORKS.AllowRun;
  249. TakeBowlTask();
  250. TakeNoodleTask();
  251. OutNoodleTask();
  252. SingleDetect();
  253. TurntableControl();
  254. Thread.Sleep(100);
  255. }), "MainTask");
  256. }
  257. /// <summary>
  258. /// 取碗控制
  259. /// </summary>
  260. private void TakeBowlTask()
  261. {
  262. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
  263. {
  264. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  265. {
  266. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  267. TakeBowlControl(orderLocInfo.Loc);
  268. SetRecipeNumber(orderLocInfo.RecipeNumber);
  269. SimpleFactory.GetInstance.OrderChanged(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  270. MessageLog.GetInstance.Show($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  271. }
  272. mORKS.TakeBowlInterlock = true;
  273. }
  274. }
  275. /// <summary>
  276. /// 转台控制
  277. /// </summary>
  278. private void TurntableControl()
  279. {
  280. if (mORKS.TurntableMoveInPlace && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  281. {
  282. if (mORKS.TurntableLowerLimit)
  283. {
  284. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  285. mORKS.AllowTakeNoodle = true;
  286. mORKS.TurntableLocLists.Clear();
  287. MessageLog.GetInstance.Show("转台位置OK");
  288. mORKS.IsNoodles = true;
  289. }
  290. else
  291. {
  292. if (!mORKS.TurntableInterlock)
  293. {
  294. var result = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  295. if (result != null)
  296. {
  297. foreach (var item in result)
  298. {
  299. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  300. {
  301. if (mORKS.TurntableFeedbackloc != loc)
  302. {
  303. if (!mORKS.TurntableLocLists.Contains(loc))
  304. {
  305. TurntableStart(loc);
  306. MessageLog.GetInstance.Show("未检测到物料,启动转台查找");
  307. return;
  308. }
  309. }
  310. }
  311. }
  312. mORKS.IsNoodles = false;
  313. MessageLog.GetInstance.Show("转台位置缺少物料");
  314. }
  315. }
  316. }
  317. }
  318. #region 优化版本
  319. //if (mORKS.TurntableMoveInPlace && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  320. //{
  321. // var result = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  322. // if (mORKS.TurntableLowerLimit)
  323. // {
  324. // if (mORKS.TurntableFeedbackloc == mORKS.RBTakeNoodleTask.ElementAt(0).Loc || (result?.Count > 0 && result?.Count == mORKS.TurntableLocLists.Count))
  325. // {
  326. // mORKS.TurntableLocLists.Clear();
  327. // mORKS.AllowTakeNoodle = true;
  328. // MessageLog.GetInstance.Show("转台位置OK,执行机器人取面");
  329. // }
  330. // else
  331. // {
  332. // if (!mORKS.TurntableInterlock)
  333. // {
  334. // TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  335. // MessageLog.GetInstance.Show($"有物料检测,反馈位置不同的转台启动控制,转台位置:[{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}]");
  336. // }
  337. // }
  338. // }
  339. // else
  340. // {
  341. // if (!mORKS.TurntableInterlock)
  342. // {
  343. // if (result != null)
  344. // {
  345. // foreach (var item in result)
  346. // {
  347. // if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  348. // {
  349. // if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  350. // {
  351. // TurntableStart(loc);
  352. // MessageLog.GetInstance.Show($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  353. // break;
  354. // }
  355. // else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  356. // }
  357. // }
  358. // }
  359. // }
  360. // }
  361. //}
  362. //转台到位检测
  363. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace))
  364. {
  365. mORKS.TurntableInterlock = false;
  366. }
  367. #endregion
  368. }
  369. /// <summary>
  370. /// 取面任务
  371. /// </summary>
  372. private void TakeNoodleTask()
  373. {
  374. //取面控制
  375. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  376. {
  377. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  378. if (loc >= 0 && loc <= 5)
  379. {
  380. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  381. {
  382. //设置转台位置
  383. TurntableStart(orderLocInfo.Loc);
  384. //设置倒面位置
  385. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  386. SetFallNoodleLoc((ushort)(loc + 1));
  387. //机器人开始取面
  388. RobotTakeNoodle();
  389. SimpleFactory.GetInstance.OrderChanged(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  390. MessageLog.GetInstance.Show($"订单【{orderLocInfo.SuborderId}】,转台:[{orderLocInfo}],煮面栏:[{loc + 1}]");
  391. mORKS.TakeNoodleInterlock = true;
  392. }
  393. }
  394. }
  395. }
  396. /// <summary>
  397. /// 出餐控制
  398. /// </summary>
  399. private void OutNoodleTask()
  400. {
  401. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  402. {
  403. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  404. if (loc >= 0 && loc <= 5)
  405. {
  406. if (mORKS.CookNoodlesComplete[loc])
  407. {
  408. SetTakeNoodleLoc((ushort)(loc + 1));
  409. RobotOutMeal();
  410. CookNoodleStatusReset((ushort)(loc + 1));
  411. ResetAllowFallNoodle();
  412. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  413. mORKS.IngredientsCompleteId = string.Empty;
  414. mORKS.CookNodelId[loc] = string.Empty;
  415. MessageLog.GetInstance.Show($"{loc + 1}号位置出餐控制");
  416. mORKS.OutNoodleing = true;
  417. }
  418. }
  419. }
  420. }
  421. /// <summary>
  422. /// 信号检测
  423. /// </summary>
  424. private void SingleDetect()
  425. {
  426. //允许倒面信号检测
  427. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  428. {
  429. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  430. mORKS.TakeBowlId = string.Empty;
  431. MessageLog.GetInstance.Show($"允许到面,{mORKS.IngredientsCompleteId}");
  432. mORKS.TakeBowlInterlock = false;
  433. }
  434. //出餐完成信号检测
  435. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  436. {
  437. SimpleFactory.GetInstance.OrderChanged(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  438. MessageLog.GetInstance.Show($"订单【{mORKS.OutMealId}】制作完成");
  439. mORKS.OutNoodleing = false;
  440. }
  441. //取餐完成逻辑处理
  442. if (DelayRTrig.GetInstance("CompleteChange1").Start(mORKS.RbOutMealComplete && !mORKS.TakeMealDetect, 2))
  443. {
  444. SimpleFactory.GetInstance.OrderChanged(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  445. MessageLog.GetInstance.Show($"订单【{mORKS.OutMealId}】取餐完成");
  446. //var RemoveItem = Json<MorkOrderPushPar>.Data.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId);
  447. //if (RemoveItem != null)
  448. //{
  449. // Json<MorkOrderPushPar>.Data.morkOrderPushes.Remove(RemoveItem);
  450. //}
  451. var RemoveItem = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.OrderPush.SuborderId == mORKS.OutMealId);
  452. if (RemoveItem != null)
  453. {
  454. Json<KeepDataBase>.Data.orderLists.Remove(RemoveItem);
  455. }
  456. ResetCookComplete();
  457. mORKS.OutMealId = string.Empty;
  458. }
  459. //机器人取面完成信号检测
  460. if (RTrig.GetInstance("TakeNoodleComplete").Start(mORKS.RbTakeNoodleComplete))
  461. {
  462. mORKS.TakeNoodleInterlock = false;
  463. mORKS.AllowTakeNoodle = false;
  464. mORKS.TurntableInterlock = false;
  465. MessageLog.GetInstance.Show("取面完成");
  466. TakeNoodleCompleteReset();
  467. }
  468. //转台到位检测
  469. //if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace))
  470. //{
  471. // mORKS.TurntableInterlock = false;
  472. //}
  473. int OutMealRequstCount = mORKS.CookNoodlesComplete.Where(p => p == true).ToList().Count;
  474. int mlCount = mORKS.NoodleCookerStatus.Where(p => p == true).ToList().Count;
  475. mORKS.RobotTaskInterlock = OutMealRequstCount > 0 && mORKS.AllowFallNoodle && (mlCount >= 2 || mORKS.RBTakeNoodleTask.Count == 0);
  476. }
  477. #region PLC 控制函数
  478. /// <summary>
  479. /// 写入配方数据到 PLC
  480. /// </summary>
  481. private void WriteRecipeBoms()
  482. {
  483. List<ushort> recipeBoms = new List<ushort>();
  484. foreach (var item in Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds)
  485. {
  486. foreach (var rec in item.Recipes)
  487. {
  488. recipeBoms.Add((ushort)rec);
  489. }
  490. }
  491. if (recipeBoms.Count > 0)
  492. {
  493. if (ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray()))
  494. {
  495. MessageLog.GetInstance.Show("成功写入配方数据");
  496. }
  497. }
  498. else { MessageLog.GetInstance.Show("配方数据为空"); }
  499. }
  500. /// <summary>
  501. /// 转台移动
  502. /// </summary>
  503. //private void MoveTurntable()
  504. //{
  505. // //ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true);
  506. //}
  507. /// <summary>
  508. /// 取面完成复位
  509. /// </summary>
  510. private void TakeNoodleCompleteReset()
  511. {
  512. ModbusTcpHelper.GetInstance.Write(1124, WriteType.Coils, false);
  513. }
  514. /// <summary>
  515. /// 指定煮面口状态复位
  516. /// </summary>
  517. /// <param name="num"></param>
  518. private void CookNoodleStatusReset(int num)
  519. {
  520. if (num >= 1 && num <= 6)
  521. {
  522. ushort addRess = (ushort)(1136 + num - 1);
  523. ModbusTcpHelper.GetInstance.Write(addRess, WriteType.Coils, false);
  524. MessageLog.GetInstance.Show($"{num}号煮面口占用复位");
  525. }
  526. }
  527. /// <summary>
  528. /// 写配方编号
  529. /// </summary>
  530. /// <param name="num"></param>
  531. private void SetRecipeNumber(ushort num)
  532. {
  533. ModbusTcpHelper.GetInstance.Write(100, WriteType.HoldingRegisters, num);
  534. }
  535. /// <summary>
  536. /// 启动转台
  537. /// </summary>
  538. /// <param name="loc"></param>
  539. private void TurntableStart(ushort loc)
  540. {
  541. mORKS.TurntableInterlock = true;
  542. mORKS.TurntableLocLists.Add(loc);
  543. ModbusTcpHelper.GetInstance.Write(101, WriteType.HoldingRegisters, loc);
  544. ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true);
  545. }
  546. /// <summary>
  547. /// 设置倒面位置
  548. /// </summary>
  549. /// <param name="loc"></param>
  550. private void SetFallNoodleLoc(ushort loc)
  551. {
  552. ModbusTcpHelper.GetInstance.Write(102, WriteType.HoldingRegisters, loc);
  553. }
  554. /// <summary>
  555. /// 设置取面位置
  556. /// </summary>
  557. /// <param name="loc"></param>
  558. private void SetTakeNoodleLoc(ushort loc)
  559. {
  560. ModbusTcpHelper.GetInstance.Write(103, WriteType.HoldingRegisters, loc);
  561. }
  562. /// <summary>
  563. /// 取碗控制
  564. /// </summary>
  565. /// <param name="loc"></param>
  566. private void TakeBowlControl(ushort loc)
  567. {
  568. if (loc == 10)//小碗
  569. {
  570. ModbusTcpHelper.GetInstance.Write(321, WriteType.Coils, true);
  571. }
  572. else if (loc == 11)//大碗
  573. {
  574. ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true);
  575. }
  576. }
  577. /// <summary>
  578. /// 机器人取面
  579. /// </summary>
  580. private void RobotTakeNoodle()
  581. {
  582. ModbusTcpHelper.GetInstance.Write(323, WriteType.Coils, true);
  583. }
  584. /// <summary>
  585. /// 机器人取餐
  586. /// </summary>
  587. private void RobotOutMeal()
  588. {
  589. ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true);
  590. var result = ModbusTcpHelper.GetInstance.Read(324, ReadType.Coils);
  591. if (result is bool res)
  592. while (!res)
  593. {
  594. ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true);
  595. }
  596. }
  597. /// <summary>
  598. /// 制作完成信号复位
  599. /// </summary>
  600. private void ResetCookComplete()
  601. {
  602. ModbusTcpHelper.GetInstance.Write(1126, WriteType.Coils, false);
  603. }
  604. /// <summary>
  605. /// 复位允许取面信号
  606. /// </summary>
  607. private void ResetAllowFallNoodle()
  608. {
  609. ModbusTcpHelper.GetInstance.Write(1123, WriteType.Coils, false);
  610. }
  611. /// <summary>
  612. /// 设备初始化
  613. /// </summary>
  614. public async void DeviceInit()
  615. {
  616. ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, true);
  617. await Task.Delay(1000);
  618. ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, false);
  619. }
  620. #endregion
  621. }
  622. }