123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- using Aitex.Core.RT.Device;
- using MECF.Framework.Common.Communications;
- using Newtonsoft.Json.Linq;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.SMIFs.Brooks
- {
- public abstract class BrooksSMIFHandler : HandlerBase
- {
- public BrooksSMIF Device { get; }
- public string _commandType;
- public string _command;
- public string _parameter;
- protected string _completeEvent;
- protected BrooksSMIFHandler(BrooksSMIF device, string commandType,string command, string completeEvent = null,string parameter = null)
- : base(BuildMessage(commandType, command, parameter))
- {
- Device = device;
- _commandType = commandType;
- _command = command;
- _completeEvent = completeEvent;
- _parameter = parameter;
- Name = command;
- }
- private static string BuildMessage(string commandType, string command, string parameter)
- {
- string commandStr = commandType;
- if(command != null)
- {
- commandStr += " " + command;
- }
- if (parameter != null)
- {
- commandStr += " " + parameter;
- }
- return commandStr + "\r\n";
- }
- protected static string F2S(float value)
- {
- return value < 0 ? value.ToString() : " " + value.ToString();
- }
- public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
- {
- BrooksSMIFMessage response = msg as BrooksSMIFMessage;
- ResponseMessage = msg;
- if (msg.IsError)
- {
- Device.NoteError(response.Data);
- }
- else
- {
- Device.NoteError(null);
- if(msg.IsAck)
- {
- this.SetState(EnumHandlerState.Acked);
- }
- if (_completeEvent == null)
- {
- if (this.IsAcked)
- {
- SetState(EnumHandlerState.Completed);
- transactionComplete = true;
- return true;
- }
- }
- else if (this.IsAcked && msg.IsEvent && _completeEvent == response.Data)
- {
- SetState(EnumHandlerState.Completed);
- transactionComplete = true;
- return true;
- }
- }
- transactionComplete = false;
- return false;
- }
- }
- public class BrooksSMIFRawCommandHandler : BrooksSMIFHandler
- {
- public BrooksSMIFRawCommandHandler(BrooksSMIF device, string commandType, string command, string completeEvent,string parameter = null)
- : base(device, commandType, command, completeEvent,parameter)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as BrooksSMIFMessage;
- Device.NoteRawCommandInfo(_commandType,_command, result.RawMessage, msg.IsAck);
- ResponseMessage = msg;
- handled = true;
- }
- return true;
- }
- }
- public class BrooksSMIFEnableActionHandler : BrooksSMIFHandler
- {
- public BrooksSMIFEnableActionHandler(BrooksSMIF device, string action, bool isEnable)
- : base(device, "HCS", isEnable? "ENABLE":"DISABLE",null, action)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as BrooksSMIFMessage;
- Device.NoteEnable(_parameter, _command == "ENABLE");
- }
- return true;
- }
- }
- public class BrooksSMIFFetchCassetteHandler : BrooksSMIFHandler
- {
- public BrooksSMIFFetchCassetteHandler(BrooksSMIF device)
- : base(device, "HCS", "FETCH", "CMPL_FETCH")
- {
- }
- }
- public class BrooksSMIFLoadCassetteHandler : BrooksSMIFHandler
- {
- public BrooksSMIFLoadCassetteHandler(BrooksSMIF device)
- : base(device, "HCS", "LOAD", null)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (!base.HandleMessage(msg, out handled))
- {
- BrooksSMIFMessage response = msg as BrooksSMIFMessage;
- if (response.Data.Contains("ABORT_LOAD"))
- {
- Device.NoteError("ABORT_LOAD");
- handled = true;
- }
- }
- return true;
- }
- }
- public class BrooksSMIFHomeHandler : BrooksSMIFHandler
- {
- public BrooksSMIFHomeHandler(BrooksSMIF device)
- : base(device, "HCS", "HOME", null)
- {
- }
- }
- public class BrooksSMIFRecoveryHandler : BrooksSMIFHandler
- {
- public BrooksSMIFRecoveryHandler(BrooksSMIF device)
- : base(device, "HCS", "RECOVERY", null)
- {
- }
- }
- public class BrooksSMIFStopHandler : BrooksSMIFHandler
- {
- public BrooksSMIFStopHandler(BrooksSMIF device)
- : base(device, "HCS", "STOP", null)
- {
- }
- }
- public class BrooksSMIFResetHandler : BrooksSMIFHandler
- {
- public BrooksSMIFResetHandler(BrooksSMIF device)
- : base(device, "HCS", "RESET", null)
- {
- }
- }
- public class BrooksSMIFOpenPodHandler : BrooksSMIFHandler
- {
- public BrooksSMIFOpenPodHandler(BrooksSMIF device)
- : base(device, "HCS", "OPEN", "CMPL_OPEN")
- {
- }
- }
- public class BrooksSMIFUnloadCassetteHandler : BrooksSMIFHandler
- {
- public BrooksSMIFUnloadCassetteHandler(BrooksSMIF device)
- : base(device, "HCS", "UNLOAD", null)
- {
- }
- //mabye need and the guide document miss this info ??
- //public override bool HandleMessage(MessageBase msg, out bool handled)
- //{
- // if (!base.HandleMessage(msg, out handled))
- // {
- // BrooksSMIFMessage response = msg as BrooksSMIFMessage;
- // if (response.Data.Contains("ABORT_UNLOAD"))
- // {
- // Device.NoteError("ABORT_UNLOAD");
- // handled = true;
- // }
- // }
- // return true;
- //}
- }
- public class BrooksSMIFClosePodHandler : BrooksSMIFHandler
- {
- public BrooksSMIFClosePodHandler(BrooksSMIF device)
- : base(device, "HCS", "CLOSE", "CMPL_UNLOAD")
- {
- }
- }
- public class BrooksSMIFRequestConstantHandler : BrooksSMIFHandler
- {
- public BrooksSMIFRequestConstantHandler(BrooksSMIF device, string constantId)
- : base(device, "ECR", null, null, constantId)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as BrooksSMIFMessage;
- if (result.MessagePart[0] == "ECD")
- {
- msg.IsAck = true;
- }
- else
- {
- handled = false;
- return false;
- }
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteConstant(result.MessagePart[1]);
- }
- return true;
- }
- }
- public class BrooksSMIFRequestStatusHandler : BrooksSMIFHandler
- {
- int _formCode;
- string AlarmId = "ALMID";//0000 = No alarm
- string Mode = "MODE";//AUTO,MANUAL
- string PodPresent = "PIP";//FALSE=no pod present,TRUE=pod present
- string PortStatus = "PRTST";//UNLK=port unlocked,LOCK=port locked,OTHER=none of the above
- string GripperStatus = "GRPST";//OPEN=gripper opened;CLOSE=gripper closed;OT=overtraveled;OTHER=none of the above
- string Ready = "READY";//FALSE=busy;TRUE=ready for new command
- string Home = "HOME";//FALSE=not home;TRUE=home
- string Elevator = "ELUP";//FALSE=elevator not at home limit;TRUE=elevator at home limit
- string ArmRetract = "ARM_RETR";//TRUE=arm retract;FALSE=arm not retract
- public BrooksSMIFRequestStatusHandler(BrooksSMIF device, int formCode)
- : base(device, "FSR", null, null, "FC="+formCode.ToString())
- {
- _formCode = formCode;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as BrooksSMIFMessage;
- if (result.MessagePart[0].Contains($"FSD{_formCode}"))
- {
- msg.IsAck = true;
- }
- else
- {
- handled = false;
- return false;
- }
- bool isPodPresent = false;
- bool isReady = false;
- bool isArmRetract = false;
- bool isHomed = false;
- for (int i = 0;i< result.MessagePart.Length;i++)
- {
- var statusArray = result.MessagePart[i].Split('=');
- if (statusArray.Length != 2)
- continue;
- if (statusArray[0] == AlarmId)
- {
- if (statusArray[1] != "0000")
- Device.SetError(statusArray[1]);
- }
- else if (statusArray[0] == Mode)
- {
- }
- else if (statusArray[0] == PodPresent)
- {
- if (statusArray[1].ToUpper() == "TRUE")
- isPodPresent = true;
- }
- else if (statusArray[0] == PortStatus)
- {
- }
- else if (statusArray[0] == GripperStatus)
- {
- }
- else if (statusArray[0] == Ready)
- {
- if (statusArray[1].ToUpper() == "TRUE")
- isReady = true;
- }
- else if (statusArray[0] == Home)
- {
- if (statusArray[1].ToUpper() == "TRUE")
- isHomed = true;
- }
- else if (statusArray[0] == Elevator)
- {
- }
- else if (statusArray[0] == ArmRetract)
- {
- if (statusArray[1].ToUpper() == "TRUE")
- isArmRetract = true;
- }
- }
- Device.SetStatus(isReady, isHomed, isPodPresent, isArmRetract);
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteStatus(result.MessagePart[0], result.Data);
- }
- return true;
- }
- }
- }
|