终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

174 satır
7.5 KiB

  1. using BPA.Message.Enum;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.MorkCL.Model.Json;
  4. using BPASmartClient.MorkCL.Server;
  5. using SqlSugar;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace BPASmartClient.MorkCL
  12. {
  13. public class Control_MorkCL : BaseDevice
  14. {
  15. public override DeviceClientType DeviceType => DeviceClientType.MORKCL;
  16. GVL_MorkCL morkCL = new GVL_MorkCL();
  17. Alarm alarm = new Alarm();
  18. /// <summary>
  19. /// 设备信息集合
  20. /// </summary>
  21. ConcurrentDictionary<EDeviceType, IModbus> devices { get; set; } = new();
  22. /// <summary>
  23. /// 任务集合
  24. /// </summary>
  25. ConcurrentDictionary<EDeviceType, TaskServer> TaskList { get; set; } = new();
  26. public override void DoMain()
  27. {
  28. MonitorViewModel.DeviceId = DeviceId;
  29. #region 读取本地文件数据
  30. Json<RecipesInfo>.Read();
  31. Json<ItemStorageInfo>.Read();
  32. #endregion
  33. //注册本地配方接收
  34. ActionManage.GetInstance.Register(new Action<object>(o =>
  35. {
  36. if (o != null && o is ControlData cd) morkCL.cds.Enqueue(cd);
  37. }), NotifyTopic.FormulaDistribution);
  38. //初始化通讯对象
  39. devices.TryAdd(EDeviceType.炒锅1, new FryingPanServer());
  40. devices.TryAdd(EDeviceType.炒锅2, new FryingPanServer());
  41. devices.TryAdd(EDeviceType.机器人, new RobotServer());
  42. devices.TryAdd(EDeviceType.压力锅, new PressureCookerServer());
  43. devices.TryAdd(EDeviceType.外部设备, new OtherServer());
  44. devices[EDeviceType.炒锅1].Init(ConnectPar.FryingPanIP1);
  45. devices[EDeviceType.炒锅2].Init(ConnectPar.FryingPanIP2);
  46. devices[EDeviceType.机器人].Init(ConnectPar.RobotIP);
  47. devices[EDeviceType.压力锅].Init(ConnectPar.PressureCookerIP);
  48. devices[EDeviceType.外部设备].Init(ConnectPar.PPortName);
  49. }
  50. public override void MainTask()
  51. {
  52. if (morkCL.cds.Count > 0 && !TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType))
  53. {
  54. if (morkCL.cds.TryDequeue(out ControlData cd))
  55. {
  56. TaskList.TryAdd(cd.DeviceType, new TaskServer());
  57. TaskList[cd.DeviceType].TaskName = $"{cd.DeviceType.ToString()}-{cd.Name}";
  58. TaskList[cd.DeviceType].RunTask = new Task(new Action(() => { FryingPanControl(cd.DeviceType, cd); }));
  59. TaskList[cd.DeviceType].RunTask.Start();
  60. }
  61. }
  62. //检查到有任务完成后将对已完成的任务进行清理
  63. var res = TaskList.FirstOrDefault(p => p.Value.IsComplete).Key;
  64. if (TaskList.ContainsKey(res)) TaskList.TryRemove(res, out _);
  65. }
  66. private void FryingPanControl(EDeviceType et, ControlData cd)
  67. {
  68. DeviceProcessLogShow($"开始执行-{cd.Name} 任务");
  69. if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested) return;
  70. while (cd.ControlFuncs.Count > 0)
  71. {
  72. if (cd.ControlFuncs.TryDequeue(out FuncModel fm))
  73. {
  74. var device = (FryingPanServer)devices[et];
  75. var robot = (RobotServer)devices[EDeviceType.机器人];
  76. int index = (ushort)et - 1;
  77. DeviceProcessLogShow($"{cd.Name}-任务执行-{fm.eFunc.ToString()}-步骤");
  78. switch (fm.eFunc)
  79. {
  80. case EFunc.搅拌启动:
  81. device.MixingFrequencySet(fm.funcPars.ElementAt(0).ParValue.ToString());
  82. device.StirStartOrStop = true;
  83. break;
  84. case EFunc.搅拌停止:
  85. device.StirStartOrStop = false;
  86. break;
  87. case EFunc.加热启动:
  88. device.HeatingGearSet(fm.funcPars.ElementAt(0).ParValue.ToString());
  89. device.HeatStartOrStop = true;
  90. break;
  91. case EFunc.加热停止:
  92. device.HeatStartOrStop = false;
  93. break;
  94. case EFunc.添加调料:
  95. var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id);
  96. if (Seasoning != null)
  97. {
  98. device.CuttingControl(Seasoning.Loc.ToString(), fm.funcPars.ElementAt(1).ParValue.ToString());
  99. }
  100. break;
  101. case EFunc.添加主料:
  102. case EFunc.添加辅料:
  103. MaterialBase mb = new MaterialBase();
  104. if (fm.eFunc == EFunc.添加辅料)
  105. mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id);
  106. else mb = SqliteHelper.GetInstance.GetIngredients().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id);
  107. robot.RobotTaskControl(mb.Loc.ToString(), et);
  108. device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置
  109. robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置
  110. robot.AllowPourVegetables(et);//允许机器人开始投料
  111. robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成
  112. break;
  113. case EFunc.炒锅回原点位:
  114. device.FryingPanHome = true;
  115. break;
  116. case EFunc.出餐启动:
  117. robot.RobotTaskControl("1", et);//取空盆
  118. robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置
  119. device.DiningOutStart = true;
  120. break;
  121. case EFunc.炒锅清洗:
  122. device.FryingPanClear = true;
  123. break;
  124. case EFunc.炒锅回投料位置:
  125. device.FryingPanFeedingLoc = true;
  126. break;
  127. case EFunc.去指定炒制位:
  128. device.SetStirFryingLoc(fm.funcPars.ElementAt(0).ParValue.ToString());
  129. break;
  130. case EFunc.炒制:
  131. if (int.TryParse(fm.funcPars.ElementAt(0).ParValue.ToString(), out int time))
  132. Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token);
  133. break;
  134. default:
  135. break;
  136. }
  137. }
  138. }
  139. }
  140. public override void ReadData()
  141. {
  142. }
  143. public override void ResetProgram()
  144. {
  145. morkCL = null;
  146. morkCL = new GVL_MorkCL();
  147. }
  148. public override void SimOrder()
  149. {
  150. }
  151. public override void Stop()
  152. {
  153. }
  154. }
  155. }