终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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