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.
 
 

462 lines
16 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using HBLConsole.Interface;
  7. using HBLConsole.Communication;
  8. using System.Threading;
  9. using System.Collections.Concurrent;
  10. using HBLConsole.Model;
  11. using HBLConsole.Attributes;
  12. using System.Diagnostics;
  13. namespace HBLConsole.MORKD
  14. {
  15. public class GVL_MORKD : IGvl
  16. {
  17. #region 上位机到 --> PLC 控制
  18. /// <summary>
  19. /// 初始化控制
  20. /// </summary>
  21. public void InitControl()
  22. {
  23. ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, true);
  24. //await Task.Delay(1000);
  25. //ModbusTcpHelper.GetInstance.Write(320, WriteType.Coils, false);
  26. }
  27. /// <summary>
  28. /// 机器人取面启动
  29. /// </summary>
  30. /// <param name="CookNoodleLoc">煮面篮位置</param>
  31. /// /// <param name="TurntableLoc">转台位置</param>
  32. public void RBTakeNoodleStart(ushort CookNoodleLoc, ushort TurntableLoc)
  33. {
  34. ModbusTcpHelper.GetInstance.Write(101, WriteType.HoldingRegisters, CookNoodleLoc);
  35. ModbusTcpHelper.GetInstance.Write(100, WriteType.HoldingRegisters, TurntableLoc);
  36. ModbusTcpHelper.GetInstance.Write(321, WriteType.Coils, true);
  37. }
  38. /// <summary>
  39. /// 机器人出面启动
  40. /// </summary>
  41. /// <param name="OutNoodleLoc">出面位置</param>
  42. /// <param name="BowlLoc">倒面至碗位置</param>
  43. public void RBOutNoodleStart(ushort OutNoodleLoc, ushort BowlLoc)
  44. {
  45. ModbusTcpHelper.GetInstance.Write(102, WriteType.HoldingRegisters, OutNoodleLoc);
  46. ModbusTcpHelper.GetInstance.Write(103, WriteType.HoldingRegisters, BowlLoc);
  47. Trace.WriteLine($"#######出面位置:{OutNoodleLoc},碗位置:{BowlLoc}");
  48. ModbusTcpHelper.GetInstance.Write(322, WriteType.Coils, true);
  49. }
  50. /// <summary>
  51. /// 机器人取浇头启动
  52. /// </summary>
  53. /// <param name="SoupLoc">浇头位置</param>
  54. /// <param name="CutLoc">破口位置</param>
  55. public void RBTakeSoupStart(ushort SoupLoc, ushort CutLoc)
  56. {
  57. AllowTakeSoup = true;
  58. ModbusTcpHelper.GetInstance.Write(105, WriteType.HoldingRegisters, SoupLoc);
  59. ModbusTcpHelper.GetInstance.Write(106, WriteType.HoldingRegisters, CutLoc);
  60. ModbusTcpHelper.GetInstance.Write(323, WriteType.Coils, true);
  61. }
  62. /// <summary>
  63. /// 加热完成取浇头启动
  64. /// </summary>
  65. /// <param name="SoupLoc">取浇头完成</param>
  66. /// <param name="BowlLoc">倒浇头至碗位置</param>
  67. /// <param name="OutMealLoc">放面至出餐口位置</param>
  68. public void HeatCompleteTakeSoupStart(ushort SoupLoc, ushort BowlLoc, ushort OutMealLoc)
  69. {
  70. //2022.3.29 允许进行下一次取浇头
  71. AllowTakeSoup = false;
  72. ModbusTcpHelper.GetInstance.Write(108, WriteType.HoldingRegisters, SoupLoc);
  73. ModbusTcpHelper.GetInstance.Write(109, WriteType.HoldingRegisters, BowlLoc);
  74. ModbusTcpHelper.GetInstance.Write(110, WriteType.HoldingRegisters, OutMealLoc);
  75. ModbusTcpHelper.GetInstance.Write(324, WriteType.Coils, true);
  76. }
  77. /// <summary>
  78. /// 转台启动
  79. /// </summary>
  80. /// <param name="TurntableLoc">转台位置</param>
  81. public void TurntableStart(ushort TurntableLoc)
  82. {
  83. this.TurntableLoc = TurntableLoc;
  84. TurntableInterlock = true;
  85. if (!TurntableLocLists.Contains(TurntableLoc)) TurntableLocLists.Add(TurntableLoc);
  86. ModbusTcpHelper.GetInstance.Write(100, WriteType.HoldingRegisters, TurntableLoc);
  87. ModbusTcpHelper.GetInstance.Write(325, WriteType.Coils, true);
  88. }
  89. /// <summary>
  90. /// 下碗启动
  91. /// </summary>
  92. /// <param name="AxisLoc">启动轴位置</param>
  93. /// <param name="BowlType">碗类型位置</param>
  94. public void DropBowlStart(ushort AxisLoc, ushort BowlType)
  95. {
  96. ModbusTcpHelper.GetInstance.Write(113, WriteType.HoldingRegisters, AxisLoc);
  97. ModbusTcpHelper.GetInstance.Write(114, WriteType.HoldingRegisters, BowlType);
  98. }
  99. /// <summary>
  100. /// 取面完成信号复位
  101. /// </summary>
  102. public void TakeNoodleCompleteReset()
  103. {
  104. ModbusTcpHelper.GetInstance.Write(1122, WriteType.Coils, false);
  105. }
  106. /// <summary>
  107. /// 出面完成信号复位
  108. /// </summary>
  109. public void PutNoodleTakeMealCompleteReset()
  110. {
  111. ModbusTcpHelper.GetInstance.Write(1148, WriteType.Coils, false);
  112. OutNoodleing = false;
  113. }
  114. /// <summary>
  115. /// 取浇头完成信号复位
  116. /// </summary>
  117. public void TakeSoupCompleteReset()
  118. {
  119. ModbusTcpHelper.GetInstance.Write(1147, WriteType.Coils, false);
  120. }
  121. #endregion
  122. #region PLC --> 上位机
  123. /// <summary>
  124. /// 初始化完成
  125. /// PLC --> M100.0
  126. /// ModbusTcp --> 1120
  127. /// </summary>
  128. [Circuit(new string[] { "允许运行", "转台控制" }, "初始化完成")]
  129. [VariableMonitor("初始化完成", "M100.0", "1120")]
  130. public bool InitComplete { get; set; }
  131. /// <summary>
  132. /// 转台到位
  133. /// PLC --> M100.1
  134. /// ModbusTcp --> 1121
  135. /// </summary>
  136. [Circuit("取面任务", "转台到位检测")]
  137. [VariableMonitor("转台到位", "M100.1", "1121")]
  138. public bool TurntableInPlace { get; set; }
  139. /// <summary>
  140. /// 机器人取面完成
  141. /// PLC --> M100.2
  142. /// ModbusTcp --> 1122
  143. /// </summary>
  144. [VariableMonitor("机器人取面完成", "M100.2", "1122")]
  145. public bool RBTakeNoodleComplete { get; set; }
  146. /// <summary>
  147. /// 轴空闲
  148. /// PLC --> M100.3 -- M100.04
  149. /// ModbusTcp --> 1123 -- 1124
  150. /// </summary>
  151. [VariableMonitor("轴空闲", "M100.3", "1123")]
  152. public bool[] AxisIdle { get; set; } = new bool[2] { false, false };
  153. /// <summary>
  154. /// 轴允许倒面
  155. /// PLC --> M100.5 -- M100.06
  156. /// ModbusTcp --> 1125 -- 1126
  157. /// </summary>
  158. [VariableMonitor("轴允许倒面", "M100.5", "1125")]
  159. public bool[] AxisAllowInvertedNoodle { get; set; } = new bool[2] { false, false };
  160. /// <summary>
  161. /// 轴允许倒浇头
  162. /// PLC --> M100.7 -- M101.00
  163. /// ModbusTcp --> 1127 -- 1128
  164. /// </summary>
  165. [VariableMonitor("轴允许倒浇头", "M100.7", "1127")]
  166. public bool[] AxisAllowInvertedSoup { get; set; } = new bool[2] { false, false };
  167. /// <summary>
  168. /// 浇头加热完成
  169. /// PLC --> M101.1 -- M101.02
  170. /// ModbusTcp --> 1129 -- 1130
  171. /// </summary>
  172. [VariableMonitor("浇头加热完成", "M101.1", "1129")]
  173. public bool[] SoupHeatComplete { get; set; } = new bool[2] { false, false };
  174. /// <summary>
  175. /// 煮面篮空闲
  176. /// PLC --> M101.3 -- M102.0
  177. /// ModbusTcp --> 1131 -- 1136
  178. /// </summary>
  179. [VariableMonitor("煮面篮空闲", "M101.3", "1131")]
  180. public bool[] CookNoodleBasketIdle { get; set; } = new bool[6] { false, false, false, false, false, false };
  181. /// <summary>
  182. /// 煮面完成
  183. /// PLC --> M102.1 -- M102.6
  184. /// ModbusTcp --> 1137 -- 1142
  185. /// </summary>
  186. [VariableMonitor("煮面完成", "M102.1", "1137")]
  187. public bool[] CookNoodleComplete { get; set; } = new bool[6] { false, false, false, false, false, false };
  188. /// <summary>
  189. /// 取面机器人空闲状态
  190. /// PLC --> M102.7
  191. /// ModbusTcp --> 1143
  192. /// </summary>
  193. [Circuit(new string[] { "取面任务", "出餐控制" }, "取面机器人空闲")]
  194. [VariableMonitor("取面机器人空闲状态", "M102.7", "1143")]
  195. public bool TakeNoodleRobotIdle { get; set; }
  196. /// <summary>
  197. /// 取浇头机器人空闲状态
  198. /// PLC --> M103.0
  199. /// ModbusTcp --> 1144
  200. /// </summary>
  201. [Circuit(new string[] { "取浇头控制", "出浇头控制" }, "取浇头机器人空闲状态")]
  202. [VariableMonitor("取浇头机器人空闲状态", "M103.0", "1144")]
  203. public bool TakeSoupRobotIdle { get; set; }
  204. /// <summary>
  205. /// 破口机构空闲
  206. /// PLC --> M103.1 -- M103.02
  207. /// ModbusTcp --> 1145 -- 1146
  208. /// </summary>
  209. [VariableMonitor("破口机构空闲", "M103.1", "1145")]
  210. public bool[] BreakMechanismIdle { get; set; } = new bool[2] { false, false };
  211. /// <summary>
  212. /// 取浇头完成
  213. /// PLC --> M103.3
  214. /// ModbusTcp --> 1147
  215. /// </summary>
  216. [VariableMonitor("取浇头完成", "M103.3", "1147")]
  217. public bool TakeSoupComplete { get; set; }
  218. /// <summary>
  219. /// 放面至取餐口完成
  220. /// PLC --> M103.4
  221. /// ModbusTcp --> 1148
  222. /// </summary>
  223. [VariableMonitor("放面至取餐口完成", "M103.4", "1148")]
  224. public bool PutNoodleTakeMealComplete { get; set; }
  225. /// <summary>
  226. /// 设备初始化中
  227. /// PLC --> M103.5
  228. /// ModbusTcp --> 1149
  229. /// </summary>
  230. [VariableMonitor("设备初始化中", "M103.5", "1149")]
  231. public bool Initing { get; set; }
  232. /// <summary>
  233. /// 转台反馈位置
  234. /// PLC -> VW1240
  235. /// ModbusTcp -> 720
  236. /// </summary>
  237. [VariableMonitor("转台反馈位置", "VW1240", "720")]
  238. public ushort TurntableFeedbackloc { get; set; }
  239. #endregion
  240. #region 传感器状态
  241. /// <summary>
  242. /// 转台下限位
  243. /// PLC --> M120.0
  244. /// ModbusTcp --> 1200
  245. /// </summary>
  246. [VariableMonitor("转台下限位", "M120.0", "1280")]
  247. public bool TurntableLowerLimit { get; set; }
  248. /// <summary>
  249. /// 转台上限位
  250. /// PLC --> M120.1
  251. /// ModbusTcp --> 1201
  252. /// </summary>
  253. [VariableMonitor("转台上限位", "M120.1", "1281")]
  254. public bool TurntableUpLimit { get; set; }
  255. /// <summary>
  256. /// 浇头缺料
  257. /// PLC --> M120.2 -- M120.6
  258. /// ModbusTcp --> 1202 -- 1206
  259. /// </summary>
  260. [VariableMonitor("浇头缺料", "M120.2", "1282")]
  261. public bool[] SoupMaterialShortage { get; set; } = new bool[5] { false, false, false, false, false };
  262. /// <summary>
  263. /// 出餐口检测
  264. /// PLC --> M120.7 -- M121.1
  265. /// ModbusTcp --> 1207 -- 1209
  266. /// </summary>
  267. [VariableMonitor("出餐口检测", "M120.7", "1287")]
  268. public bool[] OutMealDetect { get; set; } = new bool[3] { false, false, false };
  269. /// <summary>
  270. /// 温度到达
  271. /// PLC --> M121.2
  272. /// ModbusTcp --> 1210
  273. /// </summary>
  274. [VariableMonitor("温度到达", "M121.2", "1290")]
  275. public bool TemperatureReached { get; set; }
  276. #endregion
  277. #region 内部变量
  278. /// <summary>
  279. /// 允许倒浇头
  280. /// </summary>
  281. [Circuit(new string[] { "出浇头控制" }, "允许倒浇头", new bool[] { true })]
  282. [VariableMonitor("允许倒浇头")]
  283. public bool AllowPutSoup { get; set; }
  284. /// <summary>
  285. /// 允许取浇头
  286. /// </summary>
  287. [Circuit(new string[] { "取浇头控制", "出浇头控制" }, "允许取浇头", new bool[] { true, true })]
  288. [VariableMonitor("允许取浇头")]
  289. public bool AllowTakeSoup { get; set; }
  290. /// <summary>
  291. /// 放面位置
  292. /// </summary>
  293. [VariableMonitor("放面位置")]
  294. public int PutNoodleLoc { get; set; }
  295. /// <summary>
  296. /// 轴空闲位置
  297. /// </summary>
  298. [VariableMonitor("轴空闲位置")]
  299. public int AxisIdleIndex { get; set; }
  300. /// <summary>
  301. /// 轴空闲互锁位置
  302. /// </summary>
  303. [VariableMonitor("轴空闲互锁位置")]
  304. public int AxisIdleLockIndex { get; set; }
  305. /// <summary>
  306. /// 转台位置
  307. /// </summary>
  308. [VariableMonitor("转台位置")]
  309. public ushort TurntableLoc { get; set; }
  310. /// <summary>
  311. /// 机器人任务互锁信号
  312. /// </summary>
  313. [Circuit(new string[] { "取面任务", "出餐控制" }, "机器人任务互锁", new bool[] { true, false })]
  314. [VariableMonitor("机器人任务互锁信号")]
  315. public bool RobotTaskInterlock { get; set; }
  316. /// <summary>
  317. /// 取碗互锁信号
  318. /// </summary>
  319. [VariableMonitor("取碗互锁信号")]
  320. public bool TakeBowlInterlock { get; set; }
  321. /// <summary>
  322. /// 取面互锁信号
  323. /// </summary>
  324. [Circuit(new string[] { "出餐控制" }, "取面互锁信号", new bool[] { true })]
  325. [VariableMonitor("取面互锁信号")]
  326. public bool TakeNoodleInterlock { get; set; }
  327. /// <summary>
  328. /// 出面中
  329. /// </summary>
  330. [Circuit(new string[] { "取面任务" }, "出面中", new bool[] { true })]
  331. [VariableMonitor("出面中")]
  332. public bool OutNoodleing { get; set; }
  333. /// <summary>
  334. /// 允许取面
  335. /// </summary>
  336. [Circuit(new string[] { "转台控制", "取面任务" }, "允许取面", new bool[] { true, false })]
  337. [VariableMonitor("允许取面")]
  338. public bool AllowTakeNoodle { get; set; }
  339. /// <summary>
  340. /// 转台互锁信号
  341. /// </summary>
  342. [Circuit(new string[] { "转台控制" }, "转台互锁信号", new bool[] { true })]
  343. [VariableMonitor("转台互锁信号")]
  344. public bool TurntableInterlock { get; set; }
  345. [VariableMonitor("煮面炉互锁")]
  346. public bool[] CookNodeState { get; set; } = new bool[6] { false, false, false, false, false, false };
  347. /// <summary>
  348. /// 轴空闲互锁
  349. /// </summary>
  350. [VariableMonitor("轴空闲互锁")]
  351. public bool[] AxisIdleLock { get; set; } = new bool[2] { false, false };
  352. /// <summary>
  353. /// 转台位置轮询
  354. /// </summary>
  355. public List<ushort> TurntableLocLists = new List<ushort>();
  356. /// <summary>
  357. /// 允许运行
  358. /// </summary>
  359. [Circuit(new string[] { "取面任务", "取浇头控制" }, "允许运行")]
  360. [VariableMonitor("允许运行")]
  361. public bool AllowRun { get; set; }
  362. /// <summary>
  363. /// 取面位置队列
  364. /// </summary>
  365. public ConcurrentQueue<OrderLocInfo> RBTakeNoodleTask { get; set; } = new ConcurrentQueue<OrderLocInfo>();
  366. /// <summary>
  367. /// 取浇头任务队列
  368. /// </summary>
  369. public ConcurrentQueue<OrderLocInfo> TakeSoupTask { get; set; } = new ConcurrentQueue<OrderLocInfo>();
  370. /// <summary>
  371. ///取碗任务队列
  372. /// </summary>
  373. public ConcurrentQueue<OrderLocInfo> TakeBowlTask { get; set; } = new ConcurrentQueue<OrderLocInfo>();
  374. /// <summary>
  375. /// 煮面完成任务队列
  376. /// </summary>
  377. public ConcurrentQueue<ushort> CookNoodleCompleteTask { get; set; } = new ConcurrentQueue<ushort>();
  378. #endregion
  379. #region 内部变量 --> 订单ID记录
  380. /// <summary>
  381. /// 煮面口对应的订单ID
  382. /// </summary>
  383. public string[] CookNodelId { get; set; } = new string[6] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, };
  384. /// <summary>
  385. /// 出餐口订单ID
  386. /// </summary>
  387. public string[] OutMealId { get; set; } = new string[3] { string.Empty, string.Empty, string.Empty };
  388. /// <summary>
  389. /// 轴允许倒面 id
  390. /// </summary>
  391. public string[] AxisAllowInvertedNoodleID { get; set; } = new string[2] { string.Empty, string.Empty };
  392. /// <summary>
  393. /// 轴允许倒浇头 id
  394. /// </summary>
  395. public string[] AxisAllowInvertedSoupID { get; set; } = new string[2] { string.Empty, string.Empty };
  396. /// <summary>
  397. /// 浇头加热位 id
  398. /// </summary>
  399. public string[] SoupHeatLocID { get; set; } = new string[2] { string.Empty, string.Empty };
  400. #endregion
  401. }
  402. }