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

998 line
35 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. //ThreadManage.GetInstance().Start(FirePot1_Process, "炒锅1流程");
  50. DeviceProcessLogShow("MORKF 设备初始化完成");
  51. }
  52. private void DataParse()
  53. {
  54. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  55. {
  56. if (@event == null) return;
  57. if (@event is DoOrderEvent order)
  58. {
  59. if (order.MorkOrder.GoodBatchings == null) return;
  60. OrderCount++;
  61. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  62. }
  63. });
  64. }
  65. private void ServerInit()
  66. {
  67. //物料信息
  68. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  69. {
  70. if (@event == null) return;
  71. if (@event is MaterialDeliveryEvent material)
  72. {
  73. orderMaterialDelivery = material.orderMaterialDelivery;
  74. }
  75. });
  76. //配方数据信息
  77. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  78. {
  79. if (@event == null) return;
  80. if (@event is RecipeBomEvent recipe)
  81. {
  82. recipeBoms = recipe.recipeBoms;
  83. }
  84. });
  85. }
  86. /// <summary>
  87. /// 调试
  88. /// </summary>
  89. /// <exception cref="NotImplementedException"></exception>
  90. private void CommandRegist()
  91. {
  92. #region 炒锅
  93. ActionManage.GetInstance.Register(FirePot_SetFireGear, "FirePot_SetFireGear");//炒锅设定加热挡位
  94. ActionManage.GetInstance.Register(FirePot_StartFire, "FirePot_StartFire");//炒锅加热启动
  95. ActionManage.GetInstance.Register(FirePot_StartFire, "FirePot_StopFire");//炒锅关闭加热
  96. ActionManage.GetInstance.Register(FirePot_SetStirGear, "FirePot_SetStirGear");//炒锅设定搅拌挡位
  97. ActionManage.GetInstance.Register(FirePot_StartStir, "FirePot_StartStir");//炒锅搅拌启动
  98. ActionManage.GetInstance.Register(FirePot_StartStir, "FirePot_StopStir");//炒锅搅拌停止
  99. ActionManage.GetInstance.Register(FirePot_SetTurnSpeed, "FirePot_SetTurnSpeed");//炒锅翻转频率设定
  100. ActionManage.GetInstance.Register(FirePot_SetPotAngle, "FirePot_SetPotAngle");//设定炒锅角度
  101. ActionManage.GetInstance.Register(FirePot_StartPassWay, "FirePot_StartPassWay");//炒锅翻转频率设定
  102. ActionManage.GetInstance.Register(FirePot_Reset, "FirePot_Reset");//复位;
  103. ActionManage.GetInstance.Register(FirePot_PotGotoOrigin, "FirePot_PotGotoOrigin");//炒锅回原点
  104. ActionManage.GetInstance.Register(FirePot_PotGotoInFoodPosition, "FirePot_PotGotoInFoodPosition");//炒锅去投料位置
  105. ActionManage.GetInstance.Register(FirePot_StartOutFood, "FirePot_StartOutFood");//出餐启动
  106. ActionManage.GetInstance.Register(FirePot_Clean, "FirePot_Clean");//清洗
  107. ActionManage.GetInstance.Register(FirePot_StartPumpWater, "FirePot_StartPumpWater");//抽水启动
  108. ActionManage.GetInstance.Register(FirePot_StartPumpWater, "FirePot_StopPumpWater");//抽水关闭
  109. ActionManage.GetInstance.Register(FirePot_PushReach, "FirePot_PushReach");//推杆伸出
  110. ActionManage.GetInstance.Register(FirePot_PushRetract, "FirePot_PushRetract");//推杆缩回
  111. ActionManage.GetInstance.Register(FirePot_PotForward, "FirePot_PotForward");//翻转正转
  112. ActionManage.GetInstance.Register(FirePot_PotReversal, "FirePot_PotReversal");//翻转反转
  113. #endregion
  114. #region 机器人
  115. ActionManage.GetInstance.Register(RobotAction, "RobotAction");//上使能
  116. #endregion
  117. }
  118. public override void MainTask()
  119. {
  120. if(morkBF.RobotActinQueue.Count>0&&! morkBF.Robot_Start)//机器人启动
  121. {
  122. if( morkBF.RobotActinQueue.TryDequeue(out RobotAction_Pot robotAction))
  123. {
  124. morkBF.Robot_IsBusy =true;
  125. RobotProcess(robotAction);
  126. }
  127. }
  128. }
  129. private void FirePot1_Process()
  130. {
  131. if (morkBF.FirePan1_Order.Count > 0 && morkBF.FirePot1_InitCompleted && morkBF.FirePot2_IsAuto && !morkBF.FirePan1_Busy)
  132. {
  133. if (morkBF.FirePan1_Order.TryDequeue(out FryPotMessages result))
  134. {
  135. morkBF.FirePan1_Busy = true;
  136. morkBF.FryPot1_CurrentProcess = result.fryPotProcesses;
  137. foreach (var item in result.fryPotProcesses)
  138. {
  139. switch (item.fryActions)
  140. {
  141. case FryAction.冷锅加热:
  142. FirePot_PotPerHeat(item, 1);
  143. MessageLog.GetInstance.Show("炒锅1---冷锅加热完成");
  144. break;
  145. case FryAction.热油:
  146. FirePot_HeatOil(item, 1);
  147. MessageLog.GetInstance.Show("炒锅1---热油完成");
  148. break;
  149. case FryAction.机器人加调料:
  150. FirePot_RobotGetSeasoning(item, 1);
  151. MessageLog.GetInstance.Show("炒锅1---机器人加调料完成");
  152. break;
  153. case FryAction.通道出调料:
  154. FirePot_PasswayOutSeasoning(item, 1);
  155. MessageLog.GetInstance.Show("炒锅1---通道出调料完成");
  156. break;
  157. case FryAction.炒制菜品:
  158. FirePot_FryFood(item, 1);
  159. MessageLog.GetInstance.Show("炒锅1---炒制菜品完成");
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. FirePot_StartFire(new object[] { 1, false });//关火
  166. Thread.Sleep(result.FryOffStirTime*1000);//关火翻炒时间
  167. FirePot_StartStir(new object[] { 1, false });//关闭搅拌
  168. Message.MessageLog.GetInstance.Show($"炒锅1炒制{result.GoodName}完成");
  169. }
  170. }
  171. }
  172. private void FirePot2_Process()
  173. {
  174. }
  175. #region 炒锅流程功能
  176. /// <summary>
  177. /// 判断下个动作是否需要机器人
  178. /// </summary>
  179. /// <param name="i"></param>
  180. /// <param name="currentFryTime"></param>
  181. /// <returns></returns>
  182. private bool IsRobotNextWork(int i, int currentFryTime)
  183. {
  184. bool res = false;
  185. List<FryPotProcess> currentProcess = new List<FryPotProcess>();
  186. currentProcess = i == 1 ? morkBF.FryPot1_CurrentProcess: morkBF.FryPot2_CurrentProcess;
  187. if (currentProcess.Count> currentFryTime)
  188. {
  189. if (currentProcess[currentFryTime + 1].fryActions == FryAction.机器人加调料 ||
  190. currentProcess[currentFryTime + 1].fryActions == FryAction.炒制菜品)
  191. {
  192. res = true;
  193. }
  194. }
  195. return res;
  196. }
  197. /// <summary>
  198. /// 冷锅预热
  199. /// </summary>
  200. private void FirePot_PotPerHeat(FryPotProcess item,int i)
  201. {
  202. bool isRobotWork = false;
  203. FirePot_SetFireGear(new object[]{ i, item.FryGear});//设定加热挡位
  204. FirePot_StartFire(new object[] { i, true });
  205. isRobotWork = IsRobotNextWork(i,item.FryTime);//下个流程动作是否需要机器人
  206. if (isRobotWork && item.FryDuration > RobotLeadTime) Thread.Sleep((item.FryDuration - RobotLeadTime) * 1000);//提前10秒机器人去取物料
  207. else Thread.Sleep(item.FryDuration * 1000);
  208. }
  209. /// <summary>
  210. /// 热油
  211. /// </summary>
  212. private void FirePot_HeatOil(FryPotProcess item, int i)
  213. {
  214. bool isRobotWork = false;
  215. if (item.FryGear != 0)
  216. {
  217. FirePot_SetFireGear(new object[] { i, item.FryGear });//设定加热挡位
  218. FirePot_StartFire(new object[] { i, true });
  219. }
  220. if (item.StirGear != 0)
  221. {
  222. FirePot_SetStirGear(new object[] { i, item.StirGear });//设定搅拌挡位
  223. FirePot_StartStir(new object[] { i, true });
  224. }
  225. isRobotWork = IsRobotNextWork(i, item.FryTime);
  226. if (isRobotWork && item.FryDuration > RobotLeadTime) Thread.Sleep((item.FryDuration - RobotLeadTime) * 1000);//提前10秒机器人去取物料
  227. else Thread.Sleep(item.FryDuration * 1000);//加热时间;
  228. }
  229. /// <summary>
  230. /// 通道出调料
  231. /// </summary>
  232. private void FirePot_PasswayOutSeasoning(FryPotProcess item,int i)
  233. {
  234. foreach(var acc in item.accessories)
  235. {
  236. FirePot_StartPassWay(new object[] { i, acc.Loc, acc.Qry });
  237. }
  238. }
  239. /// <summary>
  240. /// 机器人取调料
  241. /// </summary>
  242. private void FirePot_RobotGetSeasoning(FryPotProcess item, int i)
  243. {
  244. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot
  245. {
  246. Pot = i,
  247. MainTask = BPASmartClient.Model.大炒.MainTask.机器人炒制任务,
  248. subTask1 = (SubTask1)item.accessories[0].Loc + 9,
  249. subTask2 = (SubTask2)i
  250. });
  251. }
  252. /// <summary>
  253. /// 炒制菜品
  254. /// </summary>
  255. private void FirePot_FryFood(FryPotProcess item, int i)
  256. {
  257. bool isRobotWork = false;
  258. morkBF.RobotActinQueue.Enqueue(new RobotAction_Pot
  259. {
  260. Pot = i,
  261. MainTask = BPASmartClient.Model.大炒.MainTask.机器人炒制任务,
  262. subTask1 = (SubTask1)item.accessories[1].Loc,
  263. subTask2 =(SubTask2)i
  264. });
  265. while (!morkBF.FirePot1_CompleteSingle[item.accessories[0].Loc])//取菜信号是否完成
  266. {
  267. Thread.Sleep(100);
  268. }
  269. isRobotWork = IsRobotNextWork(i, item.FryTime);
  270. if (isRobotWork && item.FryDuration > RobotLeadTime) Thread.Sleep((item.FryDuration - RobotLeadTime) * 1000);//提前10秒机器人去取物料
  271. else Thread.Sleep(item.FryDuration * 1000);//加热时间;
  272. }
  273. #endregion
  274. /// <summary>
  275. /// 机器人进程
  276. /// </summary>
  277. /// <param name="robotAction"></param>
  278. private void RobotProcess(RobotAction_Pot robotAction)
  279. {
  280. Robot_Write("GI0", (int)robotAction.MainTask);//设定机器人主要任务
  281. while(morkBF.Robot_GI0ActionCallback != (int)robotAction.MainTask)//等待主程序完成反馈
  282. {
  283. Thread.Sleep(300);
  284. }
  285. if((int)robotAction.subTask1>0&& (int)robotAction.subTask1<16)//任务1
  286. {
  287. Robot_Write("GI1", (int)robotAction.subTask1);
  288. Thread.Sleep(1000);
  289. while (morkBF.Robot_GI1ActionCallback != (int)robotAction.subTask1)//等待子程序1完成反馈
  290. {
  291. Thread.Sleep(300);
  292. }
  293. }
  294. if((int)robotAction.subTask1>15) //出餐
  295. {
  296. }
  297. if ((int)robotAction.subTask2 > 0)//任务2
  298. {
  299. Robot_Write("GI2", (int)robotAction.subTask2);
  300. Thread.Sleep(1000);
  301. while (morkBF.Robot_GI2ActionCallback != (int)robotAction.subTask2)//等待子程序2完成反馈
  302. {
  303. Thread.Sleep(300);
  304. }
  305. while (morkBF.Robot_OutMaterialCompleted)//等待子程序2完成反馈
  306. {
  307. Thread.Sleep(300);
  308. }
  309. }
  310. if ((int)robotAction.subTask3 > 0)//任务3
  311. {
  312. Robot_Write("GI3", (int)robotAction.subTask3);
  313. Thread.Sleep(1000);
  314. while (morkBF.Robot_GI3ActionCallback != (int)robotAction.subTask3)//等待子程序3完成反馈
  315. {
  316. Thread.Sleep(300);
  317. }
  318. }
  319. if ((int)robotAction.subTask4 > 0)//任务4
  320. {
  321. Robot_Write("GI4", (int)robotAction.subTask4);
  322. Thread.Sleep(1000);
  323. while (morkBF.Robot_GI4ActionCallback != (int)robotAction.subTask4)//等待主程序4完成反馈
  324. {
  325. Thread.Sleep(300);
  326. }
  327. }
  328. MessageLog.GetInstance.Show($"机器人完成[{robotAction.MainTask.ToString()}]任务");
  329. }
  330. public override void ReadData()
  331. {
  332. GetStatus("M20.0",new Action<object>((o)=>
  333. {
  334. if (o == null) return;
  335. if(o is bool[] values&&values.Length == 19)
  336. {
  337. morkBF.FirePot1_InitCompleted = values[0];
  338. morkBF.FirePot1_IsAuto = values[1];
  339. morkBF.FirePot1_Emergencystop = values[2];
  340. morkBF.FirePot1_MealTubExist = values[3];
  341. morkBF.FirePot1_VegetablesTub1Exist = values[4];
  342. morkBF.FirePot1_VegetablesTub2Exist = values[5];
  343. morkBF.FirePot1_Seasoning1Exist = values[6];
  344. morkBF.FirePot1_Seasoning2Exist = values[7];
  345. morkBF.FirePot1_Accessories1Exist = values[8];
  346. morkBF.FirePot1_Accessories2Exist = values[9];
  347. morkBF.FirePot1_OutFoodTubExist = values[10];
  348. morkBF.FirePot1_OnOrigin = values[11];
  349. morkBF.FirePot1_FirePosition1 = values[12];
  350. morkBF.FirePot1_FirePosition2 = values[13];
  351. morkBF.FirePot1_FirePosition3 = values[14];
  352. morkBF.FirePot1_FirePosition4 = values[15];
  353. morkBF.FirePot1_PotOnOutFoodPosition = values[16];
  354. morkBF.FirePot1_PotOnIntoFoodPosition = values[17];
  355. morkBF.FirePot1_PotOnCleanPosition = values[18];
  356. }
  357. }),0);
  358. GetStatus("VW120", new Action<object>((o) =>
  359. {
  360. if (o == null) return;
  361. if (o is int[] values&&values.Length == 2)
  362. {
  363. morkBF.FirePot1_Temperature = values[0];
  364. morkBF.FirePot1_Pulse = values[1];
  365. }
  366. }), 0);
  367. GetStatus("M25.0", new Action<object>((o) =>
  368. {
  369. if (o == null) return;
  370. if (o is bool[] values&& values.Length == 19)
  371. {
  372. morkBF.FirePot2_InitCompleted = values[0];
  373. morkBF.FirePot2_IsAuto = values[1];
  374. morkBF.FirePot2_Emergencystop = values[2];
  375. morkBF.FirePot2_MealTubExist = values[3];
  376. morkBF.FirePot2_VegetablesTub1Exist = values[4];
  377. morkBF.FirePot2_VegetablesTub2Exist = values[5];
  378. morkBF.FirePot2_Seasoning1Exist = values[6];
  379. morkBF.FirePot2_Seasoning2Exist = values[7];
  380. morkBF.FirePot2_Accessories1Exist = values[8];
  381. morkBF.FirePot2_Accessories2Exist = values[9];
  382. morkBF.FirePot2_OutFoodTubExist = values[10];
  383. morkBF.FirePot2_OnOrigin = values[11];
  384. morkBF.FirePot2_FirePosition1 = values[12];
  385. morkBF.FirePot2_FirePosition2 = values[13];
  386. morkBF.FirePot2_FirePosition3 = values[14];
  387. morkBF.FirePot2_FirePosition4 = values[15];
  388. morkBF.FirePot2_PotOnOutFoodPosition = values[16];
  389. morkBF.FirePot2_PotOnIntoFoodPosition = values[17];
  390. morkBF.FirePot2_PotOnCleanPosition = values[18];
  391. }
  392. }), 0);
  393. GetStatus("VW150", new Action<object>((o) =>
  394. {
  395. if (o == null) return;
  396. if (o is int[] values&& values.Length == 2)
  397. {
  398. morkBF.FirePot2_Temperature = values[0];
  399. morkBF.FirePot2_Pulse = values[1];
  400. }
  401. }), 0);
  402. GetStatus("VW2250", new Action<object>((o) =>
  403. {
  404. if (o == null) return;
  405. if (o is int[] values && values.Length == 1)
  406. {
  407. dataReport.FirePot1_PotState = values[0];
  408. }
  409. }), 1);
  410. GetStatus("VW2350", new Action<object>((o) =>
  411. {
  412. if (o == null) return;
  413. if (o is int[] values && values.Length == 1)
  414. {
  415. dataReport.FirePot2_PotState = values[0];
  416. }
  417. }), 1);
  418. }
  419. public override void ResetProgram()
  420. {
  421. morkBF = null;
  422. morkBF = new GVL_MorkBF();
  423. }
  424. public override void SimOrder()
  425. {
  426. }
  427. public override void Stop()
  428. {
  429. }
  430. /// <summary>
  431. /// 获取炒锅PLC的所有状态
  432. /// </summary>
  433. /// <param name="key"></param>
  434. /// <param name="action"></param>
  435. /// <param name="num">炒锅编号</param>
  436. private void GetStatus(string key, Action<object> action, int num)
  437. {
  438. if (dicPort2peripheralStatus.ContainsKey(num))
  439. {
  440. if (dicPort2peripheralStatus[num].ContainsKey(key))
  441. {
  442. action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值
  443. }
  444. }
  445. }
  446. #region 控制
  447. private void FirePot1_Write(string address, object value, int i = 0)
  448. {
  449. WriteControlExact(address, value, i);
  450. }
  451. private void FirePot2_Write(string address, object value, int i = 1)
  452. {
  453. WriteControlExact(address, value, i);
  454. }
  455. private void Robot_Write(string address, object value, int i = 2)
  456. {
  457. WriteControlExact(address, value, i);
  458. }
  459. #region 炒锅
  460. /// <summary>
  461. /// 炒锅设定加热挡位
  462. /// </summary>
  463. /// <param name="o"></param>
  464. private void FirePot_SetFireGear(object[] o)
  465. {
  466. if (o == null) return;
  467. if (o.Length == 2 && o[0] is int fryNo && o[1] is int value)
  468. {
  469. if(fryNo == 1)
  470. {
  471. FirePot1_Write("VW100", (ushort)value);
  472. }
  473. else if(fryNo == 2)
  474. {
  475. FirePot2_Write("VW100", (ushort)value);
  476. }
  477. }
  478. Thread.Sleep(200);
  479. }
  480. /// <summary>
  481. /// 炒锅1加热启停
  482. /// </summary>
  483. /// <param name="b"></param>
  484. private void FirePot_StartFire(object[] o)
  485. {
  486. if (o == null) return;
  487. if (o.Length == 2 && o[0] is int fryNo && o[1] is bool value)
  488. {
  489. if (fryNo == 1)
  490. {
  491. FirePot1_Write("M10.0", value);
  492. }
  493. else if (fryNo == 2)
  494. {
  495. FirePot2_Write("M10.0", value);
  496. }
  497. }
  498. Thread.Sleep(200);
  499. }
  500. /// <summary>
  501. /// 炒锅1设置搅拌挡位
  502. /// </summary>
  503. /// <param name="o"></param>
  504. private void FirePot_SetStirGear(object[] o)
  505. {
  506. if (o == null) return;
  507. if (o.Length == 2 && o[0] is int fryNo && o[1] is int value)
  508. {
  509. if (fryNo == 1)
  510. {
  511. FirePot1_Write("VW102", (ushort)value);
  512. }
  513. else if (fryNo == 2)
  514. {
  515. FirePot2_Write("VW102", (ushort)value);
  516. }
  517. }
  518. Thread.Sleep(200);
  519. }
  520. /// <summary>
  521. /// 炒锅1搅拌启停
  522. /// </summary>
  523. /// <param name="o"></param>
  524. private void FirePot_StartStir(object[] o)
  525. {
  526. if (o == null) return;
  527. if (o.Length == 2 && o[0] is int fryNo && o[1] is bool value)
  528. {
  529. if (fryNo == 1)
  530. {
  531. FirePot1_Write("M10.1", value);
  532. }
  533. else if (fryNo == 2)
  534. {
  535. FirePot2_Write("M10.1", value);
  536. }
  537. }
  538. Thread.Sleep(200);
  539. }
  540. /// <summary>
  541. /// 设置炒锅1翻转速度
  542. /// </summary>
  543. /// <param name="o"></param>
  544. private void FirePot_SetTurnSpeed(object[] o)
  545. {
  546. if (o == null) return;
  547. if (o.Length == 2 && o[0] is int fryNo && o[1] is int value)
  548. {
  549. if (fryNo == 1)
  550. {
  551. FirePot1_Write("VW104", (ushort)value);
  552. }
  553. else if (fryNo == 2)
  554. {
  555. FirePot2_Write("VW104", (ushort)value);
  556. }
  557. }
  558. Thread.Sleep(200);
  559. }
  560. /// <summary>
  561. /// 设定炒锅角度
  562. /// </summary>
  563. /// <param name="o"></param>
  564. private void FirePot_SetPotAngle(object[] o)
  565. {
  566. if (o == null) return;
  567. if (o.Length == 2 && o[0] is int fryNo && o[1] is int value)
  568. {
  569. if (fryNo == 1)
  570. {
  571. FirePot1_Write("VW106", (ushort)value);
  572. }
  573. else if (fryNo == 2)
  574. {
  575. FirePot2_Write("VW106", (ushort)value);
  576. }
  577. }
  578. Thread.Sleep(200);
  579. }
  580. /// <summary>
  581. /// 通道出料启动
  582. /// </summary>
  583. /// <param name="o"></param>
  584. private void FirePot_StartPassWay(object[] o)
  585. {
  586. if (o == null) return;
  587. if (o.Length == 3 && o[0] is int fryNo && o[1] is int value1&& o[2] is int value2)
  588. {
  589. if (fryNo == 1)
  590. {
  591. FirePot1_Write(morkBF.Fire_PasswayValue[value1], (ushort)value2);//写入需求值
  592. Thread.Sleep(200);
  593. FirePot1_Write(morkBF.Fire_PasswayWrite[value1], true);//启动通道哦
  594. }
  595. else if (fryNo == 2)
  596. {
  597. FirePot2_Write(morkBF.Fire_PasswayValue[value1], (ushort)value2);
  598. Thread.Sleep(200);
  599. FirePot2_Write(morkBF.Fire_PasswayWrite[value1], true);
  600. }
  601. }
  602. Thread.Sleep(200);
  603. }
  604. /// <summary>
  605. /// 炒锅复位
  606. /// </summary>
  607. /// <param name="o"></param>
  608. private void FirePot_Reset(object o)
  609. {
  610. if (o == null) return;
  611. if (int.TryParse(o.ToString(), out int i))
  612. {
  613. if (i == 1)
  614. {
  615. }
  616. else if (i == 2)
  617. {
  618. }
  619. }
  620. }
  621. /// <summary>
  622. /// 炒锅回原点
  623. /// </summary>
  624. /// <param name="o"></param>
  625. private void FirePot_PotGotoOrigin(object o)
  626. {
  627. if (o == null) return;
  628. if (o is int i)
  629. {
  630. if (i == 1)
  631. {
  632. FirePot1_Write("M10.5", true);
  633. }
  634. else if (i == 2)
  635. {
  636. FirePot2_Write("M10.5", true);
  637. }
  638. }
  639. Thread.Sleep(200);
  640. }
  641. /// <summary>
  642. /// 炒锅去投料位置
  643. /// </summary>
  644. /// <param name="o"></param>
  645. private void FirePot_PotGotoInFoodPosition(object o)
  646. {
  647. if (o == null) return;
  648. if (o is int i)
  649. {
  650. if (i == 1)
  651. {
  652. FirePot1_Write("M11.2", true);
  653. }
  654. else if (i == 2)
  655. {
  656. FirePot2_Write("M11.2", true);
  657. }
  658. }
  659. Thread.Sleep(200);
  660. }
  661. /// <summary>
  662. /// 出餐启动
  663. /// </summary>
  664. /// <param name="o"></param>
  665. private void FirePot_StartOutFood(object o)
  666. {
  667. if (o == null) return;
  668. if (o is int i)
  669. {
  670. if (i == 1)
  671. {
  672. FirePot1_Write("M10.6", true);
  673. }
  674. else if (i == 2)
  675. {
  676. FirePot2_Write("M10.6", true);
  677. }
  678. }
  679. Thread.Sleep(200);
  680. }
  681. /// <summary>
  682. /// 清洗
  683. /// </summary>
  684. /// <param name="o"></param>
  685. private void FirePot_Clean(object o)
  686. {
  687. if (o == null) return;
  688. if (o is int i)
  689. {
  690. if (i == 1)
  691. {
  692. FirePot1_Write("M10.7", true);
  693. }
  694. else if (i == 2)
  695. {
  696. FirePot2_Write("M10.7", true);
  697. }
  698. }
  699. Thread.Sleep(200);
  700. }
  701. /// <summary>
  702. /// 抽水启动
  703. /// </summary>
  704. /// <param name="o"></param>
  705. private void FirePot_StartPumpWater(object[] o)
  706. {
  707. if (o == null) return;
  708. if (o.Length == 2 && o[0] is int fryNo && o[1] is int value)
  709. {
  710. if (fryNo == 1)
  711. {
  712. FirePot1_Write("M11.0", value);
  713. }
  714. else if (fryNo == 2)
  715. {
  716. FirePot2_Write("M11.0", value);
  717. }
  718. }
  719. Thread.Sleep(200);
  720. }
  721. /// <summary>
  722. /// 推杆伸出
  723. /// </summary>
  724. /// <param name="o"></param>
  725. private void FirePot_PushReach(object o)
  726. {
  727. if (o == null) return;
  728. if (o is int i)
  729. {
  730. if (i == 1)
  731. {
  732. FirePot1_Write("M12.3", true);
  733. }
  734. else if (i == 2)
  735. {
  736. FirePot2_Write("M12.3", true);
  737. }
  738. }
  739. Thread.Sleep(200);
  740. }
  741. /// <summary>
  742. /// 推杆缩回
  743. /// </summary>
  744. /// <param name="o"></param>
  745. private void FirePot_PushRetract(object o)
  746. {
  747. if (o == null) return;
  748. if (o is int i)
  749. {
  750. if (i == 1)
  751. {
  752. FirePot1_Write("M12.4", true);
  753. }
  754. else if (i == 2)
  755. {
  756. FirePot2_Write("M12.4", true);
  757. }
  758. }
  759. Thread.Sleep(200);
  760. }
  761. /// <summary>
  762. /// 翻转正转
  763. /// </summary>
  764. /// <param name="o"></param>
  765. private void FirePot_PotForward(object o)
  766. {
  767. if (o == null) return;
  768. if (o is int i)
  769. {
  770. if (i == 1)
  771. {
  772. FirePot1_Write("M12.5", true);
  773. }
  774. else if (i == 2)
  775. {
  776. FirePot2_Write("M12.5", true);
  777. }
  778. }
  779. Thread.Sleep(200);
  780. }
  781. /// <summary>
  782. /// 翻转正转
  783. /// </summary>
  784. /// <param name="o"></param>
  785. private void FirePot_PotReversal(object o)
  786. {
  787. if (o == null) return;
  788. if (o is int i)
  789. {
  790. if (i == 1)
  791. {
  792. FirePot1_Write("M12.6", true);
  793. }
  794. else if (i == 2)
  795. {
  796. FirePot2_Write("M12.6", true);
  797. }
  798. }
  799. Thread.Sleep(200);
  800. }
  801. #endregion
  802. #region 机器人
  803. private void RobotAction(object[] o)
  804. {
  805. if (o[0] is int value)
  806. {
  807. switch (value)
  808. {
  809. case 0:
  810. Robot_Write("GI0", (ushort)(MainTask)o[1]);
  811. break;
  812. case 1:
  813. Robot_Write("GI1", (ushort)(SubTask1)o[1]);
  814. break;
  815. case 2:
  816. Robot_Write("GI2", (ushort)(SubTask2)o[1]);
  817. break;
  818. case 3:
  819. Robot_Write("GI3", (ushort)(SubTask3)o[1]);
  820. break;
  821. case 4:
  822. Robot_Write("GI4", (ushort)(SubTask4)o[1]);
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. }
  829. #endregion
  830. #endregion
  831. private void ScreenDataServer()
  832. {
  833. LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒);
  834. ThreadManage.GetInstance().StartLong(new Action(() =>
  835. {
  836. List<StatsModel> statsModels = new List<StatsModel>();
  837. statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 });
  838. ScreenModelMaxWok maxWok = new ScreenModelMaxWok
  839. {
  840. IsRun = IsHealth ? IsRun.运行 : IsRun.停止,
  841. WorkStatus_1 = morkBF.FirePot1_Temperature > 0 ? WorkStatus.工作 : WorkStatus.待机,
  842. WorkStatus_2 = morkBF.FirePot2_Temperature > 0 ? WorkStatus.工作 : WorkStatus.待机,
  843. RobotStatu = WorkStatus.工作,
  844. Alarm = new List<AlarmModel>(),
  845. FailuresCount = 0,
  846. StatsCount = statsModels,
  847. MaxWok_Dishes_1 = "满汉全席",
  848. MaxWok_Dishes_2 = "海鲜大餐",
  849. MaxWok_Task_1 = ((PotState)dataReport.FirePot1_PotState).ToString(),
  850. MaxWok_Task_2 = ((PotState)dataReport.FirePot2_PotState).ToString(),
  851. MaxWok_Process_1 = SetFirePotPorcess(new Random().Next(0,11)),
  852. MaxWok_Process_2 = SetFirePotPorcess(new Random().Next(0, 11)),
  853. MaxWok_HeatGear_1 = morkBF.FirePot1_FireGear.ToString(),
  854. MaxWok_HeatGear_2 = morkBF.FirePot2_FireGear.ToString(),
  855. MaxWok_StirGear_1 = morkBF.FirePot1_StirGear.ToString(),
  856. MaxWok_StirGear_2 = morkBF.FirePot2_StirGear.ToString(),
  857. MaxWok_FlipSpeed_1 = morkBF.FirePot1_FlipSpeed.ToString(),
  858. MaxWok_FlipSpeed_2 = morkBF.FirePot2_FlipSpeed.ToString(),
  859. MaxWok_Temp_1 = new Random().Next(250, 450).ToString(),
  860. MaxWok_Temp_2 = new Random().Next(250, 450).ToString(),
  861. MaxWok_OrderCount_1 = 2,
  862. MaxWok_OrderCount_2 = 2,
  863. MaxWok_ErrorOrderCount_1 = 0,
  864. MaxWok_ErrorOrderCount_2 = 0,
  865. };
  866. LocalMqtt.GetInstance.Publish(maxWok);
  867. Thread.Sleep(1000);
  868. }), "大屏数据上报");
  869. }
  870. private List<ProcessModel> SetFirePotPorcess(int potState)
  871. {
  872. if (potState > 0)
  873. {
  874. if(potState <=3)
  875. {
  876. SetState(2);
  877. }
  878. else if(potState>3&&potState < 9) SetState(3);
  879. else if(potState == 9) SetState(4);
  880. else if (potState == 10) SetState(5);
  881. }
  882. else
  883. {
  884. foreach(var item in dataReport.processModels)
  885. {
  886. item.Status = ProcessStatus.未执行;
  887. }
  888. }
  889. return dataReport.processModels;
  890. }
  891. public void SetState(int c )
  892. {
  893. for (int i = 0; i < dataReport.processModels.Count; i++)
  894. {
  895. if (i == c)
  896. {
  897. dataReport.processModels[i].Status = ProcessStatus.正在执行;
  898. }
  899. else if( i<c) dataReport.processModels[i].Status = ProcessStatus.执行完成;
  900. else if (i > c ) dataReport.processModels[i].Status = ProcessStatus.未执行;
  901. }
  902. }
  903. }
  904. }