using MECF.Framework.Common.CommonData;
using MECF.Framework.Common.Communications;
using MECF.Framework.Common.Equipment;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HiWin
{
public abstract class HiwinRobotHandler : HandlerBase
{
public HiwinRobot Device { get; set; }
protected string _requestResponse = "";
protected string _command;
protected string _parameter;
protected string _target;
protected RobotArmEnum _blade;
public HiwinRobotHandler(HiwinRobot device, string command, string parameter = null) : base(BuildMessage(command, parameter))
{
Device = device;
_command = command;
_parameter = parameter;
Name = command;
}
public static string BuildMessage(string command, string parameter)
{
string msg = parameter == null ? $"{command}" : $"{command} {parameter}";
return msg + "\r\n";
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
HiwinRobotMessage response = msg as HiwinRobotMessage;
ResponseMessage = msg;
if (response.IsError)
{
Device.NoteError(response.Data);
}
if (response.IsComplete)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
return true;
}
if (response.IsResponse)
{
_requestResponse = response.Data;
}
//处理反馈信息
transactionComplete = false;
return false;
}
}
///
/// 通用命令
///
public class SunwayRobotRawCommandHandler : HiwinRobotHandler
{
public SunwayRobotRawCommandHandler(HiwinRobot 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 HiwinRobotMessage;
var rawMsg = _requestResponse != null ? _requestResponse + "$" + result.RawMessage : result.RawMessage;
//Device.NoteRawCommandInfo(_command, rawMsg);
}
return true;
}
}
public class HiwinRobotGetControllerStatusHandler : HiwinRobotHandler
{
//RESP,VAR.....
public HiwinRobotGetControllerStatusHandler(HiwinRobot device, ModuleName module,int timeout=300)
: base(device, "STAT")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 读取机械臂全部错误
///
public class HiwinRobotGetAllErrHandler : HiwinRobotHandler
{
//0000, 0000, 0001, 0001, 0001, 0000, 0000, 0000
//0000, 0002, 0000, 0000, 0000, 0000, 0000, 0000
public HiwinRobotGetAllErrHandler(HiwinRobot device, int timeout=300)
: base(device, "ERR", $"0")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 读取机械臂输入信息错误
///
public class HiwinRobotGeInputErrHandler : HiwinRobotHandler
{
//RESP,VAR.....
public HiwinRobotGeInputErrHandler(HiwinRobot device, ModuleName module,int timeout=300)
: base(device, "ERR", $"1")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 要求重置控制器
///
public class HiwinRobotResetControllerErrHandler : HiwinRobotHandler
{
//RESP,VAR.....
public HiwinRobotResetControllerErrHandler(HiwinRobot device, ModuleName module,int timeout=300)
: base(device, "RES")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 设置机械手轴运动速度
///
public class HiwinRobotSetAxisVelocityHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
public HiwinRobotSetAxisVelocityHandler(HiwinRobot device, ModuleName module, string axis, string velocity,int timeout=300)
: base(device, "SSP", $"{axis},{velocity}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 设置机械手轴运动速度
///
public class HiwinRobotSetSpeedHandler : HiwinRobotHandler
{
///
/// 设置机械手运动速度
///
///
///
///
///
public HiwinRobotSetSpeedHandler(HiwinRobot device, float speedPercent)
: base(device, "SSPP", $"A,{speedPercent},{speedPercent},{speedPercent}")
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 设置机械手轴运动加速
///
public class HiwinRobotSetAxisAccelerationHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
public HiwinRobotSetAxisAccelerationHandler(HiwinRobot device, ModuleName module, string axis, string acceleration,int timeout=300)
: base(device, "SAD", $"{axis},{acceleration}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 设置机械手轴运动加速
///
public class HiwinRobotSetAxisDecelerationHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
public HiwinRobotSetAxisDecelerationHandler(HiwinRobot device, ModuleName module, string axis, string deceleration,int timeout=300)
: base(device, "SDL", $"{axis},{deceleration}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 打开或关闭机械手电机
///
public class HiwinRobotOpeOrCloseMotorHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
public HiwinRobotOpeOrCloseMotorHandler(HiwinRobot device, ModuleName module, bool isOpen, string axis,int timeout=300)
: base(device, isOpen ? "SVON" : "SVOFF", axis)
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 移动机械手至绝对位置
///
public class HiwinRobotAxisMoveAbsoluteHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
public HiwinRobotAxisMoveAbsoluteHandler(HiwinRobot device, ModuleName module, string axis, int position,int timeout=300)
: base(device, "MOVA", $"{axis},{position}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 移动机械手至相对位置
///
public class HiwinRobotAxisMoveRelativeHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
public HiwinRobotAxisMoveRelativeHandler(HiwinRobot device, ModuleName module, string axis, int position,int timeout=300)
: base(device, "MOVR", $"{axis},{position}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 移动机械手轴移动X,Y位置
///
public class HiwinRobotAxisMoveXYHandler : HiwinRobotHandler
{
///
/// 设置机械手轴运动速度
///
///
///
///
///
///
public HiwinRobotAxisMoveXYHandler(HiwinRobot device, ModuleName module, string axis, int x, int y,int timeout=300)
: base(device, "MOVXY", $"{axis},{x},{y}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 停止机械手轴移动
///
public class HiwinRobotAxisStopMoveHandler : HiwinRobotHandler
{
///
/// 停止机械手轴移动
///
///
///
///
public HiwinRobotAxisStopMoveHandler(HiwinRobot device, ModuleName module)
: base(device, "ABM")
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 机械手特定轴归原点
///
public class HiwinRobotAxisHomeHandler : HiwinRobotHandler
{
///
/// 停止机械手轴移动
///
///
///
///
public HiwinRobotAxisHomeHandler(HiwinRobot device, ModuleName module, string axis,int timeout=300)
: base(device, "HOME", $"{axis}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 机械手全轴归原点
///
public class HiwinRobotHomeALLHandler : HiwinRobotHandler
{
///
/// 停止机械手轴移动
///
///
///
public HiwinRobotHomeALLHandler(HiwinRobot device, ModuleName module,int timeout=300)
: base(device, "HOM")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 设置机器晶舟站点坐标(第一组坐标)
///
public class HiwinRobotSetBoatStationHandler : HiwinRobotHandler
{
///
/// 机器晶舟站点坐标
///
///
///
/// A-Z,AA-AZ---GA-GZ
///
///
///
public HiwinRobotSetBoatStationHandler(HiwinRobot device, ModuleName module, string station, int coordinateT, int coordinateR, int coordinateZ, int coordinateH,int timeout=300)
: base(device, "SPC", $"{station},{coordinateT},{coordinateR}{coordinateZ},{coordinateH}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 设置机器晶舟站点坐标(第一组坐标)
///
public class HiwinRobotSetBoatStation2Handler : HiwinRobotHandler
{
///
/// 机器晶舟站点坐标
///
///
///
/// A-Z,AA-AZ---GA-GZ
///
public HiwinRobotSetBoatStation2Handler(HiwinRobot device, ModuleName module, string station, int coordinateT, int coordinateR,int timeout=300)
: base(device, "SPC2", $"{station},{coordinateT},{coordinateR}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 机器晶元扫描坐标,例如:SVON,SOOF,MOVA,MOVR
///
public class HiWinScanCoordinateHandler : HiwinRobotHandler
{
//
public HiWinScanCoordinateHandler(HiwinRobot device, ModuleName module, string station, int coordinateT, int coordinateR, int coordinateZ,int timeout=300)
: base(device, "SPSC", $"{station},{coordinateT},{coordinateR},{coordinateZ}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
public class HiwinRobotQueryWaferPresentHandler : HiwinRobotHandler
{
//INPUT A,1
//0 = 有片
//1 = 没片
public HiwinRobotQueryWaferPresentHandler(HiwinRobot device)
: base(device, "INPUT A,1")
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
if (result.Data == "0")
Device.IsWaferPresenceOnBlade1 = true;
if (result.Data == "1")
Device.IsWaferPresenceOnBlade1 = false;
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
public class HiwinRobotGetMapResultHandler : HiwinRobotHandler
{
//RSR
//0100001000100000000000000 2,7,11有片
//0122301000100000000000000 3,4斜放;5叠片
public HiwinRobotGetMapResultHandler(HiwinRobot device)
: base(device, "PSR")
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 机器晶元扫描动作,例如:MAP,a
///
public class HiWinWaferScanActionHandler : HiwinRobotHandler
{
//
public HiWinWaferScanActionHandler(HiwinRobot device, string station,int timeout=300)
: base(device, "MAP", $"{station}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.MapResult = result.Data;
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
///
/// 机器晶元扫描移动,例如:SVON,SOOF,MOVA,MOVR
///
public class HiWinScanMoveHandler : HiwinRobotHandler
{
//
public HiWinScanMoveHandler(HiwinRobot device, ModuleName module, string station,int timeout=300)
: base(device, "MAPST", $"{station}")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HiwinRobotMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
}
ResponseMessage = msg;
handled = true;
//Device.NoteActionCompleted();
return true;
}
}
}