123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- using MECF.Framework.Common.Communications;
- using Newtonsoft.Json.Linq;
- using System.Linq;
- using System.Text;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Siasun1500C800C
- {
- public abstract class RobotSiasun1500C800CHandler : HandlerBase
- {
- public RobotSiasun1500C800C Device { get; }
- protected string _command;
- protected string _parameter;
- protected string _requestResponse = "";
- protected RobotSiasun1500C800CHandler(RobotSiasun1500C800C device, string command, string parameter = null)
- : base(BuildMessage(command, parameter))
- {
- Device = device;
- _command = command;
- _parameter = parameter;
- Name = command;
- }
- private static string BuildMessage( string command, string parameter)
- {
- string msg = parameter == null ? $"{command}" : $"{command} {parameter}";
- return msg + "\r";
- }
- public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
- {
- RobotSiasun1500C800CMessage response = msg as RobotSiasun1500C800CMessage;
- ResponseMessage = msg;
- if (response.IsError)
- {
- Device.NoteError(response.Data);
- }
- else
- {
- Device.NoteError(null);
- }
- if (response.IsComplete)
- {
- SetState(EnumHandlerState.Completed);
- transactionComplete = true;
- return true;
- }
- if(response.IsResponse)
- {
- _requestResponse = response.Data;
- }
- transactionComplete = false;
- return false;
- }
- }
- public class RobotSiasun1500C800CRawCommandHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CRawCommandHandler(RobotSiasun1500C800C device, string command, string parameter = null)
- : base(device, command, parameter)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if(base.HandleMessage(msg, out handled))
- {
- var result = msg as RobotSiasun1500C800CMessage;
- var rawMsg = _requestResponse != null ? _requestResponse + "$" + result.RawMessage : result.RawMessage;
- Device.NoteRawCommandInfo(_command, rawMsg);
- }
- return true;
- }
- }
- public class RobotSiasun1500C800CGotoHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CGotoHandler(RobotSiasun1500C800C device, string jsonParameter)
- : base(device, "GOTO", BuildCommandParameter(jsonParameter))
- {
- }
- static string BuildCommandParameter(string jsonParameter)
- {
- JObject jsonObject = JObject.Parse(jsonParameter);
- StringBuilder paraBuilder = new StringBuilder();
- foreach (var item in jsonObject)
- {
- string key = item.Key;
- if (key == "station")
- key = "N";
- if (paraBuilder.Length == 0)
- {
- paraBuilder.Append(key.ToUpper() + " " + item.Value);
- }
- else
- {
- paraBuilder.Append(" " + key.ToUpper() + " " + item.Value);
- }
- }
- return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteIsHalted(true);
- if (_parameter.Contains("ARM B"))
- {
- string position = _parameter.Replace(" ARM B", "");
- Device.NoteArmBPosition(position);
- }
- else
- {
- string position = _parameter;
- if (_parameter.Contains("ARM A"))
- {
- position = _parameter.Replace(" ARM A", "");
- }
- Device.NoteArmAPosition(position);
- }
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CPickHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CPickHandler(RobotSiasun1500C800C device, string jsonParameter)
- : base(device, "PICK", BuildCommandParameter(jsonParameter))
- {
- }
- //N 2 R EX Z DOWN SLOT 1 ARM A
- static string BuildCommandParameter(string jsonParameter)
- {
- JObject jsonObject = JObject.Parse(jsonParameter);
- StringBuilder paraBuilder = new StringBuilder();
- foreach (var item in jsonObject)
- {
- if (paraBuilder.Length == 0)
- {
- paraBuilder.Append(item.Value);
- }
- else
- {
- if(item.Key == "Slot" || item.Key == "Arm")
- paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
- else
- paraBuilder.Append(" " + item.Value);
- }
- }
- return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteLastPickInfo(SendText);
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CPlaceHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CPlaceHandler(RobotSiasun1500C800C device, string jsonParameter)
- : base(device, "PLACE", BuildCommandParameter(jsonParameter))
- {
- }
- static string BuildCommandParameter(string jsonParameter)
- {
- JObject jsonObject = JObject.Parse(jsonParameter);
- StringBuilder paraBuilder = new StringBuilder();
- foreach (var item in jsonObject)
- {
- if (paraBuilder.Length == 0)
- {
- paraBuilder.Append(item.Value);
- }
- else
- {
- if (item.Key == "Slot" || item.Key == "Arm")
- paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
- else
- paraBuilder.Append(" " + item.Value);
- }
- }
- return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteLastPlaceInfo(SendText);
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CTransferHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CTransferHandler(RobotSiasun1500C800C device, string fromStation, string toStation, string arm = null)
- : base(device, "XFER", arm == null? $"{fromStation} {toStation}" : $"ARM {arm} {fromStation} {toStation}")
- {
- }
- }
- public class RobotSiasun1500C800CRetractHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CRetractHandler(RobotSiasun1500C800C device)
- : base(device, "RETRACT")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteRetracted(true);
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CHaltHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CHaltHandler(RobotSiasun1500C800C device)
- : base(device, "HALT")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteIsHalted(false);
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteIsHalted(true);
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CSetCommunicationEchoHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CSetCommunicationEchoHandler(RobotSiasun1500C800C device, string echoStaus)
- : base(device, "SET COMM ECHO", echoStaus)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteSetCommEchoCompleted(true);
- }
- return true;
- }
- }
- public class RobotSiasun1500C800CSetLoadHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CSetLoadHandler(RobotSiasun1500C800C device, string arm, string status)
- : base(device, "SET LOAD", arm + " " + status)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteSetLoadCompleted(true);
- }
- return true;
- }
- }
- public class RobotSiasun1500C800CSevoOnOffHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CSevoOnOffHandler(RobotSiasun1500C800C device, bool isOn)
- : base(device, isOn ? "SVON" : "SVOFF")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteSevoOnOff(_command == "SVON");
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CHomeAxisHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CHomeAxisHandler(RobotSiasun1500C800C device, string parameter)
- : base(device, "HOME", parameter)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- Device.NoteAxisHomed(_parameter);
- }
- ResponseMessage = msg;
- handled = true;
- return true;
- }
- }
- public class RobotSiasun1500C800CQueryWaferOnOffHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CQueryWaferOnOffHandler(RobotSiasun1500C800C device, string jsonParameter)
- : base(device, "RQ LOAD", jsonParameter != null ? jsonParameter : "A")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as RobotSiasun1500C800CMessage;
- if (_parameter != null && _parameter.Contains('B'))
- {
- Device.NoteWafeOnOff("B", _requestResponse.Contains("ON"));
- }
- else
- {
- Device.NoteWafeOnOff("A", _requestResponse.Contains("ON"));
- }
- }
- return true;
- }
- }
- public class RobotSiasun1500C800CRequestCommunicationEchoHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CRequestCommunicationEchoHandler(RobotSiasun1500C800C device)
- : base(device, "RQ COMM ECHO")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as RobotSiasun1500C800CMessage;
- Device.NoteCommEchoStatus(_requestResponse.Contains("ON"));
- }
- return true;
- }
- }
- public class RobotSiasun1500C800CRequestWaferCentDataHandler : RobotSiasun1500C800CHandler
- {
- public RobotSiasun1500C800CRequestWaferCentDataHandler(RobotSiasun1500C800C device)
- : base(device, "RQ WAF_CEN DATA")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as RobotSiasun1500C800CMessage;
- //WAF_CEN RT value1x value1y value4x value4y LFT value2x value2y value3x value3y offset_r offset_t
- Device.NoteWafeCenData(_requestResponse);
- }
- return true;
- }
- }
- }
|