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.
 
 

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