终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

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