AsyncBehaviorRollerSend.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Pms.DataLibrary.Order;
  2. using Pms.Models;
  3. using ProjectManagementSystem.Common.Config;
  4. using ProjectManagementSystem.Common.Core;
  5. using ProjectManagementSystem.Common.Logger;
  6. using ProjectManagementSystem.Common.WebApi;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ProjectManagementSystem.TaskBookEvent
  13. {
  14. public class AsyncBehaviorRollerSend : AsyncBehavior
  15. {
  16. public override bool FirstOperator(TaskData taskData, StepData stepInfo)
  17. {
  18. string location = stepInfo.WareHouseID;
  19. int id = ExcelConfig.Instance.GetRouteConfig(location).RollerID;
  20. if (DeviceControl.Instance.Communication.InfoRollerDictionary.ContainsKey(id))
  21. {
  22. var data = DeviceControl.Instance.Communication.InfoRollerDictionary[id];
  23. if (data.DataValid)
  24. {
  25. DeviceControl.Instance.RollerOperateClear(id);
  26. Log(taskData, stepInfo, $"滚筒台清除操作已发送");
  27. if (data.OperationProgress == 0)
  28. {
  29. Log(taskData, stepInfo, $"滚筒台操作清除完成");
  30. return true;
  31. }
  32. }
  33. }
  34. else
  35. {
  36. Log(taskData, stepInfo, "获取滚筒台数据失败");
  37. }
  38. return false;
  39. }
  40. public override bool CustomOperator(TaskData taskData, StepData stepInfo)
  41. {
  42. var agvData = PmsApi.GetCarrier(taskData.Carrier);
  43. if (agvData == null)
  44. {
  45. Log(taskData, stepInfo, "获取AGV数据失败");
  46. return false;
  47. }
  48. //判断AGV滚筒是否已经转动
  49. var logicBits = agvData.LogicBits;
  50. bool rollerMoveing = (logicBits & (0x01 << 7)) > 0;
  51. if (!rollerMoveing)
  52. {
  53. Log(taskData, stepInfo, $"等待AGV滚筒转动,LogicBits:{logicBits}");
  54. return false;
  55. }
  56. string location = stepInfo.WareHouseID;
  57. int id = ExcelConfig.Instance.GetRouteConfig(location).RollerID;
  58. if (DeviceControl.Instance.Communication.InfoRollerDictionary.ContainsKey(id))
  59. {
  60. var data = DeviceControl.Instance.Communication.InfoRollerDictionary[id];
  61. if (data.DataValid
  62. && data.OperationProgress >= 100)
  63. {
  64. Log(taskData, stepInfo, $"滚筒台进度{data.OperationProgress}");
  65. return true;
  66. }
  67. else
  68. {
  69. ushort actionCode = 0x2222;
  70. if (id == 2 || id == 4)
  71. {
  72. actionCode = 0x8888;
  73. }
  74. Log(taskData, stepInfo, $"AGV滚筒已转动,LogicBits:{logicBits},滚筒台进度{data.OperationProgress},有效:{data.DataValid},发送操作0x{actionCode:X2}");
  75. DeviceControl.Instance.RollerOperate(id, actionCode);
  76. }
  77. }
  78. else
  79. {
  80. Log(taskData, stepInfo, "获取滚筒台数据失败");
  81. }
  82. return false;
  83. }
  84. }
  85. }