TaskT.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Aitex.Core.RT.SCCore;
  2. using Aitex.Core.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace athosRT.Devices.EFEM.Task
  10. {
  11. public class TaskT<T> : ITaskT, ICloneable where T : ITask, new()
  12. {
  13. private T _imp = default(T);
  14. private double _deley = Convert.ToDouble(SC.GetValue<int>("System.TimeLimitEfemComandDelay"));
  15. private DeviceTimer _timer = new DeviceTimer();
  16. private string _cmd;
  17. private string[] _args;
  18. private EfemCommandType _commandType;
  19. private EfemCommand _commandName;
  20. public bool HasInfoMessage
  21. {
  22. get => _imp.HasInfoMessage;
  23. set
  24. {
  25. }
  26. }
  27. public bool IsAcked => true;
  28. public bool IsWaitAck => false;
  29. public EfemCommandType CommandType => _commandType;
  30. public EfemCommand CommandName => _commandName;
  31. public string CommandData { get; set; }
  32. public TaskT(EfemCommandType type, EfemCommand cmd)
  33. {
  34. _commandType = type;
  35. _commandName = cmd;
  36. _imp = new T();
  37. _deley = 6000;//目前统一时间 后需要将每一个task都设计为各自的时间
  38. }
  39. public bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args) => true;
  40. public bool Execute(out string result, string cmd, params string[] args)
  41. {
  42. result = string.Empty;
  43. _cmd = cmd.Substring(4);
  44. if (!_imp.Execute(out result, args))
  45. {
  46. result = string.Format("CAN:{0}|{1}", (object)_cmd, (object)result);
  47. return false;
  48. }
  49. _args = new string[args.Length];
  50. args.CopyTo((Array)_args, 0);
  51. _timer.Start(_deley * 1000.0);
  52. result = string.Format("ACK:{0}", (object)_cmd);
  53. return true;
  54. }
  55. public bool? Monitor(out string result, params string[] args)
  56. {
  57. result = string.Empty;
  58. bool? nullable = _imp.Monitor(out result, _args);
  59. if (nullable.HasValue)
  60. {
  61. this._timer.Stop();
  62. if (nullable.Value)
  63. {
  64. result = !string.IsNullOrEmpty(result) ? string.Format("INF:{0}/{1}", (object)this._cmd, (object)result) : string.Format("INF:{0}", (object)this._cmd);
  65. return new bool?(true);
  66. }
  67. result = string.Format("ABS:{0}|ERROR/{1}/{2}", (object)this._cmd, (object)result, (object)"");
  68. return new bool?(true);
  69. }
  70. if (!this._timer.IsTimeout())
  71. return new bool?();
  72. this._timer.Stop();
  73. result = string.Format("ABS:{0}|ERROR/{1}/{2}", (object)this._cmd, (object)"TIMEOUT", (object)"TIMEOUT");
  74. return new bool?(false);
  75. }
  76. public object Clone() => MemberwiseClone();
  77. }
  78. }