123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- using System;
- using System.Collections.Generic;
- using Aitex.Core.Util;
- using Aitex.Sorter.RT.EFEMs.Tasks;
- namespace Aitex.Sorter.RT.EFEMs.Servers
- {
- public interface ITaskT
- {
- bool Execute(out string result, string cmd, params string[] args);
- /// <returns>
- /// null value, wait,
- /// true completed,
- /// false error
- /// </returns>
- bool? Monitor(out string result, params string[] args);
- bool HasInfoMessage { get; }
- bool IsAcked { get; }
- bool IsWaitAck { get; }
- bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args);
- EfemCommandType CommandType { get; }
- EfemCommand CommandName { get; }
- string CommandData { get; set; }
- }
- public interface ITask
- {
- bool Execute(out string result, params string[] args);
- /// <returns>
- /// novalue, wait, true completed, false error
- /// </returns>
- bool? Monitor(out string result, params string[] args);
- bool HasInfoMessage { get; set; }
- }
- public class TaskT<T> : ITaskT, ICloneable
- where T : ITask, new()
- {
- private T _imp = default(T);
- private double _deley = 60;
- private DeviceTimer _timer = new DeviceTimer();
- private string _cmd;
- private string[] _args;
- public bool HasInfoMessage { get { return _imp.HasInfoMessage; } set { }}
- public bool IsAcked { get { return true; } }
- public bool IsWaitAck
- {
- get { return false; }
- }
- public EfemCommandType CommandType
- {
- get { return _commandType; }
- }
- public EfemCommand CommandName
- {
- get { return _commandName; }
- }
- public string CommandData
- {
- get;
- set;
- }
- private EfemCommandType _commandType;
- private EfemCommand _commandName;
- public TaskT(EfemCommandType type, EfemCommand cmd)
- {
- _commandType = type;
- _commandName = cmd;
- _imp = new T();
- }
- public bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args)
- {
- return 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}", _cmd, result);
- return false;
- }
- _args = new string[args.Length];
- args.CopyTo(_args, 0);
- _timer.Start(_deley*1000);
- result = string.Format("ACK:{0}", _cmd);
- return true;
- }
- public bool? Monitor(out string result, params string[] args)
- {
- result = string.Empty;
- /*
- if (_timer.IsTimeout())
- {
- _timer.Stop();
- result = string.Format("INF:{0}", _cmd);
- return true;
- }
- return false;
- */
- bool? ret = _imp.Monitor(out result, _args);
- if (ret.HasValue)
- {
- _timer.Stop();
- if(ret.Value) //completed
- {
- if(string.IsNullOrEmpty(result))
- result = string.Format("INF:{0}", _cmd);
- else
- result = string.Format("INF:{0}/{1}", _cmd, result);
- return true;
- }
- else
- {
- result = string.Format("ABS:{0}|ERROR/{1}/{2}", _cmd,result, "FAILED");
- return true;
- }
- }
- if(_timer.IsTimeout())
- {
- _timer.Stop();
- result = string.Format("ABS:{0}|ERROR/{1}/{2}", _cmd, "SYSTEM_FF10", "TIMEOUT");
- return false;
- }
- return null;
- }
-
- public object Clone()
- {
- return this.MemberwiseClone();
- }
- }
- public class TaskFactory
- {
- private Dictionary<string, ITaskT> _tasks = new Dictionary<string, ITaskT>();
- private List<string> _hideTasks = new List<string>();
- public TaskFactory()
- {
- _tasks["MOV.INIT"] = new TaskT<InitTask>(EfemCommandType.MOV, EfemCommand.INIT);
- _tasks["MOV.ORGSH"] = new TaskT<OrgshTask>(EfemCommandType.MOV, EfemCommand.ORGSH);
- _tasks["MOV.HOME"] = new TaskT<HomeTask>(EfemCommandType.MOV, EfemCommand.HOME);
- _tasks["MOV.LOCK"] = new TaskT<LockTask>(EfemCommandType.MOV, EfemCommand.LOCK);
- _tasks["MOV.UNLOCK"] = new TaskT<UnlockTask>(EfemCommandType.MOV, EfemCommand.UNLOCK);
- _tasks["MOV.DOCK"] = new TaskT<DockTask>(EfemCommandType.MOV, EfemCommand.DOCK);
- _tasks["MOV.UNDOCK"] = new TaskT<UnDockTask>(EfemCommandType.MOV, EfemCommand.UNDOCK);
- //open cassette wafsh = open
- _tasks["MOV.OPEN"] = new TaskT<OpenTask>(EfemCommandType.MOV, EfemCommand.OPEN);
- _tasks["MOV.CLOSE"] = new TaskT<CloseDoorTask>(EfemCommandType.MOV, EfemCommand.CLOSE);
- _tasks["GET.CSTID"] = new TaskT<CstidTask>(EfemCommandType.GET, EfemCommand.CSTID);
- _tasks["MOV.WAFSH"] = new TaskT<WafshTask>(EfemCommandType.MOV, EfemCommand.WAFSH);
- _tasks["GET.MAPDT"] = new TaskT<MapdtTask>(EfemCommandType.GET, EfemCommand.MAPDT);
- _tasks["MOV.ALIGN"] = new TaskT<AlignTask>(EfemCommandType.MOV, EfemCommand.ALIGN);
- _tasks["SET.ALIGN"] = new TaskT<SetAlignTask>(EfemCommandType.SET, EfemCommand.ALIGN);
- _tasks["MOV.GOTO"] = new TaskT<GotoTask>(EfemCommandType.MOV, EfemCommand.GOTO);
- _tasks["MOV.LOAD"] = new TaskT<PickTask>(EfemCommandType.MOV, EfemCommand.LOAD);
- _tasks["MOV.UNLOAD"] = new TaskT<PlaceTask>(EfemCommandType.MOV, EfemCommand.UNLOAD);
- _tasks["MOV.TRANS"] = new TaskT<TransferTask>(EfemCommandType.MOV, EfemCommand.TRANS);
- _tasks["MOV.CHANGE"] = new TaskT<ExchangeTask>(EfemCommandType.MOV, EfemCommand.CHANGE);
- _tasks["MOV.EMS"] = new TaskT<EmsTask>(EfemCommandType.MOV, EfemCommand.EMS);
- _tasks["MOV.HOLD"] = new TaskT<HoldTask>(EfemCommandType.MOV, EfemCommand.HOLD);
- _tasks["MOV.RESTR"] = new TaskT<RestrTask>(EfemCommandType.MOV, EfemCommand.RESTR);
- _tasks["MOV.ABORT"] = new TaskT<AbortTask>(EfemCommandType.MOV, EfemCommand.ABORT);
- _tasks["SET.ERROR"] = new TaskT<ClearErrorTask>(EfemCommandType.SET, EfemCommand.ERROR);
- _tasks["GET.ERROR"] = new TaskT<QueryErrorTask>(EfemCommandType.GET, EfemCommand.ERROR);
- _tasks["SET.EVENT"] = new TaskT<SetEventTask>(EfemCommandType.SET, EfemCommand.EVENT);
- _tasks["GET.EVENT"] = new TaskT<QueryEventTask>(EfemCommandType.GET, EfemCommand.EVENT);
- _tasks["SET.SIGOUT"] = new TaskT<SigoutTask>(EfemCommandType.SET, EfemCommand.SIGOUT);
- _tasks["GET.SIGSTAT"] = new TaskT<SigStatTask>(EfemCommandType.GET, EfemCommand.SIGSTAT);
- _tasks["SET.CLAMP"] = new TaskT<SetClampTask>(EfemCommandType.SET, EfemCommand.CLAMP);
- _tasks["GET.CLAMP"] = new TaskT<GetClampTask>(EfemCommandType.GET, EfemCommand.CLAMP);
- _tasks["SET.MODE"] = new TaskT<SetModeTask>(EfemCommandType.SET, EfemCommand.MODE);
- _tasks["GET.MODE"] = new TaskT<QueryModeTask>(EfemCommandType.GET, EfemCommand.MODE);
- _tasks["MOV.TRANSREQ"] = new TaskT<SetTransferTask>(EfemCommandType.MOV, EfemCommand.TRANSREQ);
- _tasks["GET.TRANSREQ"] = new TaskT<QueryTransferTask>(EfemCommandType.GET, EfemCommand.TRANSREQ);
- _tasks["GET.STATE"] = new TaskT<QueryStateTask>(EfemCommandType.GET, EfemCommand.STATE);
- _tasks["SET.FFU"] = new TaskT<SetFfuTask>(EfemCommandType.SET, EfemCommand.FFU);
- _tasks["SET.WTYPE"] = new TaskT<SetWtypeTask>(EfemCommandType.SET, EfemCommand.WTYPE);
- _tasks["GET.WTYPE"] = new TaskT<QueryWtypeTask>(EfemCommandType.GET, EfemCommand.WTYPE);
- _tasks["SET.PURGE"] = new TaskT<SetPurgeTask>(EfemCommandType.SET, EfemCommand.PURGE);
- _tasks["GET.PURGE"] = new TaskT<QueryPurgeTask>(EfemCommandType.GET, EfemCommand.PURGE);
- _tasks["MOV.ADPLOCK"] = new TaskT<SetAdplockTask>(EfemCommandType.MOV, EfemCommand.ADPLOCK);
- _tasks["SET.ADPUNLOCK"] = new TaskT<SetAdpunlockTask>(EfemCommandType.SET, EfemCommand.ADPUNLOCK);
- _tasks["SET.LED"] = new TaskT<SetLedTask>(EfemCommandType.SET, EfemCommand.LED);
- _tasks["MOV.WORKCHK"] = new TaskT<SetWorkchkTask>(EfemCommandType.MOV, EfemCommand.WORKCHK);
- _tasks["SET.FFUFAN"] = new TaskT<SetFfuFanTask>(EfemCommandType.SET, EfemCommand.FFUFAN);
- }
- public bool UnSupport(EfemCommandType type, EfemCommand cmd)
- {
- string key = string.Format("{0}.{1}", type, cmd);
- return _hideTasks.Exists(item => item == key) || !_tasks.ContainsKey(key);
- }
- public ITaskT Create(EfemCommandType type, EfemCommand cmd)
- {
- if (!UnSupport(type,cmd))
- {
- string key = string.Format("{0}.{1}", type, cmd);
- return (ITaskT)(((ICloneable)_tasks[key]).Clone());
- }
- return null;
- }
-
- }
- }
|