123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- using MECF.Framework.Common.Communications;
- using Newtonsoft.Json.Linq;
- using System.Linq;
- using System.Text;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.VCE.SiasunVCE
- {
- public abstract class SiasunVCEHandler : HandlerBase
- {
- public SiasunVCE Device { get; set; }
- protected string _commandType;
- protected string _command;
- protected string _parameter;
- public bool IsSendText(string commandType, string command, string commandArgumen)
- {
- return _commandType == commandType && _command == command && _parameter == commandArgumen;
- }
- protected SiasunVCEHandler(SiasunVCE device, string commandType, string command, string parameter = null)
- : base(BuildMessage(device.Address, commandType, command, parameter))
- {
- Device = device;
- _commandType = commandType;
- _command = command;
- _parameter = parameter;
- Name = command;
- }
- private static string BuildMessage(string address, string commandType, string command, string parameter)
- {
- string strCommand = $"{address},{commandType}";
- if (!string.IsNullOrEmpty(command))
- {
- strCommand += "," + command;
- }
- if (!string.IsNullOrEmpty(parameter))
- {
- strCommand += "," + parameter;
- }
- return strCommand + "\r";
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- var result = msg as SiasunVCEMessage;
- handled = msg.IsComplete;
- if (result.IsError)
- {
- Device.NoteError(result.Data);
- }
- else
- {
- Device.NoteError(null);
- }
- if (result.IsComplete)
- {
- SetState(EnumHandlerState.Completed);
- }
- if (result.IsAck)
- {
- SetState(EnumHandlerState.Acked);
- }
- if (result.IsRDY)
- {
- if (IsAcked)
- {
- SetState(EnumHandlerState.Completed);
- handled = true;
- }
- else
- {
- SetState(EnumHandlerState.Acked);
- }
- }
- ResponseMessage = msg;
- return handled;
- }
- }
- public class SiasunVCERawCommandHandler : SiasunVCEHandler
- {
- public SiasunVCERawCommandHandler(SiasunVCE device, string commandType, string command, string parameter = null)
- : base(device, commandType, command, parameter)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- base.HandleMessage(msg, out handled);
- var result = msg as SiasunVCEMessage;
- Device.NoteRawCommandInfo(_commandType, _command, result.RawMessage);
- return true;
- }
- }
- public class SiasunVCEAbortHandler : SiasunVCEHandler
- {
- public SiasunVCEAbortHandler(SiasunVCE device)
- : base(device, "E", "")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteIsHalted(true);
- }
- return true;
- }
- }
- public class SiasunVCECommonActionHandler : SiasunVCEHandler
- {
- public SiasunVCECommonActionHandler(SiasunVCE device, string command)
- : base(device, "A", command)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteCommonActionResult(_command);
- }
- return true;
- }
- }
- public class SiasunVCEMoveHandler : SiasunVCEHandler
- {
- public SiasunVCEMoveHandler(SiasunVCE device, string axis, string type, string value)
- : base(device, "A", "MOVE", axis + "," + type + "," + value)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteMoveResult(_parameter);
- }
- return true;
- }
- }
- public class SiasunVCECloseDoorHandler : SiasunVCEHandler
- {
- public SiasunVCECloseDoorHandler(SiasunVCE device)
- : base(device, "A", "DC")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteDoorClosed(true);
- }
- return true;
- }
- }
- public class SiasunVCEOpenDoorHandler : SiasunVCEHandler
- {
- public SiasunVCEOpenDoorHandler(SiasunVCE device)
- : base(device, "A", "DO")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteDoorClosed(false);
- }
- return true;
- }
- }
- public class SiasunVCEHomeHandler : SiasunVCEHandler
- {
- public SiasunVCEHomeHandler(SiasunVCE device)
- : base(device, "A", "HM", "")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteHomed(true);
- }
- return true;
- }
- }
- public class SiasunVCEGotoZHandler : SiasunVCEHandler
- {
- public SiasunVCEGotoZHandler(SiasunVCE device, int slot)
- : base(device, "A", "GOTO", slot.ToString())
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- Device.NoteZAxisPosition(_parameter.Split(',')[2]);
- }
- return true;
- }
- }
- public class SiasunVCESetCommunicationModeHandler : SiasunVCEHandler
- {
- public SiasunVCESetCommunicationModeHandler(SiasunVCE device, string commMode)
- : base(device, "S", "COMM", "FLOW," + commMode)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- if (result.IsComplete)
- {
- Device.NoteCommunicationMode(this._parameter.Split(',')[2]);
- }
- }
- return true;
- }
- }
- public class BrooksACERequestArmRPositonHandler : SiasunVCEHandler
- {
- public BrooksACERequestArmRPositonHandler(SiasunVCE device, string axisPosition)
- : base(device, "R", "ARM", "R," + axisPosition)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteArmRPositon(result.Data.Split(',')[2]);
- }
- return true;
- }
- }
- public class BrooksACERequestArmZPositonHandler : SiasunVCEHandler
- {
- public BrooksACERequestArmZPositonHandler(SiasunVCE device, string axisPosition)
- : base(device, "R", "ARM", "Z," + axisPosition)
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteArmZPositon(result.Data.Split(',')[2]);
- }
- return true;
- }
- }
- public class BrooksACERequestCommModeHandler : SiasunVCEHandler
- {
- public BrooksACERequestCommModeHandler(SiasunVCE device)
- : base(device, "R", "COMM", "FLOW")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteCurrentCommunicationMode(result.Data);
- }
- return true;
- }
- }
- public class BrooksACERequestErrorStatusHandler : SiasunVCEHandler
- {
- public BrooksACERequestErrorStatusHandler(SiasunVCE device)
- : base(device, "R", "ER")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteCurrentErrorStatus(result.Data);
- }
- return true;
- }
- }
- public class BrooksACERequestVCEStatusHandler : SiasunVCEHandler
- {
- public BrooksACERequestVCEStatusHandler(SiasunVCE device)
- : base(device, "R", "STAT", "ALL")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteCurrentACEStatus(result.Data);
- }
- return true;
- }
- }
- public class BrooksACERequestLoadPositionHandler : SiasunVCEHandler
- {
- public BrooksACERequestLoadPositionHandler(SiasunVCE device)
- : base(device, "R", "LP")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteIsLoadPositon(result.Data);
- }
- return true;
- }
- }
- public class BrooksACERequestMappingInfoHandler : SiasunVCEHandler
- {
- public BrooksACERequestMappingInfoHandler(SiasunVCE device)
- : base(device, "R", "MI")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteCurrentMappingInfo(result.Data);
- }
- return true;
- }
- }
- public class BrooksACERequestPlatformPositionHandler : SiasunVCEHandler
- {
- public BrooksACERequestPlatformPositionHandler(SiasunVCE device)
- : base(device, "R", "LP")
- {
- }
- public override bool HandleMessage(MessageBase msg, out bool handled)
- {
- if (base.HandleMessage(msg, out handled))
- {
- var result = msg as SiasunVCEMessage;
- Device.NoteIsPlatformPosition(result.Data);
- }
- return true;
- }
- }
- }
|