12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace athosRT.Devices.EFEM.Task
- {
- public class TaskT<T> : ITaskT, ICloneable where T : ITask, new()
- {
- private T _imp = default(T);
- private double _deley = Convert.ToDouble(SC.GetValue<int>("System.TimeLimitEfemComandDelay"));
- private DeviceTimer _timer = new DeviceTimer();
- private string _cmd;
- private string[] _args;
- private EfemCommandType _commandType;
- private EfemCommand _commandName;
- public bool HasInfoMessage
- {
- get => _imp.HasInfoMessage;
- set
- {
- }
- }
- public bool IsAcked => true;
- public bool IsWaitAck => false;
- public EfemCommandType CommandType => _commandType;
- public EfemCommand CommandName => _commandName;
- public string CommandData { get; set; }
- public TaskT(EfemCommandType type, EfemCommand cmd)
- {
- _commandType = type;
- _commandName = cmd;
- _imp = new T();
- _deley = 6000;//目前统一时间 后需要将每一个task都设计为各自的时间
- }
- public bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args) => true;
- public bool Execute(out string result, string cmd, params string[] args)
- {
- result = string.Empty;
- _cmd = cmd.Substring(4);
- if (!_imp.Execute(out result, args))
- {
- result = string.Format("CAN:{0}|{1}", (object)_cmd, (object)result);
- return false;
- }
- _args = new string[args.Length];
- args.CopyTo((Array)_args, 0);
- _timer.Start(_deley * 1000.0);
- result = string.Format("ACK:{0}", (object)_cmd);
- return true;
- }
- public bool? Monitor(out string result, params string[] args)
- {
- result = string.Empty;
- bool? nullable = _imp.Monitor(out result, _args);
- if (nullable.HasValue)
- {
- this._timer.Stop();
- if (nullable.Value)
- {
- result = !string.IsNullOrEmpty(result) ? string.Format("INF:{0}/{1}", (object)this._cmd, (object)result) : string.Format("INF:{0}", (object)this._cmd);
- return new bool?(true);
- }
- result = string.Format("ABS:{0}|ERROR/{1}/{2}", (object)this._cmd, (object)result, (object)"");
- return new bool?(true);
- }
- if (!this._timer.IsTimeout())
- return new bool?();
- this._timer.Stop();
- result = string.Format("ABS:{0}|ERROR/{1}/{2}", (object)this._cmd, (object)"TIMEOUT", (object)"TIMEOUT");
- return new bool?(false);
- }
- public object Clone() => MemberwiseClone();
- }
- }
|