终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

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