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.
 
 

701 lines
26 KiB

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