Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

696 linhas
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. var errorStatus = ModbusTcpHelper.GetInstance.Read((ushort)ModbusTcpHelper.GetInstance.GetBoolAddress("M235.0"), ReadType.Coils, 1);
  117. if (errorStatus != null && errorStatus is bool error) mORKS.Error = error;
  118. ModbusTcpHelper.GetInstance.Readbool(1136, 7, new Action<bool[]>((bools) =>
  119. {
  120. for (int i = 0; i < 6; i++)
  121. {
  122. mORKS.NoodleCookerStatus[i] = bools[i];
  123. }
  124. mORKS.Feeding = bools[6];
  125. }));
  126. ModbusTcpHelper.GetInstance.Readbool(1144, 6, new Action<bool[]>((bools) =>
  127. {
  128. for (int i = 0; i < 6; i++)
  129. {
  130. mORKS.CookNoodlesComplete[i] = bools[i];
  131. }
  132. }));
  133. ModbusTcpHelper.GetInstance.Readbool(1570, 20, new Action<bool[]>((bools) =>
  134. {
  135. alarm.MachineLeftLowTemperature = bools[0];
  136. alarm.MachineRightLowTemperature = bools[1];
  137. alarm.Supply1_LossBowl = bools[2];
  138. alarm.Supply2_LossBowl = bools[3];
  139. alarm.Supply1_ErrorOutBowl = bools[4];
  140. alarm.Supply2_ErrorOutBowl = bools[5];
  141. alarm.PushBowlCylinderError = bools[6];
  142. alarm.NoodleMacCommunicateError = bools[7];
  143. alarm.DosingMacCommunicateError = bools[8];
  144. alarm.RobotMacCommunicateError = bools[9];
  145. alarm.RobotInitError = bools[11];
  146. alarm.RobotUrgentStop = bools[12];
  147. alarm.RobotNotInRemoteMode = bools[13];
  148. alarm.RobotNotInReady = bools[14];
  149. alarm.RobotSelfInException = bools[15];
  150. }));
  151. var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters);
  152. if (ResLoc != null)
  153. {
  154. if (ResLoc is ushort loc)
  155. {
  156. mORKS.TurntableFeedbackloc = loc;
  157. }
  158. }
  159. Thread.Sleep(500);
  160. }), "ReadPLCData");
  161. }
  162. public void SimOrder<T>(T simOrder)
  163. {
  164. if (simOrder != null)
  165. {
  166. if (simOrder is List<ushort> locs)
  167. {
  168. string subId = Guid.NewGuid().ToString();
  169. foreach (var item in locs)
  170. {
  171. if (item >= 1 && item <= 5)
  172. {
  173. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId });
  174. MessageLog.GetInstance.Show($"添加订单:面条位置【{item}】");
  175. }
  176. if (item >= 10 && item <= 11)
  177. {
  178. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId });
  179. MessageLog.GetInstance.Show($"添加订单:碗位置【{item}】");
  180. }
  181. }
  182. }
  183. }
  184. }
  185. /// <summary>
  186. /// IOT 广播消息命令
  187. /// </summary>
  188. public void IotBroadcast<T>(T broadcast)
  189. {
  190. if (broadcast != null && broadcast is IOTCommandModel iOTCommand)
  191. {
  192. MessageLog.GetInstance.Show($"IOT 广播消息命令 {iOTCommand.deviceName} 设备命令 {iOTCommand.CommandName} 控制变量{iOTCommand.CommandValue.Keys.First()}{iOTCommand.CommandValue[iOTCommand.CommandValue.Keys.First()]}");
  193. switch (iOTCommand.CommandName)
  194. {
  195. case 0://控制类
  196. if (iOTCommand.CommandValue != null)
  197. {
  198. if (iOTCommand.CommandValue.ContainsKey("order"))
  199. {
  200. List<ushort> vs = new List<ushort>();
  201. vs.Add((ushort)(new Random().Next(1, 5)));
  202. vs.Add(ushort.Parse(iOTCommand.CommandValue["order"]));
  203. SimOrder(vs);
  204. }
  205. else if (iOTCommand.CommandValue.ContainsKey("init"))
  206. {
  207. DeviceInit();
  208. }
  209. else if (iOTCommand.CommandValue.ContainsKey("stop"))
  210. {
  211. }
  212. else if (iOTCommand.CommandValue.ContainsKey("start"))
  213. {
  214. }
  215. }
  216. break;
  217. case 1://设置属性
  218. break;
  219. case 2://通知消息
  220. break;
  221. default:
  222. break;
  223. }
  224. }
  225. }
  226. int OrderCount = 0;
  227. /// <summary>
  228. /// 数据解析
  229. /// </summary>
  230. public void DataParse<T>(T order)
  231. {
  232. OrderCount++;
  233. MessageLog.GetInstance.Show($"接收到{OrderCount}次订单");
  234. if (order is MorkOrderPush morkOrderPush)
  235. {
  236. foreach (var item in morkOrderPush.GoodBatchings)
  237. {
  238. var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  239. if (res != null)
  240. {
  241. if (ushort.TryParse(res.BatchingLoc, out ushort loc))
  242. {
  243. if (loc >= 1 && loc <= 5)
  244. {
  245. if (mORKS.RBTakeNoodleTask.FirstOrDefault(p => p.SuborderId == morkOrderPush.SuborderId) == null)
  246. mORKS.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = ushort.Parse(res.BatchingLoc), SuborderId = morkOrderPush.SuborderId, BatchingId = res.BatchingId });
  247. }
  248. else if (loc >= 10 && loc <= 11)
  249. {
  250. int index = 0;
  251. if (Json<BatchingInfoPar>.Data.recipeBoms != null)
  252. {
  253. index = Array.FindIndex(Json<BatchingInfoPar>.Data.recipeBoms?.RecipeIds.ToArray(), p => p.RecipeId == morkOrderPush.RecipeId);
  254. index++;
  255. }
  256. if (mORKS.TakeBowlTask.FirstOrDefault(p => p.SuborderId == morkOrderPush.SuborderId) == null)
  257. mORKS.TakeBowlTask.Enqueue(new OrderLocInfo()
  258. {
  259. Loc = ushort.Parse(res.BatchingLoc),
  260. SuborderId = morkOrderPush.SuborderId,
  261. RecipeNumber = (index >= 1 && index <= 10) ? (ushort)index : (ushort)0
  262. });
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. public void Main()
  270. {
  271. ThreadManage.GetInstance.StartLong(new Action(() =>
  272. {
  273. mORKS.AllowRun = mORKS.InitComplete;
  274. GeneralConfig.Healthy = mORKS.Error && mORKS.InitComplete && !GeneralConfig.EnableLocalSimOrder;
  275. TakeBowlTask();
  276. TakeNoodleTask();
  277. OutNoodleTask();
  278. SingleDetect();
  279. TurntableControl();
  280. Thread.Sleep(100);
  281. }), "MainTask");
  282. }
  283. /// <summary>
  284. /// 取碗控制
  285. /// </summary>
  286. private void TakeBowlTask()
  287. {
  288. if (mORKS.AllowRun && mORKS.TakeBowlTask.Count > 0 && !mORKS.TakeBowlIdle && !mORKS.TakeBowlInterlock)
  289. {
  290. if (mORKS.TakeBowlTask.TryDequeue(out OrderLocInfo orderLocInfo))
  291. {
  292. mORKS.TakeBowlId = orderLocInfo.SuborderId;
  293. TakeBowlControl(orderLocInfo.Loc);
  294. SetRecipeNumber(orderLocInfo.RecipeNumber);
  295. SimpleFactory.GetInstance.OrderChanged(mORKS.TakeBowlId, ORDER_STATUS.COOKING);
  296. MessageLog.GetInstance.Show($"订单【{ mORKS.TakeBowlId}】执行取碗控制,位置:[{orderLocInfo.Loc}]");
  297. }
  298. mORKS.TakeBowlInterlock = true;
  299. }
  300. }
  301. /// <summary>
  302. /// 转台控制
  303. /// </summary>
  304. private void TurntableControl()
  305. {
  306. if (GeneralConfig.EnableLocalSimOrder)
  307. {
  308. //不做轮询,直接取面,模拟订单使用
  309. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  310. {
  311. if (mORKS.TurntableLowerLimit)
  312. {
  313. TurntableStart(mORKS.RBTakeNoodleTask.ElementAt(0).Loc);
  314. mORKS.TurntableLocLists.Clear();
  315. mORKS.AllowTakeNoodle = true;
  316. MessageLog.GetInstance.Show($"控制机器人去转台【{mORKS.RBTakeNoodleTask.ElementAt(0).Loc}】号位置取面");
  317. }
  318. }
  319. }
  320. else
  321. {
  322. //正常轮询
  323. if (mORKS.TurntableMoveInPlace && !mORKS.Feeding && mORKS.InitComplete && !mORKS.AllowTakeNoodle && mORKS.RBTakeNoodleTask.Count > 0)
  324. {
  325. var result = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKS.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
  326. if (result != null)
  327. {
  328. var res = result.FirstOrDefault(P => P.BatchingLoc == mORKS.TurntableFeedbackloc.ToString());
  329. if (mORKS.TurntableLowerLimit && res != null)
  330. {
  331. //if (mORKS.RBTakeNoodleTask.ElementAt(0).Loc != mORKS.TurntableFeedbackloc)
  332. TurntableStart(mORKS.TurntableFeedbackloc);
  333. mORKS.TurntableLocLists.Clear();
  334. mORKS.AllowTakeNoodle = true;
  335. MessageLog.GetInstance.Show($"控制机器人去转台【{mORKS.TurntableFeedbackloc}】号位置取面");
  336. }
  337. else
  338. {
  339. if (!mORKS.TurntableInterlock)
  340. {
  341. foreach (var item in result)
  342. {
  343. if (ushort.TryParse(item.BatchingLoc, out ushort loc))
  344. {
  345. if (mORKS.TurntableFeedbackloc != loc && !mORKS.TurntableLocLists.Contains(loc))
  346. {
  347. TurntableStart(loc);
  348. MessageLog.GetInstance.Show($"没有物料检测的启动转台控制,转台位置:[{loc}]");
  349. break;
  350. }
  351. else if (mORKS.TurntableFeedbackloc == loc && !mORKS.TurntableLocLists.Contains(loc)) mORKS.TurntableLocLists.Add(loc);
  352. }
  353. }
  354. }
  355. }
  356. }
  357. else MessageLog.GetInstance.Show("未找到可用的物料信息");
  358. }
  359. }
  360. //转台到位检测
  361. if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
  362. {
  363. mORKS.CurrentLoc = 0;
  364. mORKS.TurntableInterlock = false;
  365. MessageLog.GetInstance.Show("转台到位检测");
  366. }
  367. //补料完成检测
  368. if (RTrig.GetInstance("FeedComplete").Start(mORKS.FeedComplete))
  369. {
  370. if (!mORKS.AllowTakeNoodle && mORKS.TurntableLocLists.Count > 0)
  371. {
  372. mORKS.TurntableLocLists.Clear();
  373. mORKS.TurntableInterlock = false;
  374. MessageLog.GetInstance.Show("补料完成检测");
  375. }
  376. }
  377. }
  378. /// <summary>
  379. /// 取面任务
  380. /// </summary>
  381. private void TakeNoodleTask()
  382. {
  383. //取面控制
  384. if (mORKS.AllowRun && mORKS.RobotIdle && !mORKS.Feeding && !mORKS.RobotTaskInterlock && mORKS.AllowTakeNoodle && mORKS.TurntableMoveInPlace && !mORKS.TakeNoodleInterlock && !mORKS.OutNoodleing && mORKS.RBTakeNoodleTask.Count > 0)
  385. {
  386. int loc = Array.FindIndex(mORKS.NoodleCookerStatus, p => p == false);//查找煮面炉空闲位置
  387. if (loc >= 0 && loc <= 5)
  388. {
  389. if (mORKS.RBTakeNoodleTask.TryDequeue(out OrderLocInfo orderLocInfo))
  390. {
  391. mORKS.CookNodelId[loc] = orderLocInfo.SuborderId;
  392. SetFallNoodleLoc((ushort)(loc + 1));
  393. //机器人开始取面
  394. RobotTakeNoodle();
  395. SimpleFactory.GetInstance.OrderChanged(orderLocInfo.SuborderId, ORDER_STATUS.COOKING);
  396. MessageLog.GetInstance.Show($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏");
  397. //写入煮面时间
  398. //List<ushort> values = new List<ushort>();
  399. //values.Add(Json<KeepDataBase>.Data.parSets.ElementAt(loc).Minute);
  400. //values.Add(Json<KeepDataBase>.Data.parSets.ElementAt(loc).Second);
  401. //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (loc * 6)}"), WriteType.HoldingRegisters, values.ToArray());
  402. mORKS.TakeNoodleInterlock = true;
  403. }
  404. }
  405. }
  406. }
  407. /// <summary>
  408. /// 出餐控制
  409. /// </summary>
  410. private void OutNoodleTask()
  411. {
  412. if (mORKS.AllowFallNoodle && mORKS.RobotTaskInterlock && !mORKS.TakeNoodleInterlock && mORKS.RobotIdle && !mORKS.TakeMealDetect)
  413. {
  414. int loc = Array.FindIndex(mORKS.CookNodelId, p => p == mORKS.IngredientsCompleteId && p.Length > 0);
  415. if (loc >= 0 && loc <= 5)
  416. {
  417. if (mORKS.CookNoodlesComplete[loc])
  418. {
  419. SetTakeNoodleLoc((ushort)(loc + 1));
  420. RobotOutMeal();
  421. CookNoodleStatusReset((ushort)(loc + 1));
  422. ResetAllowFallNoodle();
  423. mORKS.OutMealId = mORKS.IngredientsCompleteId;
  424. mORKS.IngredientsCompleteId = string.Empty;
  425. mORKS.CookNodelId[loc] = string.Empty;
  426. MessageLog.GetInstance.Show($"{loc + 1}号位置出餐控制");
  427. mORKS.OutNoodleing = true;
  428. }
  429. }
  430. }
  431. }
  432. /// <summary>
  433. /// 信号检测
  434. /// </summary>
  435. private void SingleDetect()
  436. {
  437. //允许倒面信号检测
  438. if (RTrig.GetInstance("AllowFallNoodle").Start(mORKS.AllowFallNoodle))
  439. {
  440. mORKS.IngredientsCompleteId = mORKS.TakeBowlId;
  441. mORKS.TakeBowlId = string.Empty;
  442. MessageLog.GetInstance.Show($"碗到位,允许到面,{mORKS.IngredientsCompleteId}");
  443. mORKS.TakeBowlInterlock = false;
  444. }
  445. //出餐完成信号检测
  446. if (RTrig.GetInstance("CompleteChange").Start(mORKS.RbOutMealComplete))
  447. {
  448. SimpleFactory.GetInstance.OrderChanged(mORKS.OutMealId, ORDER_STATUS.COMPLETED_COOK);
  449. MessageLog.GetInstance.Show($"订单【{mORKS.OutMealId}】制作完成");
  450. mORKS.OutNoodleing = false;
  451. }
  452. //取餐完成逻辑处理
  453. if (DelayRTrig.GetInstance("CompleteChange1").Start(mORKS.RbOutMealComplete && !mORKS.TakeMealDetect, 2))
  454. {
  455. SimpleFactory.GetInstance.OrderChanged(mORKS.OutMealId, ORDER_STATUS.COMPLETED_TAKE);
  456. MessageLog.GetInstance.Show($"订单【{mORKS.OutMealId}】取餐完成");
  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. if (Json<BatchingInfoPar>.Data.recipeBoms == null) return;
  486. foreach (var item in Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds)
  487. {
  488. foreach (var rec in item.Recipes)
  489. {
  490. recipeBoms.Add((ushort)rec);
  491. }
  492. }
  493. if (recipeBoms.Count > 0)
  494. {
  495. if (ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray()))
  496. {
  497. MessageLog.GetInstance.Show("成功写入配方数据");
  498. }
  499. }
  500. else { MessageLog.GetInstance.Show("配方数据为空"); }
  501. }
  502. /// <summary>
  503. /// 转台移动
  504. /// </summary>
  505. //private void MoveTurntable()
  506. //{
  507. // //ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true);
  508. //}
  509. /// <summary>
  510. /// 取面完成复位
  511. /// </summary>
  512. private void TakeNoodleCompleteReset()
  513. {
  514. ModbusTcpHelper.GetInstance.Write(1124, WriteType.Coils, false);
  515. }
  516. /// <summary>
  517. /// 指定煮面口状态复位
  518. /// </summary>
  519. /// <param name="num"></param>
  520. private void CookNoodleStatusReset(int num)
  521. {
  522. if (num >= 1 && num <= 6)
  523. {
  524. ushort addRess = (ushort)(1136 + num - 1);
  525. ModbusTcpHelper.GetInstance.Write(addRess, WriteType.Coils, false);
  526. MessageLog.GetInstance.Show($"{num}号煮面口占用复位");
  527. }
  528. }
  529. /// <summary>
  530. /// 写配方编号
  531. /// </summary>
  532. /// <param name="num"></param>
  533. private void SetRecipeNumber(ushort num)
  534. {
  535. ModbusTcpHelper.GetInstance.Write(100, WriteType.HoldingRegisters, num);
  536. }
  537. /// <summary>
  538. /// 启动转台
  539. /// </summary>
  540. /// <param name="loc"></param>
  541. private void TurntableStart(ushort loc)
  542. {
  543. mORKS.CurrentLoc = loc;
  544. mORKS.TurntableInterlock = true;
  545. mORKS.TurntableLocLists.Add(loc);
  546. ModbusTcpHelper.GetInstance.Write(101, WriteType.HoldingRegisters, loc);
  547. ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true);
  548. }
  549. /// <summary>
  550. /// 设置倒面位置
  551. /// </summary>
  552. /// <param name="loc"></param>
  553. private void SetFallNoodleLoc(ushort loc)
  554. {
  555. ModbusTcpHelper.GetInstance.Write(102, WriteType.HoldingRegisters, loc);
  556. }
  557. /// <summary>
  558. /// 设置取面位置
  559. /// </summary>
  560. /// <param name="loc"></param>
  561. private void SetTakeNoodleLoc(ushort loc)
  562. {
  563. ModbusTcpHelper.GetInstance.Write(103, WriteType.HoldingRegisters, loc);
  564. }
  565. /// <summary>
  566. /// 取碗控制
  567. /// </summary>
  568. /// <param name="loc"></param>
  569. private void TakeBowlControl(ushort loc)
  570. {
  571. if (loc == 10)//小碗
  572. {
  573. ModbusTcpHelper.GetInstance.Write(321, WriteType.Coils, true);
  574. }
  575. else if (loc == 11)//大碗
  576. {
  577. ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true);
  578. }
  579. }
  580. /// <summary>
  581. /// 机器人取面
  582. /// </summary>
  583. private void RobotTakeNoodle()
  584. {
  585. ModbusTcpHelper.GetInstance.Write(323, WriteType.Coils, true);
  586. }
  587. /// <summary>
  588. /// 机器人取餐
  589. /// </summary>
  590. private void RobotOutMeal()
  591. {
  592. ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true);
  593. var result = ModbusTcpHelper.GetInstance.Read(324, ReadType.Coils);
  594. if (result is bool res)
  595. while (!res)
  596. {
  597. ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true);
  598. }
  599. }
  600. /// <summary>
  601. /// 制作完成信号复位
  602. /// </summary>
  603. private void ResetCookComplete()
  604. {
  605. ModbusTcpHelper.GetInstance.Write(1126, WriteType.Coils, false);
  606. }
  607. /// <summary>
  608. /// 复位允许取面信号
  609. /// </summary>
  610. private void ResetAllowFallNoodle()
  611. {
  612. ModbusTcpHelper.GetInstance.Write(1123, WriteType.Coils, false);
  613. }
  614. /// <summary>
  615. /// 设备初始化
  616. /// </summary>
  617. public async void DeviceInit()
  618. {
  619. ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, true);
  620. await Task.Delay(1000);
  621. ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, false);
  622. }
  623. #endregion
  624. }
  625. }