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

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