终端一体化运控平台
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.
 
 
 

1132 lines
40 KiB

  1. using BPA.Message;
  2. using BPA.Message.Enum;
  3. using BPASmartClient.Business;
  4. using BPASmartClient.Device;
  5. using BPASmartClient.EventBus;
  6. using BPASmartClient.Helper;
  7. using BPASmartClient.Message;
  8. using BPASmartClient.Model;
  9. using BPASmartClient.Model.大炒;
  10. using BPASmartClient.MorkBF.Model;
  11. using BPASmartClient.MorkBF.ViewModel;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using static BPASmartClient.EventBus.EventBus;
  19. using static BPASmartClient.Model.大炒.FryPotMessages;
  20. namespace BPASmartClient.MorkBF
  21. {
  22. public class Control_MorkBF : BaseDevice
  23. {
  24. GVL_MorkBF morkBF = new GVL_MorkBF();
  25. public override DeviceClientType DeviceType => DeviceClientType.MORKCS;
  26. int RobotLeadTime = 5;//机器人提前动作时间 s
  27. public override void DoMain()
  28. {
  29. IsHealth = true;
  30. BPASmartClient.Helper.Json<LocalFryPotMessage>.Read();
  31. MonitorViewModel.DeviceId = DeviceId;
  32. ActionManage.GetInstance.Register(new Action(() =>
  33. {
  34. GlobalFoodMenu.LocalFoodMenus.Clear();
  35. if(BPASmartClient.Helper.Json<LocalFryPotMessage>.Data.FryPotMessage.Count>0)
  36. {
  37. foreach (var item in BPASmartClient.Helper.Json<LocalFryPotMessage>.Data.FryPotMessage)
  38. {
  39. GlobalFoodMenu.LocalFoodMenus.Add(new FoodMenuModel { GoodKey = item.GoodKey, GoodName = item.GoodName });
  40. }
  41. }
  42. }), "更新菜单");
  43. CommandRegist();//调试
  44. ServerInit();
  45. DataParse();//数据解析
  46. ScreenDataServer();//大屏数据上报
  47. ActionManage.GetInstance.Send("更新菜单");
  48. DeviceProcessLogShow("MORKF 设备初始化完成");
  49. }
  50. private void DataParse()
  51. {
  52. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  53. {
  54. if (@event == null) return;
  55. if (@event is DoOrderEvent order)
  56. {
  57. if (order.MorkOrder.GoodBatchings == null) return;
  58. OrderCount++;
  59. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  60. }
  61. });
  62. }
  63. private void ServerInit()
  64. {
  65. //物料信息
  66. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  67. {
  68. if (@event == null) return;
  69. if (@event is MaterialDeliveryEvent material)
  70. {
  71. orderMaterialDelivery = material.orderMaterialDelivery;
  72. }
  73. });
  74. //配方数据信息
  75. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  76. {
  77. if (@event == null) return;
  78. if (@event is RecipeBomEvent recipe)
  79. {
  80. recipeBoms = recipe.recipeBoms;
  81. }
  82. });
  83. }
  84. /// <summary>
  85. /// 调试
  86. /// </summary>
  87. /// <exception cref="NotImplementedException"></exception>
  88. private void CommandRegist()
  89. {
  90. #region 炒锅1
  91. ActionManage.GetInstance.Register(FirePot1_SetFireGear, "FirePot1_SetFireGear");//炒锅1设定加热挡位
  92. ActionManage.GetInstance.Register(FirePot1_StartFire, "FirePot1_StartFire");//炒锅1加热启动
  93. ActionManage.GetInstance.Register(FirePot1_StartFire, "FirePot1_StopFire");//炒锅1关闭加热
  94. ActionManage.GetInstance.Register(FirePot1_SetStirGear, "FirePot1_SetStirGear");//炒锅1设定搅拌挡位
  95. ActionManage.GetInstance.Register(FirePot1_StartStir, "FirePot1_StartStir");//炒锅1搅拌启动
  96. ActionManage.GetInstance.Register(FirePot1_StartStir, "FirePot1_StopStir");//炒锅1搅拌停止
  97. ActionManage.GetInstance.Register(FirePot1_SetTurnSpeed, "FirePot1_SetTurnSpeed");//炒锅1翻转频率设定
  98. #endregion
  99. #region 炒锅2
  100. ActionManage.GetInstance.Register(FirePot2_SetFireGear, "FirePot2_SetFireGear");//炒锅2设定加热挡位
  101. ActionManage.GetInstance.Register(FirePot2_StartFire, "FirePot2_StartFire");//炒锅2加热启动
  102. ActionManage.GetInstance.Register(FirePot2_StartFire, "FirePot2_StopFire");//炒锅2关闭加热
  103. ActionManage.GetInstance.Register(FirePot2_SetStirGear, "FirePot2_SetStirGear");//炒锅2设定搅拌挡位
  104. ActionManage.GetInstance.Register(FirePot2_StartStir, "FirePot2_StartStir");//炒锅2搅拌启动
  105. ActionManage.GetInstance.Register(FirePot2_StartStir, "FirePot2_StopStir");//炒锅2搅拌停止
  106. ActionManage.GetInstance.Register(FirePot2_SetTurnSpeed, "FirePot2_SetTurnSpeed");//炒锅2翻转频率设定
  107. #endregion
  108. #region 炒锅通用
  109. ActionManage.GetInstance.Register(FirePot_Reset, "FirePot_Reset");//复位;
  110. ActionManage.GetInstance.Register(FirePot_PotGotoOrigin, "FirePot_PotGotoOrigin");//炒锅回原点
  111. ActionManage.GetInstance.Register(FirePot_PotGotoP1, "FirePot_PotGotoP1");//炒锅去位置1
  112. ActionManage.GetInstance.Register(FirePot_PotGotoP2, "FirePot_PotGotoP2");//炒锅去位置2
  113. ActionManage.GetInstance.Register(FirePot_PotGotoP3, "FirePot_PotGotoP3");//炒锅去位置3
  114. ActionManage.GetInstance.Register(FirePot_PotGotoP4, "FirePot_PotGotoP4");//炒锅去位置4
  115. //ActionManage.GetInstance.Register(FirePot_PotGotoOutFoodPosition, "FirePot_PotGotoOutFoodPositiong");//炒锅去出餐位置
  116. ActionManage.GetInstance.Register(FirePot_PotGotoInFoodPosition, "FirePot_PotGotoInFoodPosition");//炒锅去投料位置
  117. ActionManage.GetInstance.Register(FirePot_StartOutFood, "FirePot_StartOutFood");//出餐启动
  118. ActionManage.GetInstance.Register(FirePot_Clean, "FirePot_Clean");//清洗
  119. ActionManage.GetInstance.Register(FirePot_StartPumpWater, "FirePot_StartPumpWater");//抽水启动
  120. ActionManage.GetInstance.Register(FirePot_StartPumpOil, "FirePot_StartPumpOil");//抽油启动
  121. #endregion
  122. #region 机器人
  123. ActionManage.GetInstance.Register(RobotStart, "RobotStart");//机器人启动
  124. ActionManage.GetInstance.Register(RobotStop, "RobotStop");//机器人停止
  125. ActionManage.GetInstance.Register(RobotReset, "RobotReset");//复位
  126. ActionManage.GetInstance.Register(RobotProgramStart, "RobotProgramStart");//程序启动
  127. ActionManage.GetInstance.Register(Robot_Pot1AllowInMaterail, "Robot_Pot1AllowInMaterail");//1号炒锅允许机器人投料
  128. ActionManage.GetInstance.Register(Robot_Pot1OutFoodInSlowDown, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料到减速位
  129. ActionManage.GetInstance.Register(Robot_Pot1OutFood, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料完成
  130. ActionManage.GetInstance.Register(Robot_Pot2AllowInMaterail, "Robot_Pot2AllowInMaterail");//2号炒锅允许机器人投料
  131. ActionManage.GetInstance.Register(Robot_Pot2OutFoodInSlowDown, "Robot_Pot2OutFoodInSlowDown");//2号炒锅出餐倒料到减速位
  132. ActionManage.GetInstance.Register(Robot_Pot2OutFood, "Robot_Pot2OutFood");//2号炒锅出餐倒料完成
  133. ActionManage.GetInstance.Register(RobotActionStart, "Robot_Pot2OutFood");//2号炒锅出餐倒料完成
  134. #endregion
  135. }
  136. public override void MainTask()
  137. {
  138. if(morkBF.FirePan1_Order.Count>0&& morkBF.FirePot1_InitCompleted&&morkBF.FirePot2_IsAuto&&!morkBF.FirePan1_Busy)
  139. {
  140. ThreadManage.GetInstance().Start(FirePot1_Process, "炒锅1流程");
  141. }
  142. if(morkBF.RobotActinQueue.Count>0&&! morkBF.Robot_Origin)//机器人在原点为
  143. {
  144. if( morkBF.RobotActinQueue.TryDequeue(out RobotAction_Pot robotAction))
  145. {
  146. morkBF.Robot_IsBusy =true;
  147. RobotProcess(robotAction);
  148. }
  149. }
  150. }
  151. private void FirePot1_Process()
  152. {
  153. if(morkBF.FirePan1_Order.TryDequeue(out FryPotMessages result))
  154. {
  155. morkBF.FirePan1_Busy = true;
  156. morkBF.FryPot1_CurrentProcess = result.fryPotProcesses;
  157. foreach (var item in result.fryPotProcesses)
  158. {
  159. switch (item.fryActions)
  160. {
  161. case FryAction.冷锅加热:
  162. FirePot_PotPerHeat(item, 1);
  163. MessageLog.GetInstance.Show("炒锅1---冷锅加热完成");
  164. break;
  165. case FryAction.热油:
  166. FirePot_HeatOil(item,1);
  167. MessageLog.GetInstance.Show("炒锅1---热油完成");
  168. break;
  169. case FryAction.加调料:
  170. FirePot_AddSeasoning(item, 1);
  171. MessageLog.GetInstance.Show("炒锅1---加调料完成");
  172. break;
  173. case FryAction.加辅料:
  174. FirePot_AddAccessories(item,1);
  175. MessageLog.GetInstance.Show("炒锅1---加辅料完成");
  176. break;
  177. case FryAction.炒制菜品:
  178. FirePot_FryFood(item,1);
  179. MessageLog.GetInstance.Show("炒锅1---炒制菜品完成");
  180. break;
  181. default:
  182. break;
  183. }
  184. }
  185. }
  186. }
  187. private void FirePot2_Process()
  188. {
  189. }
  190. #region 炒锅流程功能
  191. private bool IsRobotNextWork(List<FryPotProcess> currentProcess, int currentFryTime)
  192. {
  193. bool res = false;
  194. if(currentProcess.Count> currentFryTime)
  195. {
  196. if (currentProcess[currentFryTime + 1].fryActions == FryAction.加调料 ||
  197. currentProcess[currentFryTime + 1].fryActions == FryAction.加辅料 ||
  198. currentProcess[currentFryTime + 1].fryActions == FryAction.炒制菜品)
  199. {
  200. res = true;
  201. }
  202. }
  203. return res;
  204. }
  205. /// <summary>
  206. /// 冷锅预热
  207. /// </summary>
  208. private void FirePot_PotPerHeat(FryPotProcess item,int i)
  209. {
  210. bool isRobotWork = false;
  211. if(i == 1)//炒锅1
  212. {
  213. FirePot1_SetFireGear(item.FryGear);
  214. Thread.Sleep(200);
  215. FirePot1_StartFire(true);
  216. isRobotWork = IsRobotNextWork(morkBF.FryPot1_CurrentProcess,item.FryTime);
  217. }
  218. else if(i == 2)//炒锅2
  219. {
  220. FirePot2_SetFireGear(item.FryGear);
  221. FirePot2_StartFire(true);
  222. isRobotWork = IsRobotNextWork(morkBF.FryPot2_CurrentProcess, item.FryTime);
  223. }
  224. if (isRobotWork && item.FryDuration > RobotLeadTime) Thread.Sleep((item.FryDuration - RobotLeadTime) * 1000);//提前10秒机器人去取物料
  225. else Thread.Sleep(item.FryDuration * 1000);
  226. }
  227. /// <summary>
  228. /// 热油
  229. /// </summary>
  230. private void FirePot_HeatOil(FryPotProcess item, int i)
  231. {
  232. bool isRobotWork = false;
  233. if (item.FryGear != 0)
  234. {
  235. FirePot1_SetFireGear(item.FryGear);//设定加热挡位
  236. FirePot1_StartFire(true);//开启加热
  237. isRobotWork = IsRobotNextWork(morkBF.FryPot1_CurrentProcess, item.FryTime);
  238. }
  239. if (item.StirGear != 0)
  240. {
  241. FirePot1_SetStirGear(item.StirGear);//设定搅拌挡位
  242. FirePot1_StartFire(true);//开启搅拌
  243. isRobotWork = IsRobotNextWork(morkBF.FryPot2_CurrentProcess, item.FryTime);
  244. }
  245. if (isRobotWork && item.FryDuration > RobotLeadTime) Thread.Sleep((item.FryDuration - RobotLeadTime) * 1000);//提前10秒机器人去取物料
  246. else Thread.Sleep(item.FryDuration * 1000);//加热时间;
  247. }
  248. /// <summary>
  249. /// 加调料
  250. /// </summary>
  251. private void FirePot_AddSeasoning(FryPotProcess item,int i)
  252. {
  253. if(i == 1)
  254. {
  255. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot { Pot =1,robotActionModel = RobotActionModel.取1号炒锅调料盆倒入1号炒锅});
  256. Thread.Sleep(item.FryDuration);
  257. }
  258. else if(i == 2)
  259. {
  260. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot { Pot = 2, robotActionModel = RobotActionModel.取2号炒锅调料盆倒入2号炒锅 });
  261. Thread.Sleep(item.FryDuration);
  262. }
  263. }
  264. /// <summary>
  265. /// 加辅料
  266. /// </summary>
  267. private void FirePot_AddAccessories(FryPotProcess item, int i)
  268. {
  269. if (i == 1)
  270. {
  271. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot { Pot = 1, robotActionModel = RobotActionModel.取1号炒锅辅料盆1倒入1号炒锅 });
  272. Thread.Sleep(item.FryDuration);
  273. }
  274. else if (i == 2)
  275. {
  276. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot { Pot = 2, robotActionModel = RobotActionModel.取2号炒锅辅料盆1倒入2号炒锅 });
  277. Thread.Sleep(item.FryDuration);
  278. }
  279. }
  280. /// <summary>
  281. /// 炒制菜品
  282. /// </summary>
  283. private void FirePot_FryFood(FryPotProcess item, int i)
  284. {
  285. bool isRobotWork = false;
  286. if (i == 1)
  287. {
  288. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot { Pot = 1, robotActionModel = (RobotActionModel)item.accessories[0].Loc });
  289. while (!morkBF.FirePot1_CompleteSingle[item.accessories[0].Loc])//取菜信号是否完成
  290. {
  291. Thread.Sleep(100);
  292. }
  293. isRobotWork = IsRobotNextWork(morkBF.FryPot2_CurrentProcess, item.FryTime);
  294. }
  295. else if (i == 2)
  296. {
  297. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot { Pot = 2, robotActionModel = (RobotActionModel)(item.accessories[0].Loc+19) });//炒制菜品位置
  298. while (!morkBF.FirePot2_CompleteSingle[item.accessories[0].Loc])//取菜信号是否完成
  299. {
  300. Thread.Sleep(100);
  301. }
  302. isRobotWork = IsRobotNextWork(morkBF.FryPot2_CurrentProcess, item.FryTime);
  303. }
  304. if (isRobotWork && item.FryDuration > RobotLeadTime) Thread.Sleep((item.FryDuration - RobotLeadTime) * 1000);//提前10秒机器人去取物料
  305. else Thread.Sleep(item.FryDuration * 1000);//加热时间;
  306. }
  307. #endregion
  308. /// <summary>
  309. /// 机器人进程
  310. /// </summary>
  311. /// <param name="robotAction"></param>
  312. private void RobotProcess(RobotAction_Pot robotAction)
  313. {
  314. Robot_Write("GI0",(int)robotAction.robotActionModel);
  315. while (morkBF.Robot_ActionCallback != (int)robotAction.robotActionModel)//机器人动作执行完动作反馈
  316. {
  317. Thread.Sleep(100);
  318. }
  319. if(robotAction.Pot == 1)//炒锅1
  320. {
  321. if (robotAction.robotActionModel == RobotActionModel.取1号空盆出餐)
  322. {
  323. Robot_Write("GM520", true);//机器人去出餐倒料减速位置
  324. while(!morkBF.Robot_ArriveFirePot1)//机器人到位,请求1#炒锅倒菜
  325. {
  326. Thread.Sleep(100);
  327. }
  328. FirePot_StartOutFood(1);//炒锅出餐;
  329. while (!morkBF.FirePot1_PotOnOutFoodPosition)//炒锅在出餐倒料位置反馈
  330. {
  331. Thread.Sleep(1000);
  332. }
  333. Thread.Sleep(6 * 1000);//等待6s出餐
  334. Robot_Write("GM521", true);//机器人出餐到料完成
  335. }
  336. else
  337. {
  338. FirePot_Write("M11.6", true);//炒锅去投料位置
  339. while (!morkBF.FirePot1_PotOnIntoFoodPosition)//等待炒锅允许倒料
  340. {
  341. Thread.Sleep(100);
  342. }
  343. Robot_Write("GM531", true);//机器人投料
  344. }
  345. }
  346. else if (robotAction.Pot == 2)
  347. {
  348. if (robotAction.robotActionModel == RobotActionModel.取1号空盆出餐)
  349. {
  350. Robot_Write("GM522", true);//炒锅去出餐倒料减速位置
  351. while (!morkBF.Robot_ArriveFirePot2)//机器人到位,请求1#炒锅倒菜
  352. {
  353. Thread.Sleep(100);
  354. }
  355. FirePot_StartOutFood(2);//炒锅去出餐倒料位置
  356. while (!morkBF.FirePot2_PotOnOutFoodPosition)//炒锅在出餐倒料位置反馈
  357. {
  358. Thread.Sleep(1000);
  359. }
  360. Thread.Sleep(6 * 1000);//等待20s出餐
  361. Robot_Write("GM523", true);//机器人出餐倒料完成
  362. }
  363. else
  364. {
  365. FirePot_Write("M16.7", true);
  366. while (!morkBF.FirePot2_PotOnIntoFoodPosition)
  367. {
  368. Thread.Sleep(100);
  369. }
  370. Robot_Write("GM531", true);
  371. }
  372. }
  373. while(!morkBF.Robot_Origin)
  374. {
  375. Thread.Sleep(1000);
  376. }
  377. morkBF.Robot_IsBusy = false;
  378. MessageLog.GetInstance.Show($"机器人完成[{robotAction.robotActionModel.ToString()}]任务");
  379. }
  380. public override void ReadData()
  381. {
  382. GetStatus("M20.0",new Action<object>((o)=>
  383. {
  384. if (o == null) return;
  385. if(o is bool[] values&&values.Length == 19)
  386. {
  387. morkBF.FirePot1_InitCompleted = values[0];
  388. morkBF.FirePot1_IsAuto = values[1];
  389. morkBF.FirePot1_Emergencystop = values[2];
  390. morkBF.FirePot1_MealTubExist = values[3];
  391. morkBF.FirePot1_VegetablesTub1Exist = values[4];
  392. morkBF.FirePot1_VegetablesTub2Exist = values[5];
  393. morkBF.FirePot1_Seasoning1Exist = values[6];
  394. morkBF.FirePot1_Seasoning2Exist = values[7];
  395. morkBF.FirePot1_Accessories1Exist = values[8];
  396. morkBF.FirePot1_Accessories2Exist = values[9];
  397. morkBF.FirePot1_OutFoodTubExist = values[10];
  398. morkBF.FirePot1_OnOrigin = values[11];
  399. morkBF.FirePot1_FirePosition1 = values[12];
  400. morkBF.FirePot1_FirePosition2 = values[13];
  401. morkBF.FirePot1_FirePosition3 = values[14];
  402. morkBF.FirePot1_FirePosition4 = values[15];
  403. morkBF.FirePot1_PotOnOutFoodPosition = values[16];
  404. morkBF.FirePot1_PotOnIntoFoodPosition = values[17];
  405. morkBF.FirePot1_PotOnCleanPosition = values[18];
  406. }
  407. }),0);
  408. GetStatus("VW120", new Action<object>((o) =>
  409. {
  410. if (o == null) return;
  411. if (o is int[] values&&values.Length == 2)
  412. {
  413. morkBF.FirePot1_Temperature = values[0];
  414. morkBF.FirePot1_Pulse = values[1];
  415. }
  416. }), 0);
  417. GetStatus("M25.0", new Action<object>((o) =>
  418. {
  419. if (o == null) return;
  420. if (o is bool[] values&& values.Length == 19)
  421. {
  422. morkBF.FirePot2_InitCompleted = values[0];
  423. morkBF.FirePot2_IsAuto = values[1];
  424. morkBF.FirePot2_Emergencystop = values[2];
  425. morkBF.FirePot2_MealTubExist = values[3];
  426. morkBF.FirePot2_VegetablesTub1Exist = values[4];
  427. morkBF.FirePot2_VegetablesTub2Exist = values[5];
  428. morkBF.FirePot2_Seasoning1Exist = values[6];
  429. morkBF.FirePot2_Seasoning2Exist = values[7];
  430. morkBF.FirePot2_Accessories1Exist = values[8];
  431. morkBF.FirePot2_Accessories2Exist = values[9];
  432. morkBF.FirePot2_OutFoodTubExist = values[10];
  433. morkBF.FirePot2_OnOrigin = values[11];
  434. morkBF.FirePot2_FirePosition1 = values[12];
  435. morkBF.FirePot2_FirePosition2 = values[13];
  436. morkBF.FirePot2_FirePosition3 = values[14];
  437. morkBF.FirePot2_FirePosition4 = values[15];
  438. morkBF.FirePot2_PotOnOutFoodPosition = values[16];
  439. morkBF.FirePot2_PotOnIntoFoodPosition = values[17];
  440. morkBF.FirePot2_PotOnCleanPosition = values[18];
  441. }
  442. }), 0);
  443. GetStatus("VW150", new Action<object>((o) =>
  444. {
  445. if (o == null) return;
  446. if (o is int[] values&& values.Length == 2)
  447. {
  448. morkBF.FirePot2_Temperature = values[0];
  449. morkBF.FirePot2_Pulse = values[1];
  450. }
  451. }), 0);
  452. GetStatus("GM500", new Action<object>((o) =>
  453. {
  454. if (o == null) return;
  455. if (o is bool[] values && values.Length == 7)
  456. {
  457. morkBF.FirePot1_CompleteSingle[0] = values[0];
  458. morkBF.FirePot1_CompleteSingle[1] = values[1];
  459. morkBF.FirePot1_CompleteSingle[2] = values[2];
  460. morkBF.Robot_FirePot1OutSeasoning = values[3];
  461. morkBF.Robot_FirePot1OutAccessories = values[4];
  462. morkBF.Robot_ArriveFirePot1 = values[5];
  463. morkBF.Robot_FirePot1OutFoodComplete = values[6];
  464. }
  465. }), 1);
  466. GetStatus("GM510", new Action<object>((o) =>
  467. {
  468. if (o == null) return;
  469. if (o is bool[] values && values.Length == 7)
  470. {
  471. morkBF.FirePot2_CompleteSingle[0] = values[0];
  472. morkBF.FirePot2_CompleteSingle[1] = values[1];
  473. morkBF.FirePot2_CompleteSingle[2] = values[2];
  474. morkBF.Robot_FirePot2OutSeasoning = values[3];
  475. morkBF.Robot_FirePot2OutAccessories = values[4];
  476. morkBF.Robot_ArriveFirePot2 = values[5];
  477. morkBF.Robot_FirePot2OutFoodComplete = values[6];
  478. }
  479. }), 1);
  480. GetStatus("GI5", new Action<object>((o) =>
  481. {
  482. if (o == null) return;
  483. if (o is int[] values && values.Length == 1)
  484. {
  485. morkBF.Robot_ActionCallback = values[0];
  486. }
  487. }), 1);
  488. }
  489. public override void ResetProgram()
  490. {
  491. morkBF = null;
  492. morkBF = new GVL_MorkBF();
  493. }
  494. public override void SimOrder()
  495. {
  496. }
  497. public override void Stop()
  498. {
  499. }
  500. /// <summary>
  501. /// 获取炒锅PLC的所有状态
  502. /// </summary>
  503. /// <param name="key"></param>
  504. /// <param name="action"></param>
  505. /// <param name="num">炒锅编号</param>
  506. private void GetStatus(string key, Action<object> action, int num)
  507. {
  508. if (dicPort2peripheralStatus.ContainsKey(num))
  509. {
  510. if (dicPort2peripheralStatus[num].ContainsKey(key))
  511. {
  512. action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值
  513. }
  514. }
  515. }
  516. #region 控制
  517. private void FirePot_Write(string address, object value, int i = 0)
  518. {
  519. WriteControlExact(address, value, i);
  520. }
  521. private void Robot_Write(string address, object value, int i = 1)
  522. {
  523. WriteControlExact(address, value, i);
  524. }
  525. #region 炒锅1
  526. /// <summary>
  527. /// 炒锅1设定加热挡位
  528. /// </summary>
  529. /// <param name="o"></param>
  530. private void FirePot1_SetFireGear(object o)
  531. {
  532. if (o == null) return;
  533. if (int.TryParse(o.ToString(), out int value))
  534. {
  535. FirePot_Write("VW100", (ushort)value);
  536. }
  537. Thread.Sleep(200);
  538. }
  539. /// <summary>
  540. /// 炒锅1加热启停
  541. /// </summary>
  542. /// <param name="b"></param>
  543. private void FirePot1_StartFire(object o)
  544. {
  545. if (o == null) return;
  546. if (bool.TryParse(o.ToString(), out bool value))
  547. {
  548. FirePot_Write("M10.0", value);
  549. }
  550. Thread.Sleep(200);
  551. FirePot_Write("M10.2", true);
  552. }
  553. /// <summary>
  554. /// 炒锅1设置搅拌挡位
  555. /// </summary>
  556. /// <param name="o"></param>
  557. private void FirePot1_SetStirGear(object o)
  558. {
  559. if (o == null) return;
  560. if (int.TryParse(o.ToString(), out int value))
  561. {
  562. FirePot_Write("VW102", (ushort)value);
  563. }
  564. Thread.Sleep(200);
  565. FirePot_Write("M10.3", true);
  566. }
  567. /// <summary>
  568. /// 炒锅1搅拌启停
  569. /// </summary>
  570. /// <param name="o"></param>
  571. private void FirePot1_StartStir(object o)
  572. {
  573. if (o == null) return;
  574. if (bool.TryParse(o.ToString(), out bool value))
  575. {
  576. FirePot_Write("M10.1", value);
  577. }
  578. Thread.Sleep(200);
  579. }
  580. /// <summary>
  581. /// 设置炒锅1翻转速度
  582. /// </summary>
  583. /// <param name="o"></param>
  584. private void FirePot1_SetTurnSpeed(object o)
  585. {
  586. if (o == null) return;
  587. if (int.TryParse(o.ToString(), out int value))
  588. {
  589. FirePot_Write("VW104", (ushort)value);
  590. }
  591. Thread.Sleep(200);
  592. FirePot_Write("M10.4", true);
  593. Thread.Sleep(200);
  594. }
  595. #endregion
  596. #region 炒锅2
  597. /// <summary>
  598. /// 炒锅2设定加热挡位
  599. /// </summary>
  600. /// <param name="o"></param>
  601. private void FirePot2_SetFireGear(object o)
  602. {
  603. if (o == null) return;
  604. if (int.TryParse(o.ToString(), out int value))
  605. {
  606. FirePot_Write("VW130", (ushort)value);
  607. }
  608. Thread.Sleep(200);
  609. FirePot_Write("M15.2", true);
  610. }
  611. /// <summary>
  612. /// 炒锅2加热启停
  613. /// </summary>
  614. /// <param name="b"></param>
  615. private void FirePot2_StartFire(object o)
  616. {
  617. if (o == null) return;
  618. if (o is bool value)
  619. {
  620. FirePot_Write("M15.0", value);
  621. }
  622. Thread.Sleep(200);
  623. }
  624. /// <summary>
  625. /// 炒锅2设置搅拌挡位
  626. /// </summary>
  627. /// <param name="o"></param>
  628. private void FirePot2_SetStirGear(object o)
  629. {
  630. if (o == null) return;
  631. if (o is int value)
  632. {
  633. FirePot_Write("VW132", (ushort)value);
  634. }
  635. Thread.Sleep(200);
  636. FirePot_Write("M15.3", true);
  637. Thread.Sleep(200);
  638. }
  639. /// <summary>
  640. /// 炒锅2搅拌启停
  641. /// </summary>
  642. /// <param name="o"></param>
  643. private void FirePot2_StartStir(object o)
  644. {
  645. if (o == null) return;
  646. if (o is bool value)
  647. {
  648. FirePot_Write("M15.1", value);
  649. }
  650. Thread.Sleep(200);
  651. }
  652. /// <summary>
  653. /// 设置炒锅2翻转速度
  654. /// </summary>
  655. /// <param name="o"></param>
  656. private void FirePot2_SetTurnSpeed(object o)
  657. {
  658. if (o == null) return;
  659. if (o is int value)
  660. {
  661. FirePot_Write("VW134", (ushort)value);
  662. }
  663. Thread.Sleep(200);
  664. FirePot_Write("M15.4", true);
  665. Thread.Sleep(200);
  666. }
  667. #endregion
  668. #region 炒锅通用
  669. /// <summary>
  670. /// 炒锅复位
  671. /// </summary>
  672. /// <param name="o"></param>
  673. private void FirePot_Reset(object o)
  674. {
  675. if (o == null) return;
  676. if (int.TryParse(o.ToString(), out int i))
  677. {
  678. if (i == 1)
  679. {
  680. }
  681. else if (i == 2)
  682. {
  683. }
  684. }
  685. }
  686. /// <summary>
  687. /// 炒锅回原点
  688. /// </summary>
  689. /// <param name="o"></param>
  690. private void FirePot_PotGotoOrigin(object o)
  691. {
  692. if (o == null) return;
  693. if (int.TryParse(o.ToString(), out int i))
  694. {
  695. if (i == 1)
  696. {
  697. FirePot_Write("M10.5", true);
  698. }
  699. else if (i == 2)
  700. {
  701. FirePot_Write("M15.5", true);
  702. }
  703. }
  704. Thread.Sleep(200);
  705. }
  706. /// <summary>
  707. /// 炒锅去位置1
  708. /// </summary>
  709. /// <param name="o"></param>
  710. private void FirePot_PotGotoP1(object o)
  711. {
  712. if (o == null) return;
  713. if (int.TryParse(o.ToString(), out int i))
  714. {
  715. if (i == 1)
  716. {
  717. FirePot_Write("M11.2", true);
  718. }
  719. else if (i == 2)
  720. {
  721. FirePot_Write("M16.2", true);
  722. }
  723. }
  724. Thread.Sleep(200);
  725. }
  726. /// <summary>
  727. /// 炒锅去位置2
  728. /// </summary>
  729. /// <param name="o"></param>
  730. private void FirePot_PotGotoP2(object o)
  731. {
  732. if (o == null) return;
  733. if (int.TryParse(o.ToString(), out int i))
  734. {
  735. if (i == 1)
  736. {
  737. FirePot_Write("M11.3", true);
  738. }
  739. else if (i == 2)
  740. {
  741. FirePot_Write("M16.3", true);
  742. }
  743. }
  744. Thread.Sleep(200);
  745. }
  746. /// <summary>
  747. /// 炒锅去位置3
  748. /// </summary>
  749. /// <param name="o"></param>
  750. private void FirePot_PotGotoP3(object o)
  751. {
  752. if (o == null) return;
  753. if (int.TryParse(o.ToString(), out int i))
  754. {
  755. if (i == 1)
  756. {
  757. FirePot_Write("M11.4", true);
  758. }
  759. else if (i == 2)
  760. {
  761. FirePot_Write("M16.4", true);
  762. }
  763. }
  764. Thread.Sleep(200);
  765. }
  766. /// <summary>
  767. /// 炒锅去位置4
  768. /// </summary>
  769. /// <param name="o"></param>
  770. private void FirePot_PotGotoP4(object o)
  771. {
  772. if (o == null) return;
  773. if (int.TryParse(o.ToString(), out int i))
  774. {
  775. if (i == 1)
  776. {
  777. FirePot_Write("M11.5", true);
  778. }
  779. else if (i == 2)
  780. {
  781. FirePot_Write("M16.5", true);
  782. }
  783. }
  784. Thread.Sleep(200);
  785. }
  786. ///// <summary>
  787. ///// 炒锅去出餐位置
  788. ///// </summary>
  789. ///// <param name="o"></param>
  790. //private void FirePot_PotGotoOutFoodPositiong(object o)
  791. //{
  792. // if (o == null) return;
  793. // if (o is int i)
  794. // {
  795. // if (i == 1)
  796. // {
  797. // FirePot_Write("M11.6", true);
  798. // }
  799. // else if (i == 2)
  800. // {
  801. // FirePot_Write("M16.6", true);
  802. // }
  803. // }
  804. // Thread.Sleep(200);
  805. //}
  806. /// <summary>
  807. /// 炒锅去投料位置
  808. /// </summary>
  809. /// <param name="o"></param>
  810. private void FirePot_PotGotoInFoodPosition(object o)
  811. {
  812. if (o == null) return;
  813. if (int.TryParse(o.ToString() ,out int i))
  814. {
  815. if (i == 1)
  816. {
  817. FirePot_Write("M11.6", true);
  818. }
  819. else if (i == 2)
  820. {
  821. FirePot_Write("M16.6", true);
  822. }
  823. }
  824. Thread.Sleep(200);
  825. }
  826. /// <summary>
  827. /// 出餐启动
  828. /// </summary>
  829. /// <param name="o"></param>
  830. private void FirePot_StartOutFood(object o)
  831. {
  832. if (o == null) return;
  833. if (int.TryParse(o.ToString(), out int i))
  834. {
  835. if (i == 1)
  836. {
  837. FirePot_Write("M10.6", true);
  838. }
  839. else if (i == 2)
  840. {
  841. FirePot_Write("M15.6", true);
  842. }
  843. }
  844. Thread.Sleep(200);
  845. }
  846. /// <summary>
  847. /// 清洗
  848. /// </summary>
  849. /// <param name="o"></param>
  850. private void FirePot_Clean(object o)
  851. {
  852. if (o == null) return;
  853. if (int.TryParse(o.ToString(), out int i))
  854. {
  855. if (i == 1)
  856. {
  857. if(morkBF.FirePot1_OnOrigin) FirePot_Write("M10.7", true);
  858. }
  859. else if (i == 2)
  860. {
  861. if (morkBF.FirePot2_OnOrigin) FirePot_Write("M15.7", true);
  862. }
  863. }
  864. Thread.Sleep(200);
  865. }
  866. /// <summary>
  867. /// 抽水启动
  868. /// </summary>
  869. /// <param name="o"></param>
  870. private void FirePot_StartPumpWater(object o)
  871. {
  872. if (o == null) return;
  873. if (int.TryParse(o.ToString(), out int i))
  874. {
  875. if (i == 1)
  876. {
  877. FirePot_Write("M11.0", true);
  878. }
  879. else if (i == 2)
  880. {
  881. FirePot_Write("M16.0", true);
  882. }
  883. }
  884. Thread.Sleep(200);
  885. }
  886. /// <summary>
  887. /// 抽油启动
  888. /// </summary>
  889. /// <param name="o"></param>
  890. private void FirePot_StartPumpOil(object o)
  891. {
  892. if (o == null) return;
  893. if (int.TryParse(o.ToString(), out int i))
  894. {
  895. if (i == 1)
  896. {
  897. FirePot_Write("M16.0", true);
  898. }
  899. else if (i == 2)
  900. {
  901. FirePot_Write("M16.1", true);
  902. }
  903. }
  904. Thread.Sleep(200);
  905. }
  906. #endregion
  907. #region 机器人
  908. /// <summary>
  909. /// 机器人启动
  910. /// </summary>
  911. private void RobotStart()
  912. {
  913. Robot_Write("GM600",true);
  914. Thread.Sleep(200);
  915. }
  916. /// <summary>
  917. /// 机器人停止
  918. /// </summary>
  919. private void RobotStop()
  920. {
  921. Robot_Write("GM601", true);
  922. Thread.Sleep(200);
  923. }
  924. /// <summary>
  925. /// 机器人复位
  926. /// </summary>
  927. private void RobotReset()
  928. {
  929. Robot_Write("GM602", true);
  930. Thread.Sleep(200);
  931. }
  932. /// <summary>
  933. /// 机器人程序重启
  934. /// </summary>
  935. private void RobotProgramStart()
  936. {
  937. Robot_Write("GM603", true);
  938. Thread.Sleep(200);
  939. }
  940. /// <summary>
  941. /// 1号炒锅允许机器人投料(炒锅在投料位给出)
  942. /// </summary>
  943. private void Robot_Pot1AllowInMaterail()
  944. {
  945. Robot_Write("GM531", true);
  946. Thread.Sleep(200);
  947. }
  948. /// <summary>
  949. /// 1号炒锅出餐倒料到减速位
  950. /// </summary>
  951. private void Robot_Pot1OutFoodInSlowDown()
  952. {
  953. Robot_Write("GM620", true);
  954. Thread.Sleep(200);
  955. }
  956. /// <summary>
  957. /// 1号炒锅出餐倒料完成
  958. /// </summary>
  959. private void Robot_Pot1OutFood()
  960. {
  961. Robot_Write("GM521", true);
  962. Thread.Sleep(200);
  963. }
  964. /// <summary>
  965. /// 2号炒锅允许机器人投料(炒锅在投料位给出)
  966. /// </summary>
  967. private void Robot_Pot2AllowInMaterail()
  968. {
  969. Robot_Write("GM530", true);
  970. Thread.Sleep(200);
  971. }
  972. /// <summary>
  973. /// 2号炒锅出餐倒料到减速位。开始倒菜
  974. /// </summary>
  975. private void Robot_Pot2OutFoodInSlowDown()
  976. {
  977. Robot_Write("GM522", true);
  978. Thread.Sleep(200);
  979. }
  980. /// <summary>
  981. /// 2号炒锅出餐倒料完成
  982. /// </summary>
  983. private void Robot_Pot2OutFood()
  984. {
  985. Robot_Write("GM523", true);
  986. Thread.Sleep(200);
  987. }
  988. /// <summary>
  989. ///
  990. /// </summary>
  991. private void RobotActionStart(object o)
  992. {
  993. if (o == null) return;
  994. if(int.TryParse(o.ToString(), out int value))
  995. {
  996. Robot_Write("GI0",value);
  997. }
  998. Thread.Sleep(200);
  999. }
  1000. #endregion
  1001. #endregion
  1002. private void ScreenDataServer()
  1003. {
  1004. LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒);
  1005. ThreadManage.GetInstance().StartLong(new Action(() =>
  1006. {
  1007. List<StatsModel> statsModels = new List<StatsModel>();
  1008. statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 });
  1009. ScreenModelMaxWok maxWok = new ScreenModelMaxWok
  1010. {
  1011. IsRun = IsHealth ? IsRun.运行 : IsRun.停止,
  1012. WorkStatus_1 = morkBF.FirePot1_Temperature > 0 ? WorkStatus.工作 : WorkStatus.待机,
  1013. WorkStatus_2 = morkBF.FirePot2_Temperature > 0 ? WorkStatus.工作 : WorkStatus.待机,
  1014. RobotStatu = morkBF.Robot_ActionCallback == 0? WorkStatus.待机 : WorkStatus.工作,
  1015. Alarm = new List<AlarmModel>(),
  1016. FailuresCount = 0,
  1017. StatsCount = statsModels,
  1018. MaxWok_Dishes_1 = "满汉全席",
  1019. MaxWok_Dishes_2 = "海鲜大餐",
  1020. MaxWok_Task_1 = "无",
  1021. MaxWok_Task_2 = "无",
  1022. MaxWok_Process_1 = new List<ProcessModel>(),
  1023. MaxWok_HeatGear_1 = morkBF.FirePot1_FireGear.ToString(),
  1024. MaxWok_HeatGear_2 = morkBF.FirePot2_FireGear.ToString(),
  1025. MaxWok_StirGear_1 = morkBF.FirePot1_StirGear.ToString(),
  1026. MaxWok_StirGear_2 = morkBF.FirePot2_StirGear.ToString(),
  1027. MaxWok_FlipSpeed_1 = morkBF.FirePot1_FlipSpeed.ToString(),
  1028. MaxWok_FlipSpeed_2 = morkBF.FirePot2_FlipSpeed.ToString(),
  1029. MaxWok_Temp_1 = new Random().Next(250, 450).ToString(),
  1030. MaxWok_Temp_2 = new Random().Next(250, 450).ToString(),
  1031. MaxWok_OrderCount_1 = 2,
  1032. MaxWok_OrderCount_2 = 2,
  1033. MaxWok_ErrorOrderCount_1 = 0,
  1034. MaxWok_ErrorOrderCount_2 = 0,
  1035. };
  1036. LocalMqtt.GetInstance.Publish(maxWok);
  1037. Thread.Sleep(1000);
  1038. }), "大屏数据上报");
  1039. }
  1040. }
  1041. }