refactor: 将Framework库和RT、UI放在同一个解决方案中。

This commit is contained in:
SL
2026-06-01 17:48:28 +08:00
parent 1948f4290d
commit b73d39a6b1
4331 changed files with 506148 additions and 49363 deletions
@@ -0,0 +1,115 @@
using Aitex.Core.RT.Device;
using Aitex.Sorter.Common;
using MECF.Framework.Common.SubstrateTrackings;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners
{
public class AlignerBase : BaseDevice, IDevice
{
public bool IsBusy
{
get { return true; }
}
public bool IsError { get; set; }
public AlignerBase(string module, string name, string display, string deviceId)
: base(module, name, display, deviceId)
{
}
public virtual bool Initialize()
{
WaferManager.Instance.SubscribeLocation(Module, 1);
return true;
}
public virtual void Terminate()
{
}
public virtual void Reset()
{
IsError = false;
}
public virtual bool Home(out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool Clear(out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool Grip(Hand hand, out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool Release(Hand hand, out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool LiftUp(out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool LiftDown(out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool Stop(out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool Align(double angle, out string reason)
{
reason = string.Empty;
return true;
}
public virtual bool QueryState(out string reason)
{
reason = string.Empty;
return true;
}
public virtual void OnError()
{
IsError = true;
}
public virtual bool QueryWaferPresence(out string reason)
{
reason = string.Empty;
return true;
}
public virtual void OnAligned()
{
}
}
}
@@ -0,0 +1,27 @@
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.AlignersBase
{
public enum AlignerStateEnum
{
Undefined = 0,
Init,
Initializing,
Idle,
Gripping,
UnGripping,
Aligning,
Error,
SettingServos,
ReadingData,
Resetting,
Stopped,
LiftingUp,
LiftingDown,
Maintenance,
Homing,
PrepareAccept,
};
}
@@ -0,0 +1,35 @@
using System.Linq;
using System.Text;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner.Handlers
{
public abstract class HwAlignerGuideHandler : HandlerBase
{
public HwAlignerGuide Device { get; }
protected HwAlignerGuideHandler(HwAlignerGuide device, string command)
: base(BuildMessage(command))
{
Device = device;
}
private static byte[] BuildMessage(string command)
{
var liCmd = Encoding.ASCII.GetBytes(command).ToList<byte>();
liCmd.Add(0x0d); //CR
liCmd.Add(0x0a); //LF 不可颠倒
return liCmd.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HwAlignerGuideMessage;
ResponseMessage = msg;
handled = true;
return true;
}
}
}
@@ -0,0 +1,32 @@
using System;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner.Handlers
{
public class HwAlignerGuideSetHandler : HwAlignerGuideHandler
{
public HwAlignerGuideSetHandler(HwAlignerGuide device, string name, string command, int timeout = 30)
: base(device, command)
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
Name = name;
device.SetCurrentOper();
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
handled = false;
var result = msg as HwAlignerGuideMessage;
if (result is { IsResponse: false })
{
handled = true;
return false;
}
handled = Device.ParseData(Name, result.Data, out var returnIfo);
return returnIfo;
}
}
}
@@ -0,0 +1,31 @@
using System;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner.Handlers
{
public class HwAlignerWaferCheckHandler : HwAlignerGuideHandler
{
public HwAlignerWaferCheckHandler(HwAlignerGuide device, int timeout = 100)
: base(device, "DOC")
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
Name = device.Name;
device.HaveWafer = false;
device.SetCurrentOper();
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HwAlignerGuideMessage;
if (result is { IsResponse: false })
{
handled = true;
return false;
}
handled = Device.CheckWaferDataA(Name, result.Data, out var returnIfo);
return returnIfo;
}
}
}
@@ -0,0 +1,670 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.OperationCenter;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.Communications;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner.Handlers;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner
{
public class HwAlignerGuide : BaseDevice, IConnection, IDevice
{
#region Variables
private enum CommandEnum
{
NULL,
SME11,
SME21,
SME31,
HOM,
DOC,
CVN,
MTM,
CCD,
BAL,
MVR,
CVF,
ERS,
STA,
//
SPS,
WSZ,
_WT,
GLM,
FWO,
};
private HwAlignerGuideConnection _connection;
private readonly bool _activeMonitorStatus;
private readonly R_TRIG _trigCommunicationError = new();
private readonly R_TRIG _trigRetryConnect = new();
private bool _bIsDisconnect = false;
private string _lastHandlerName;
private CommandEnum _iCurrentOper = CommandEnum.NULL;
private readonly LinkedList<HandlerBase> _lstHandler = new();
private readonly object _locker = new();
#endregion
#region Constructors
/// <summary>
/// 构造上银巡边器对象实例。
/// </summary>
/// <param name="module">所属模组名称。</param>
/// <param name="scRoot">系统配置定义了当前巡边器相关配置的节点。</param>
/// <param name="name">当前巡边器名称。</param>
public HwAlignerGuide(string module, string scRoot, string name) : base(module, name, name, name)
{
ScBasePath = scRoot;
_activeMonitorStatus = true;
}
#endregion
#region Properties
public bool HaveWafer { get; set; }
public string Address { get; set; }
public string Vacuum { get; set; } ="-Kpa" ;
public string PError { get; set; } = "-";
public string Response { get; set; } = "-";
public bool IsConnected => _connection is { IsConnected: true };
public bool AlarmStatus { get; set; }
public bool PositionComplete { get; set; }
public bool MotorBusy { get; set; }
public bool IsBusy
{
get
{
lock (_locker)
{
return _lstHandler.Count > 0 || _iCurrentOper != CommandEnum.NULL;
}
}
}
#endregion
#region Private Methods
private void InitData()
{
DATA.Subscribe($"{Module}.{Name}.HaveWafer", () => HaveWafer);
DATA.Subscribe($"{Module}.{Name}.Response", () => Response, SubscriptionAttribute.FLAG.IgnoreSaveDB);
DATA.Subscribe($"{Module}.{Name}.Vacuum", () => Vacuum, SubscriptionAttribute.FLAG.IgnoreSaveDB);
DATA.Subscribe($"{Module}.{Name}.PError", () => PError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
}
private void InitOp()
{
//参数保存
OP.Subscribe($"{Module}.{Name}.HwSaveParameters", (_, _) =>
{
Set("SPS");
return true;
});
//读取/设定晶圆尺寸
OP.Subscribe($"{Module}.{Name}.HwWaferSize", (_, param) =>
{
Set("WSZ" + " " + param[0]);
return true;
});
//晶圆种类
OP.Subscribe($"{Module}.{Name}.HwWaferType", (_, param) =>
{
Set("_WT" + " " + param[0]);
return true;
});
//寻边材质
OP.Subscribe($"{Module}.{Name}.HwWaferMaterial", (cmd, param) =>
{
Set("GLM" + " " + param[0]);
return true;
});
//晶圆方向
OP.Subscribe($"{Module}.{Name}.HwWaferOrientation", (cmd, param) =>
{
Set("FWO" + " " + param[0]);
return true;
});
//------------------------------------------------------------
//原点复归
OP.Subscribe($"{Module}.{Name}.HwHOM", (_, _) => MsgHome());
//晶圆确认
OP.Subscribe($"{Module}.{Name}.HwDOC", (_, _) => CheckWaferLoad());
//开启真空
OP.Subscribe($"{Module}.{Name}.HwCVN", (_, _) => OpenVacuum());
//寻边补正
OP.Subscribe($"{Module}.{Name}.HwBAL", (_, _) => MsgAliger());
//关闭真空
OP.Subscribe($"{Module}.{Name}.HwCVD", (_, _) => ReadVacuum());
//关闭真空
OP.Subscribe($"{Module}.{Name}.HwCVF", (_, _) => CloseVacuum());
//移至测量中心点
OP.Subscribe($"{Module}.{Name}.HwMTM", (_, _) => MoveToRobotPutPlace());
//清除报警
OP.Subscribe($"{Module}.{Name}.HwERS", (_, _) => ClearError());
//读取报警
OP.Subscribe($"{Module}.{Name}.HwPER", (_, _) => ReadError());
//马达激磁
OP.Subscribe($"{Module}.{Name}.HwSME", (_, _) =>
{
InitMachine();
return true;
});
//相对位移
OP.Subscribe($"{Module}.{Name}.HwMVR", (cmd, param) =>
{
Set("MVR");
return true;
});
//
OP.Subscribe($"{Module}.{Name}.HwAbort", (cmd, param) =>
{
Abort();
return true;
});
}
private bool OnTimer()
{
try
{
_connection.MonitorTimeout();
//若断,重连
if ((!_connection.IsConnected) || _connection.IsCommunicationError || _bIsDisconnect)
{
_trigRetryConnect.CLK = _bIsDisconnect;
//重连机制要改,timeout之后,要是用心跳方式探测重连
_trigRetryConnect.CLK = _bIsDisconnect;
if (_connection.Connect())
{
_bIsDisconnect = false;
//
if (_trigRetryConnect.Q)
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
LOG.Write($"{Module}.{Name} connected");
}
}
else
{
if (_trigRetryConnect.Q)
{
EV.PostInfoLog(Module,
$"Trying to connect {Module}.{Name} with address: {_connection.Address}");
LOG.Write($"Trying to connect {Module}.{Name} with address: {_connection.Address}");
}
}
}
//处理命令队列
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0 && _activeMonitorStatus && !IsBusy)
{
_lastHandlerName = "";
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
_lstHandler.RemoveFirst();
}
}
if (handler != null)
{
_lastHandlerName = handler.Name;
_connection.Execute(handler);
}
}
//
return true;
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
internal void NoteError()
{
}
protected override void HandleMonitor()
{
try
{
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
EV.PostAlarmLog(Module,
$"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
}
#endregion
#region Methods
public bool Connect()
{
return true;
}
public bool Disconnect()
{
return true;
}
public bool Initialize()
{
// string portName = SC.GetStringValue($"{_scRoot}.{Module}.{Name}.Address");
var portName = SC.GetStringValue($"{ScBasePath}.Address");
Address = portName;
var scEnableLog = $"{ScBasePath}.EnableLogMessage";
var enableLog = SC.GetValue<bool>(scEnableLog);
SC.RegisterValueChangedCallback(scEnableLog, scValue =>
{
if (scValue is bool bEnableLog)
_connection.EnableLog(bEnableLog);
});
_connection = new HwAlignerGuideConnection(portName);
_connection.EnableLog(enableLog);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} Connected");
}
var periodicJob = new PeriodicJob(200, OnTimer, $"{Name} MonitorHandler", true);
InitData();
InitOp();
ConnectionManager.Instance.Subscribe($"{Name}", this);
return true;
}
public void Abort()
{
}
/// <summary>
/// 初始化当前巡边器。
/// </summary>
public void InitMachine()
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "SME11", "SME 11"));
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "SME12", "SME 21"));
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "SME13", "SME 31"));
}
}
/// <summary>
/// 开始巡边。
/// </summary>
public void Aligner()
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVN", "CVN"));
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "BAL", "BAL"));
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVF", "CVF"));
}
}
/// <summary>
/// 回机械零点。
/// </summary>
/// <returns>
/// <value>True:命令发送成功。</value>
/// <br/>
/// <value>False:命令发送失败</value>
/// </returns>
public bool MsgHome()
{
//_lstHandler.Clear();
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "HOM", "HOM", 30));
}
return true;
}
/// <summary>
/// 检测当前巡边器上是否有晶圆。
/// </summary>
/// <returns>
/// <value>True:命令发送成功。</value>
/// <br/>
/// <value>False:命令发送失败</value>
/// </returns>
public bool CheckWaferLoad()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerWaferCheckHandler(this));
}
return true;
}
/// <summary>
/// 打开当前巡边器的真空吸附。
/// </summary>
/// <returns>
/// <value>True:命令发送成功。</value>
/// <br/>
/// <value>False:命令发送失败</value>
/// </returns>
public bool OpenVacuum()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVN", "CVN"));
}
return true;
}
/// <summary>
/// 关闭当前巡边器的真空吸附。
/// </summary>
/// <returns>
/// <value>True:命令发送成功。</value>
/// <br/>
/// <value>False:命令发送失败</value>
/// </returns>
public bool CloseVacuum()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVF", "CVF"));
}
return true;
}
private bool ReadVacuum()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVD", "CVD"));
}
return true;
}
public bool MoveToRobotPutPlace()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "MTM", "MTM"));
}
return true;
}
public bool MsgAliger()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "BAL", "BAL"));
}
return true;
}
public bool DoAliger()
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVN", "CVN"));
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "BAL", "BAL"));
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "CVF", "CVF"));
}
return true;
}
public bool ClearError()
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "ERS", "ERS"));
}
return true;
}
public bool ReadError()
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, "PER", "PER"));
}
return true;
}
/// <summary>
/// 新增一条命令到命令执行列队。
/// </summary>
/// <param name="command">命令字符。</param>
public void Set(string command)
{
lock (_locker)
{
_lstHandler.AddLast(new HwAlignerGuideSetHandler(this, command, command));
}
}
public void Terminate()
{
try
{
lock(_locker)
_lstHandler.Clear();
if (_connection != null)
{
_connection.Disconnect();
_connection = null;
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
}
public void Reset()
{
_bIsDisconnect = _connection.IsCommunicationError;
//这里重置了CommunicationError ,就是去了OnTimer里面的重连的触发,所以需要另设变量以触发之(使用timeout来触发的情况)
_connection.SetCommunicationError(false,"");
_trigCommunicationError.RST = true;
_trigRetryConnect.RST = true;
_iCurrentOper = CommandEnum.NULL;
//lock (_locker)
// _lstHandler.Clear();
}
public void SetCurrentOper()
{
_iCurrentOper = CommandEnum.CCD;
}
internal bool ParseData(string name, byte[] buffer, out bool bResult)
{
bResult = true;
var sAnswer = Encoding.ASCII.GetString(buffer).TrimEnd('\r', '\n');
Response = sAnswer;
string[] units = Regex.Split(sAnswer,"\r\n");
foreach (string unit in units)
{
if (unit.Contains("END"))
{
_iCurrentOper = CommandEnum.NULL;
return true;
}
else if (unit.Contains("ERR") && _lastHandlerName != "PER")
{
lock (_locker)
{
_lstHandler.Clear();
}
_iCurrentOper = CommandEnum.NULL;
bResult = false;
EV.PostAlarmLog(Module, $"Aligner, Execute {_lastHandlerName} error, {unit.TrimEnd('\r', '\n')}");
return true; //Handled
}
else if (_lastHandlerName == "CVD")
{
try
{
double x = Convert.ToInt32(unit);
Vacuum = unit + "Kpa";
}
catch
{
Vacuum = "Convert(" + unit + ") Failed.";
}
}
else if (_lastHandlerName == "PER")
{
PError = unit;
}
}
return false;
}
internal bool CheckWaferDataA(string name, byte[] buffer, out bool bResult)
{
bResult = true;
var sAnswer = Encoding.ASCII.GetString(buffer.ToArray());
Response = sAnswer;
if (sAnswer.Contains("END"))
{
HaveWafer = sAnswer.Contains("1\r\nEND");
_iCurrentOper = CommandEnum.NULL;
return true;
}
if (sAnswer.Contains("ERR"))
{
lock (_locker)
{
_lstHandler.Clear();
}
_iCurrentOper = CommandEnum.NULL;
bResult = false;
EV.PostAlarmLog(Module, $"Aligner, Execute {_lastHandlerName} error, {sAnswer.TrimEnd('\r', '\n')}");
return false; //Handle
}
return false;
}
}
#endregion
}
@@ -0,0 +1,41 @@
using MECF.Framework.Common.Communications;
using System.Collections.Generic;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner
{
public class HwAlignerGuideConnection : SerialPortConnectionBase
{
private readonly List<byte> _lstCacheBuffer = new();
private object _lockerActiveHandler = new object();
public HwAlignerGuideConnection(string portName)
: base(portName, 115200, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r", false)
{
}
public override bool SendMessage(byte[] message)
{
_lstCacheBuffer.Clear();
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(byte[] rawMessage)
{
_lstCacheBuffer.AddRange(rawMessage);
var temps = _lstCacheBuffer.ToArray();
HwAlignerGuideMessage msg = new HwAlignerGuideMessage();
msg.IsResponse = false;
msg.IsAck = false;
msg.IsComplete = false;
msg.RawMessage = _lstCacheBuffer.ToArray();
msg.Data = _lstCacheBuffer.ToArray();
msg.IsResponse = true;
msg.IsAck = true;
msg.IsComplete = true;
return msg;
}
}
}
@@ -0,0 +1,15 @@
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner
{
public class HwAlignerGuideMessage : BinaryMessage
{
public byte DeviceAddress { get; set; }
public byte FunctionCode { get; set; }
public byte Length { get; set; }
public byte[] Data { get; set; }
}
}
@@ -0,0 +1,513 @@
using System;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Event;
using Aitex.Core.Util;
using MECF.Framework.Common.Communications;
using MECF.Framework.Common.SubstrateTrackings;
using System.Collections.Generic;
using Aitex.Core.RT.SCCore;
using System.IO.Ports;
using System.Threading;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.AlignersBase;
using Aitex.Core.Common;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.HonghuAligners
{
public class FuqiAligner : AlignerBaseDevice, IConnection
{
public enum AlignerType
{
Mechnical = 0,
Vaccum,
}
public string Address
{
get
{
return "";
}
}
public virtual bool IsConnected
{
get { return true; }
}
public virtual bool Disconnect()
{
return true;
}
public virtual bool Connect()
{
return true;
}
public const string delimiter = "\r";
public int LastErrorCode { get; set; }
public int Status { get; set; }
public int ElapseTime { get; set; }
public int Notch { get; set; }
public bool Initalized { get; set; }
private AlignerType _tazmotype = AlignerType.Vaccum;
public AlignerType TazmoType { get => _tazmotype; }
public bool Communication
{
get
{
return !_commErr;
}
}
public virtual bool Error
{
get; set;
}
public bool Busy { get { return _connection.IsBusy || _lstHandler.Count != 0; } }
public bool TaExecuteSuccss
{
get; set;
}
public void OnWaferPresent(bool iswaferon)
{
if(iswaferon)
{
if (WaferManager.Instance.CheckNoWafer(RobotModuleName, 0))
WaferManager.Instance.CreateWafer(RobotModuleName, 0, WaferStatus.Normal);
}
else
{
if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
{
var wafer = WaferManager.Instance.GetWafer(RobotModuleName, 0);
//WaferManager.Instance.UpdateWaferE90State(wafer.WaferID, EnumE90Status.Aborted);
}
}
}
//private int _deviceAddress;
public override bool IsNeedRelease
{
get
{
return true;
}
}
public FuqiAlignerConnection Connection
{
get => _connection;
}
private FuqiAlignerConnection _connection;
//private int _presetNumber;
private R_TRIG _trigError = new R_TRIG();
private R_TRIG _trigWarningMessage = new R_TRIG();
private R_TRIG _trigCommunicationError = new R_TRIG();
private R_TRIG _trigRetryConnect = new R_TRIG();
private PeriodicJob _thread;
private static Object _locker = new Object();
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
private bool _enableLog = true;
private bool _commErr = false;
private int _defaultChuckPosition;
//private bool _exceuteErr = false;
//private string _addr;
private DeviceTimer _timerQuery = new DeviceTimer();
private string _scRoot;
private string AlarmMechanicalAlignmentError = "MechanicalAlignmentError";
public FuqiAligner(string module, string name,string scRoot,int alignertype=0)
: base(module,name)
{
Name = name;
Module = module;
_scRoot = scRoot;
InitializeFuqi();
//WaferManager.Instance.SubscribeLocation(name, 1);
}
public bool InitializeFuqi()
{
string portName = SC.GetStringValue($"{_scRoot}.{Name}.PortName");
int bautRate = SC.GetValue<int>($"{_scRoot}.{Name}.BaudRate");
int dataBits = SC.GetValue<int>($"{_scRoot}.{Name}.DataBits");
Enum.TryParse(SC.GetStringValue($"{_scRoot}.{Name}.Parity"), out Parity parity);
Enum.TryParse(SC.GetStringValue($"{_scRoot}.{Name}.StopBits"), out StopBits stopBits);
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
_connection = new FuqiAlignerConnection(portName, bautRate, dataBits, parity, stopBits);
_connection.EnableLog(_enableLog);
int count = SC.ContainsItem("System.ComPortRetryCount") ? SC.GetValue<int>("System.ComPortRetryCount") : 5;
int sleep = SC.ContainsItem("System.ComPortRetryDelayTime") ? SC.GetValue<int>("System.ComPortRetryDelayTime") : 2;
if (sleep <= 0 || sleep > 10)
sleep = 2;
int retry = 0;
do
{
_connection.Disconnect();
Thread.Sleep(sleep * 1000);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
break;
}
if (count > 0 && retry++ > count)
{
LOG.Write($"Retry connect {Module}.{Name} stop retry.");
EV.PostAlarmLog(Module, $"Can't connect to {Module}.{Name}.");
break;
}
Thread.Sleep(sleep * 1000);
LOG.Write($"Retry connect {Module}.{Name} for the {retry + 1} time.");
} while (true);
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
// string str = string.Empty;
EV.Subscribe(new EventItem(0, "Event", AlarmMechanicalAlignmentError, "Aligner error", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
// _timerQuery.Start(_queryPeriod);
return true;
}
private bool OnTimer()
{
try
{
_connection.MonitorTimeout();
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{Name}.Address"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
}
return true;
}
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0)
{
//_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
//_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
_lstHandler.RemoveFirst();
if (handler != null) _connection.Execute(handler);
}
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
try
{
_connection.EnableLog(_enableLog);
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
#region Command
public virtual bool MoveToReady(out string reason)
{
reason = "";
return true;
}
public bool RequestPlace(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestPlace));
}
reason = "";
return true;
}
public override bool IsReady()
{
return AlignerState == AlignerStateEnum.Idle && !IsBusy;
}
public override bool IsWaferPresent(int slotindex)
{
return WaferManager.Instance.CheckHasWafer(RobotModuleName, 0);
}
protected override bool fStartLiftup(object[] param)
{
lock (_locker)
{
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestPlace));
}
return true;
}
protected override bool fStartPrepareAccept(object[] param)
{
lock (_locker)
{
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestPlace));
}
return true;
}
protected override bool fStartLiftdown(object[] param)
{
return true;
}
protected override bool fStartAlign(object[] param)
{
double aligneangle = (double)param[0];
lock (_locker)
{
_lstHandler.AddLast(new FuqiRequestHandler(this, $"B{aligneangle.ToString("f1")}"));
//_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetVacuumOffAfterAlign));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestFinishPlace));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestVacuumOff));
}
return true;
}
protected override bool fStop(object[] param)
{
return true;
}
protected override bool FsmAbort(object[] param)
{
return true;
}
protected override bool fClear(object[] param)
{
return true;
}
protected override bool fStartReadData(object[] param)
{
return true;
}
protected override bool fStartSetParameters(object[] param)
{
return true;
}
protected override bool fStartUnGrip(object[] param)
{
lock (_locker)
{
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestVacuumOff));
}
return true;
}
protected override bool fStartGrip(object[] param)
{
lock (_locker)
{
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestVacuumOn));
}
return true;
}
protected override bool fResetToReady(object[] param)
{
return true;
}
protected override bool fReset(object[] param)
{
_trigError.RST = true;
_trigWarningMessage.RST = true;
_connection.SetCommunicationError(false, "");
_trigCommunicationError.RST = true;
if(!_connection.IsConnected)
{
string portName = SC.GetStringValue($"{Module}.{Name}.Address");
int bautRate = SC.GetValue<int>($"{Module}.{Name}.BaudRate");
int dataBits = SC.GetValue<int>($"{Module}.{Name}.DataBits");
Enum.TryParse(SC.GetStringValue($"{Module}.{Name}.Parity"), out Parity parity);
Enum.TryParse(SC.GetStringValue($"{Module}.{Name}.StopBits"), out StopBits stopBits);
_enableLog = SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
_connection = new FuqiAlignerConnection(portName, bautRate, dataBits, parity, stopBits);
_connection.EnableLog(_enableLog);
_connection.Connect();
}
_trigRetryConnect.RST = true;
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetUseNewCommand));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.Reset));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetVacuumOffAfterAlign));
if(SC.ContainsItem($"{_scRoot}.{Name}.CenterAndNotch") && SC.GetValue<bool>($"{_scRoot}.{Name}.CenterAndNotch"))
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetCenterAndNotch));
else
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetOnlyNotch));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetWIDReaderOff));
}
return true;
}
protected override bool fStartInit(object[] param)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetUseNewCommand));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.Reset));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetWIDReaderOff));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetVacuumOnAfterAlign));
if (SC.ContainsItem($"{_scRoot}.{Name}.CenterAndNotch") && SC.GetValue<bool>($"{_scRoot}.{Name}.CenterAndNotch"))
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetCenterAndNotch));
else
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.SetOnlyNotch));
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.RequestPlace));
}
return true;
}
protected override bool fStartHome(object[] param)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new FuqiRequestHandler(this, FuqiAlignerCommand.Reset));
}
return true;
}
protected override bool fError(object[] param)
{
return true;
}
public void OnActionDone()
{
IsBusy = false;
if (_lstHandler.Count == 0)
OnActionDone(null);
}
#endregion
public override bool IsNeedPrepareBeforePlaceWafer()
{
return true;
}
public override double CompensationAngleValue
{
get
{
if (SC.ContainsItem($"Aligner.{Name}.CompensationAngle"))
return SC.GetValue<double>($"Aligner.{Name}.CompensationAngle");
return 0;
}
}
}
}
@@ -0,0 +1,56 @@
using MECF.Framework.Common.Communications;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.HonghuAligners
{
public class FuqiAlignerMessage : AsciiMessage
{
public string Data { get; set; }
}
public class FuqiAlignerMessageBIN : BinaryMessage
{
public byte[] CMD { get; set; }
public byte[] Data { get; set; }
}
public class FuqiAlignerConnection : SerialPortConnectionBase
{
private List<byte> _lstCacheBuffer = new List<byte>();
public FuqiAlignerConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
: base(portName, baudRate, dataBits, parity, stopBits, "\r", false)
{
}
public override bool SendMessage(byte[] message)
{
_lstCacheBuffer.Clear();
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(byte[] rawBuffer)
{
_lstCacheBuffer.AddRange(rawBuffer);
byte[] temps = _lstCacheBuffer.ToArray();
FuqiAlignerMessageBIN msg = new FuqiAlignerMessageBIN();
msg.RawMessage = _lstCacheBuffer.ToArray();
if (temps.Last() == 0xA)
{
_lstCacheBuffer.Clear();
msg.IsResponse = true;
msg.CMD = temps;
}
return msg;
}
}
}
@@ -0,0 +1,360 @@
using System.Collections.Generic;
using System.Text;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.HonghuAligners
{
public static class FuqiAlignerCommand
{
public const string Reset = "C01";
public const string RequestPlace = "C02";
public const string RequestFinishPlace = "C03";
public const string RequestVacuumOn = "C04";
public const string RequestVacuumOff = "C05";
public const string SetVacuumOffAfterAlign = "C06";
public const string SetVacuumOnAfterAlign = "C07";
public const string SetWIDReaderOn = "C08";
public const string SetWIDReaderOff = "C09";
public const string SetWIDReadComplete = "C10";
public const string SetNotchProduct = "C11";
public const string SetLineProduct = "C12";
public const string SetCenterAndNotch = "C13";
public const string SetOnlyNotch = "C14";
public const string SetWIDReadFail = "C15";
public const string SetAdjustFirstTime = "C16";
public const string SetAdjustTwice = "C17";
public const string SetUseNewCommand = "C41";
public const string SetUseOldCommand = "C40";
/// <summary>
/// A
/// </summary>
}
public class FuqiAlignerHandler : HandlerBase
{
public FuqiAligner Device { get; set; }
public string Command;
protected FuqiAlignerHandler(FuqiAligner device, string command) : base(BuildMesage(command))
{
Device = device;
Command = command;
Name = command;
}
public static byte[] BuildMesage(string data)
{
List<byte> ret = new List<byte>();
foreach (char c in data)
{
ret.Add((byte)c);
}
return ret.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
FuqiAlignerMessageBIN response = msg as FuqiAlignerMessageBIN;
ResponseMessage = msg;
transactionComplete = false;
if (response.IsResponse)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
Device.OnActionDone();
return true;
}
}
public enum FuqiMotionStatus
{
None,
Complete,
Fail,
}
public class FuqiResetHandler : FuqiAlignerHandler
{
public FuqiResetHandler(FuqiAligner device, string command) : base(device, BuildData(command))
{
_xAxisStatus = MotionStatus.None;
_yAxisStatus = MotionStatus.None;
_zAxisStatus = MotionStatus.None;
}
private MotionStatus _xAxisStatus;
private MotionStatus _yAxisStatus;
private MotionStatus _zAxisStatus;
private static string BuildData(string command)
{
return command;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
HonghuAlignerMessageBIN response = msg as HonghuAlignerMessageBIN;
ResponseMessage = msg;
Device.TaExecuteSuccss = false;
transactionComplete = false;
if (response.IsAck)
{
if (Encoding.ASCII.GetString(response.CMD).Contains("X01"))
_xAxisStatus = MotionStatus.Complete;
if (Encoding.ASCII.GetString(response.CMD).Contains("X02"))
_xAxisStatus = MotionStatus.Fail;
if (Encoding.ASCII.GetString(response.CMD).Contains("Y01"))
_yAxisStatus = MotionStatus.Complete;
if (Encoding.ASCII.GetString(response.CMD).Contains("Y02"))
_yAxisStatus = MotionStatus.Fail;
if (Encoding.ASCII.GetString(response.CMD).Contains("Z01"))
_zAxisStatus = MotionStatus.Complete;
if (Encoding.ASCII.GetString(response.CMD).Contains("Z02"))
_zAxisStatus = MotionStatus.Fail;
SetState(EnumHandlerState.Completed);
if (_xAxisStatus == MotionStatus.Complete &&
_yAxisStatus == MotionStatus.Complete &&
_zAxisStatus == MotionStatus.Complete) Device.TaExecuteSuccss = true;
if (_xAxisStatus != MotionStatus.None &&
_yAxisStatus != MotionStatus.None &&
_zAxisStatus != MotionStatus.None) transactionComplete = true;
}
return true;
}
}
public class FuqiRequestHandler : FuqiAlignerHandler
{
private string cmd;
public FuqiRequestHandler(FuqiAligner device, string command) : base(device, BuildData(command))
{
cmd = command;
}
private static string BuildData(string command)
{
return command;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
FuqiAlignerMessageBIN response = msg as FuqiAlignerMessageBIN;
ResponseMessage = msg;
Device.TaExecuteSuccss = false;
transactionComplete = false;
string commandstr = Encoding.ASCII.GetString(response.CMD);
if (response.IsResponse)
{
switch (cmd)
{
case FuqiAlignerCommand.RequestPlace:
if (Encoding.ASCII.GetString(response.CMD).Contains("M01"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnWaferPresent(false);
Device.OnActionDone();
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M02"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnWaferPresent(true);
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.RequestFinishPlace:
if (Encoding.ASCII.GetString(response.CMD).Contains("M03"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M04"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M17"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M18"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
break;
case FuqiAlignerCommand.RequestVacuumOn:
if (Encoding.ASCII.GetString(response.CMD).Contains("M05"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M06"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
Device.OnError(Encoding.ASCII.GetString(response.CMD));
}
break;
case FuqiAlignerCommand.RequestVacuumOff:
if (Encoding.ASCII.GetString(response.CMD).Contains("M07"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M08"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
Device.OnError(Encoding.ASCII.GetString(response.CMD));
}
break;
case FuqiAlignerCommand.Reset:
if (Encoding.ASCII.GetString(response.CMD).Contains("M00"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.Initalized = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetVacuumOffAfterAlign:
case FuqiAlignerCommand.SetVacuumOnAfterAlign:
if (Encoding.ASCII.GetString(response.CMD).Contains("M09"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetWIDReaderOn:
case FuqiAlignerCommand.SetWIDReaderOff:
if (Encoding.ASCII.GetString(response.CMD).Contains("M10"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetWIDReadComplete:
case FuqiAlignerCommand.SetWIDReadFail:
if (Encoding.ASCII.GetString(response.CMD).Contains("M11"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetLineProduct:
case FuqiAlignerCommand.SetNotchProduct:
if (Encoding.ASCII.GetString(response.CMD).Contains("M12"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetCenterAndNotch:
case FuqiAlignerCommand.SetOnlyNotch:
if (Encoding.ASCII.GetString(response.CMD).Contains("M13"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetAdjustFirstTime:
if (Encoding.ASCII.GetString(response.CMD).Contains("M31"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetAdjustTwice:
if (Encoding.ASCII.GetString(response.CMD).Contains("M32"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetUseOldCommand:
if (Encoding.ASCII.GetString(response.CMD).Contains("M40"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
case FuqiAlignerCommand.SetUseNewCommand:
if (Encoding.ASCII.GetString(response.CMD).Contains("M41"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
break;
default:
break;
}
if (cmd.Contains("A"))
{
if (Encoding.ASCII.GetString(response.CMD).Contains("M14"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
}
if (cmd.Contains("B"))
{
if (Encoding.ASCII.GetString(response.CMD).Contains("M15"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
}
if (cmd.Contains("T"))
{
if (Encoding.ASCII.GetString(response.CMD).Contains("M16"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.OnActionDone();
}
}
}
return true;
}
}
}
@@ -0,0 +1,725 @@
using System;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.DataCenter;
using Aitex.Core.Util;
using Aitex.Sorter.Common;
using Aitex.Core.RT.Device;
using MECF.Framework.Common.Communications;
using MECF.Framework.Common.SubstrateTrackings;
using System.Collections.Generic;
using Aitex.Core.RT.SCCore;
using System.IO.Ports;
using System.Threading;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.HonghuAligners
{
public class HonghuAligner : BaseDevice, IDevice
{
public enum AlignerType
{
Mechnical =0,
Vaccum,
}
public string Address
{
get
{
return "";
}
}
public virtual bool IsConnected
{
get { return true; }
}
public virtual bool Disconnect()
{
return true;
}
public virtual bool Connect()
{
return true;
}
public const string delimiter = "\r";
public int LastErrorCode { get; set; }
public int Status { get; set; }
public int ErrorCode { get; set; }
public int ElapseTime { get; set; }
public int Notch { get; set; }
public bool Initalized { get; set; }
private AlignerType _tazmotype;
public AlignerType TazmoType { get => _tazmotype; }
public bool Communication
{
get
{
return !_commErr;
}
}
public virtual bool Error
{
get;set;
}
public bool Busy { get { return _connection.IsBusy || _lstHandler.Count != 0; } }
public DeviceState State
{
get
{
if (!Initalized)
{
return DeviceState.Unknown;
}
if (Error)
{
return DeviceState.Error;
}
if (Busy)
return DeviceState.Busy;
return DeviceState.Idle;
}
}
public bool TaExecuteSuccss
{
get;set;
}
public virtual bool WaferOnAligner
{
get
{
return true;
}
}
//private int _deviceAddress;
public HonghuAlignerConnection Connection
{
get => _connection;
}
private HonghuAlignerConnection _connection;
//private int _presetNumber;
private R_TRIG _trigError = new R_TRIG();
private R_TRIG _trigWarningMessage = new R_TRIG();
private R_TRIG _trigCommunicationError = new R_TRIG();
private R_TRIG _trigRetryConnect = new R_TRIG();
private PeriodicJob _thread;
private static Object _locker = new Object();
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
private bool _enableLog = true;
private bool _commErr = false;
private int _defaultChuckPosition;
//private bool _exceuteErr = false;
//private string _addr;
private DeviceTimer _timerQuery = new DeviceTimer();
private string AlarmMechanicalAlignmentError = "MechanicalAlignmentError";
public HonghuAligner(string module, string name)
: base()
{
Name = name;
Module = module;
WaferManager.Instance.SubscribeLocation(name, 1);
}
public bool Initialize()
{
string portName = SC.GetStringValue($"{Module}.{Name}.Address");
int bautRate = SC.GetValue<int>($"{Module}.{Name}.BaudRate");
int dataBits = SC.GetValue<int>($"{Module}.{Name}.DataBits");
Enum.TryParse(SC.GetStringValue($"{Module}.{Name}.Parity"), out Parity parity);
Enum.TryParse(SC.GetStringValue($"{Module}.{Name}.StopBits"), out StopBits stopBits);
//_deviceAddress = SC.GetValue<int>($"{Name}.DeviceAddress");
_enableLog = SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
_tazmotype = (AlignerType)(SC.ContainsItem($"{Name}.AlignerType") ? SC.GetValue<int>($"{Name}.AlignerType") : 0);
_defaultChuckPosition = SC.ContainsItem("Aligner.DefaultChuckPosition") ?
SC.GetValue<int>("Aligner.DefaultChuckPosition") : 1;
_connection = new HonghuAlignerConnection(portName, bautRate, dataBits, parity, stopBits);
_connection.EnableLog(_enableLog);
int count = SC.ContainsItem("System.ComPortRetryCount") ? SC.GetValue<int>("System.ComPortRetryCount") : 5;
int sleep = SC.ContainsItem("System.ComPortRetryDelayTime") ? SC.GetValue<int>("System.ComPortRetryDelayTime") : 2;
if (sleep <= 0 || sleep > 10)
sleep = 2;
int retry = 0;
do
{
_connection.Disconnect();
Thread.Sleep(sleep * 1000);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
break;
}
if (count > 0 && retry++ > count)
{
LOG.Write($"Retry connect {Module}.{Name} stop retry.");
EV.PostAlarmLog(Module, $"Can't connect to {Module}.{Name}.");
break;
}
Thread.Sleep(sleep * 1000);
LOG.Write($"Retry connect {Module}.{Name} for the {retry + 1} time.");
} while (true);
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
DEVICE.Register(String.Format("{0}.{1}", Name, "Init"), (out string reason, int time, object[] param) =>
{
bool ret = Init(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerInit"), (out string reason, int time, object[] param) =>
{
bool ret = Init(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Home"), (out string reason, int time, object[] param) =>
{
bool ret = Home(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerHome"), (out string reason, int time, object[] param) =>
{
bool ret = Home(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Reset"), (out string reason, int time, object[] param) =>
{
bool ret = Clear(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerReset"), (out string reason, int time, object[] param) =>
{
bool ret = Clear(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Grip"), (out string reason, int time, object[] param) =>
{
bool ret = Grip(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Hold Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerGrip"), (out string reason, int time, object[] param) =>
{
bool ret = Grip(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Hold Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Release"), (out string reason, int time, object[] param) =>
{
bool ret = Release(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Release Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerRelease"), (out string reason, int time, object[] param) =>
{
bool ret = Release(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Release Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "LiftUp"), (out string reason, int time, object[] param) =>
{
bool ret = LiftUp(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Up");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerLiftUp"), (out string reason, int time, object[] param) =>
{
bool ret = LiftUp(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Up");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "LiftDown"), (out string reason, int time, object[] param) =>
{
bool ret = LiftDown(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Down");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerLiftDown"), (out string reason, int time, object[] param) =>
{
bool ret = LiftDown(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Down");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Stop"), (out string reason, int time, object[] param) =>
{
bool ret = Stop(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Stop Align");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerStop"), (out string reason, int time, object[] param) =>
{
bool ret = Stop(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Stop Align");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Align"), (out string reason, int time, object[] param) =>
{
double angle = double.Parse((string)param[0]);
bool ret = Align(angle, out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "PreAlign");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerAlign"), (out string reason, int time, object[] param) =>
{
double angle = double.Parse((string)param[0]);
bool ret = Align(angle, out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "PreAlign");
return true;
}
return false;
});
DATA.Subscribe($"{Name}.State", () => State);
DATA.Subscribe($"{Name}.AlignerState", () => State.ToString());
DATA.Subscribe($"{Name}.Busy", () => Busy);
DATA.Subscribe($"{Name}.ErrorCode", () => ErrorCode);
DATA.Subscribe($"{Name}.Error", () => Error);
DATA.Subscribe($"{Name}.ElapseTime", () => ElapseTime);
DATA.Subscribe($"{Name}.Notch", () => Notch);
DATA.Subscribe($"{Name}.WaferOnAligner", () => WaferOnAligner);
// string str = string.Empty;
EV.Subscribe(new EventItem(0, "Event", AlarmMechanicalAlignmentError, "Aligner error", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
// _timerQuery.Start(_queryPeriod);
return true;
}
private bool OnTimer()
{
try
{
_connection.MonitorTimeout();
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{Name}.Address"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
}
return true;
}
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0)
{
//_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
//_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
if (handler != null) _connection.Execute(handler);
_lstHandler.RemoveFirst();
}
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
public void Terminate()
{
_connection.Disconnect();
}
public void Monitor()
{
try
{
_connection.EnableLog(_enableLog);
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
}
public void Reset()
{
_trigError.RST = true;
_trigWarningMessage.RST = true;
_connection.SetCommunicationError(false, "");
_trigCommunicationError.RST = true;
_enableLog = SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
_trigRetryConnect.RST = true;
}
internal void NoteError(string reason)
{
_trigWarningMessage.CLK = true;
if (_trigWarningMessage.Q)
{
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
}
}
#region Command
public virtual bool Reset(out string reason)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.Reset));
}
reason = "";
return true;
}
public virtual bool Init(out string reason)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.Reset));
}
reason = "";
return true;
}
public virtual bool Home(out string reason)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.Reset));
}
reason = "";
return true;
}
public virtual bool Clear(out string reason)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.Reset));
}
reason = "";
return true;
}
public virtual bool Grip(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.RequestVacuumOn));
}
reason = "";
return true;
}
public virtual bool Release(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.RequestVacuumOff));
}
reason = "";
return true;
}
public virtual bool LiftUp(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.RequestPlace));
}
reason = "";
return true;
}
public virtual bool LiftDown(out string reason)
{
lock (_locker)
{
}
reason = "";
return true;
}
public virtual bool MoveToReady(out string reason)
{
reason = "";
return true;
}
public virtual bool Stop(out string reason)
{
reason = string.Empty;
reason = "";
return true;
}
public virtual bool Align(double angle, out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.SetNotReadLM));
_lstHandler.AddLast(new RequestHandler(this, $"B{angle.ToString()}"));
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.SetVacuumOnAfterAln));
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.RequestFinishPlace));
}
reason = "";
return true;
}
public virtual bool RequestPlace(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new RequestHandler(this, HonghuAlignerCommand.RequestPlace));
}
reason = "";
return true;
}
public virtual bool QueryStatus(out string reason)
{
lock (_locker)
{
}
reason = "";
return true;
}
#endregion
}
}
@@ -0,0 +1,56 @@
using MECF.Framework.Common.Communications;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.HonghuAligners
{
public class HonghuAlignerMessage : AsciiMessage
{
public string Data { get; set; }
}
public class HonghuAlignerMessageBIN : BinaryMessage
{
public byte[] CMD { get; set; }
public byte[] Data { get; set; }
}
public class HonghuAlignerConnection : SerialPortConnectionBase
{
private List<byte> _lstCacheBuffer = new List<byte>();
public HonghuAlignerConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
: base(portName, baudRate, dataBits, parity, stopBits, "\r", false)
{
}
public override bool SendMessage(byte[] message)
{
_lstCacheBuffer.Clear();
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(byte[] rawBuffer)
{
_lstCacheBuffer.AddRange(rawBuffer);
byte[] temps = _lstCacheBuffer.ToArray();
HonghuAlignerMessageBIN msg = new HonghuAlignerMessageBIN();
msg.RawMessage = _lstCacheBuffer.ToArray();
if(temps.Length == 4 && temps.Last() == 0xA)
{
_lstCacheBuffer.Clear();
msg.IsResponse = true;
msg.CMD = temps.Take(3).ToArray();
}
return msg;
}
}
}
@@ -0,0 +1,304 @@
using System.Collections.Generic;
using System.Text;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.HonghuAligners
{
public static class HonghuAlignerCommand
{
public const string Reset = "C01";
public const string RequestPlace = "C02";
public const string RequestFinishPlace = "C03";
public const string RequestVacuumOn = "C04";
public const string RequestVacuumOff = "C05";
public const string SetWafer200mm = "C06";
public const string SetWafer300mm = "C07";
public const string SetVacuumOffAfterAln = "C08";
public const string SetVacuumOnAfterAln = "C09";
public const string SetReadLM = "C10";
public const string SetNotReadLM = "C11";
public const string SetAlnAngleTo180 = "C12";
public const string SetAlnAngleTo270 = "C13";
/// <summary>
/// A
/// </summary>
}
public class HonghuAlignerHandler : HandlerBase
{
public HonghuAligner Device { get; set; }
public string Command;
protected HonghuAlignerHandler(HonghuAligner device, string command) : base(BuildMesage(command))
{
Device = device;
Command = command;
Name = command;
}
public static byte[] BuildMesage(string data)
{
List<byte> ret = new List<byte>();
foreach(char c in data)
{
ret.Add((byte)c);
}
return ret.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
HonghuAlignerMessageBIN response = msg as HonghuAlignerMessageBIN;
ResponseMessage = msg;
transactionComplete = false;
if(response.IsResponse)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
return true;
}
}
public enum MotionStatus
{
None,
Complete,
Fail,
}
public class ResetHandler : HonghuAlignerHandler
{
public ResetHandler(HonghuAligner device, string command) : base(device, BuildData(command))
{
_xAxisStatus = MotionStatus.None;
_yAxisStatus = MotionStatus.None;
_zAxisStatus = MotionStatus.None;
}
private MotionStatus _xAxisStatus;
private MotionStatus _yAxisStatus;
private MotionStatus _zAxisStatus;
private static string BuildData(string command)
{
return command;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
HonghuAlignerMessageBIN response = msg as HonghuAlignerMessageBIN;
ResponseMessage = msg;
Device.TaExecuteSuccss = false;
transactionComplete = false;
if (response.IsAck)
{
if (Encoding.ASCII.GetString(response.CMD).Contains("X01"))
_xAxisStatus = MotionStatus.Complete;
if (Encoding.ASCII.GetString(response.CMD).Contains("X02"))
_xAxisStatus = MotionStatus.Fail;
if (Encoding.ASCII.GetString(response.CMD).Contains("Y01"))
_yAxisStatus = MotionStatus.Complete;
if (Encoding.ASCII.GetString(response.CMD).Contains("Y02"))
_yAxisStatus = MotionStatus.Fail;
if (Encoding.ASCII.GetString(response.CMD).Contains("Z01"))
_zAxisStatus = MotionStatus.Complete;
if (Encoding.ASCII.GetString(response.CMD).Contains("Z02"))
_zAxisStatus = MotionStatus.Fail;
SetState(EnumHandlerState.Completed);
if (_xAxisStatus == MotionStatus.Complete &&
_yAxisStatus == MotionStatus.Complete &&
_zAxisStatus == MotionStatus.Complete) Device.TaExecuteSuccss = true;
if(_xAxisStatus != MotionStatus.None &&
_yAxisStatus != MotionStatus.None &&
_zAxisStatus != MotionStatus.None) transactionComplete = true;
}
return true;
}
}
public class RequestHandler: HonghuAlignerHandler
{
private string cmd;
public RequestHandler(HonghuAligner device,string command): base(device, BuildData(command))
{
cmd = command;
}
private static string BuildData(string command)
{
return command;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
HonghuAlignerMessageBIN response = msg as HonghuAlignerMessageBIN;
ResponseMessage = msg;
Device.TaExecuteSuccss = false;
transactionComplete = false;
if (response.IsResponse)
{
switch (cmd)
{
case HonghuAlignerCommand.RequestPlace:
if (Encoding.ASCII.GetString(response.CMD).Contains("M06"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M07"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.RequestFinishPlace:
if (Encoding.ASCII.GetString(response.CMD).Contains("M08"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M09"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.RequestVacuumOn:
if (Encoding.ASCII.GetString(response.CMD).Contains("M01"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M02"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.RequestVacuumOff:
if (Encoding.ASCII.GetString(response.CMD).Contains("M03"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
if (Encoding.ASCII.GetString(response.CMD).Contains("M04"))
{
Device.TaExecuteSuccss = false;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.Reset :
if (Encoding.ASCII.GetString(response.CMD).Contains("M05"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
Device.Initalized = true;
}
break;
case HonghuAlignerCommand.SetWafer200mm:
if (Encoding.ASCII.GetString(response.CMD).Contains("M10"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetWafer300mm:
if (Encoding.ASCII.GetString(response.CMD).Contains("M10"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetVacuumOffAfterAln:
if (Encoding.ASCII.GetString(response.CMD).Contains("M11"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetVacuumOnAfterAln:
if (Encoding.ASCII.GetString(response.CMD).Contains("M11"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetNotReadLM:
if (Encoding.ASCII.GetString(response.CMD).Contains("M13"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetReadLM:
if (Encoding.ASCII.GetString(response.CMD).Contains("M13"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetAlnAngleTo180:
if (Encoding.ASCII.GetString(response.CMD).Contains("M12"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
case HonghuAlignerCommand.SetAlnAngleTo270:
if (Encoding.ASCII.GetString(response.CMD).Contains("M12"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
break;
default:
break;
}
if(cmd.Contains("A"))
{
if (Encoding.ASCII.GetString(response.CMD).Contains("M14"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
}
if (cmd.Contains("B"))
{
if (Encoding.ASCII.GetString(response.CMD).Contains("M15"))
{
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
}
}
return true;
}
}
}
@@ -0,0 +1,77 @@
using System.Collections.Generic;
using System.IO.Ports;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.JelAligner
{
public class JelAlignerMessage : AsciiMessage
{
public string Data { get; set; }
public string ErrorText { get; set; }
}
public class JelAlignerConnection : SerialPortConnectionBase
{
//private bool _isAckMode = false;//should read from config file
private string _cachedBuffer = string.Empty;
private List<byte> _lstCacheBuffer = new List<byte>();
public JelAlignerConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
: base(portName, baudRate, dataBits, parity, stopBits, "", true)
{
}
public override bool SendMessage(byte[] message)
{
_lstCacheBuffer.Clear();
return base.SendMessage(message);
}
public override bool SendMessage(string message)
{
_cachedBuffer = string.Empty;
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(string rawmsg)
{
_cachedBuffer += rawmsg;
JelAlignerMessage msg = new JelAlignerMessage();
if (_activeHandler == null)
{
_cachedBuffer = string.Empty;
return msg;
}
if (_cachedBuffer == ">" && _activeHandler.GetType() != typeof(JelAlignerReadHandler))
{
msg.IsAck = true;
msg.Data = _cachedBuffer.Replace(">", "").Replace("\r", "");
_cachedBuffer = string.Empty;
}
else if (_cachedBuffer.Contains(">$") && _cachedBuffer.Contains("\r"))
{
msg.IsAck = true;
msg.Data = _cachedBuffer.Replace(">", "").Replace("\r", "");
_cachedBuffer = string.Empty;
}
else if (_cachedBuffer.Contains("\r"))
{
msg.IsAck = true;
msg.Data = _cachedBuffer.Replace(">", "").Replace("\r", "");
_cachedBuffer = string.Empty;
}
//else if (_cachedBuffer.Contains("\r"))
//{
// msg.IsAck = true;
// msg.Data = rawmsg.Replace(">", "").Replace("\r", "");
// _cachedBuffer = string.Empty;
//}
return msg;
}
}
}
@@ -0,0 +1,793 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Aitex.Core.RT.Device.Unit;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.Communications;
using MECF.Framework.Common.SubstrateTrackings;
using Aitex.Core.Common;
using Aitex.Core.RT.DataCenter;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.AlignersBase;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
using Aitex.Core.RT.Device.Devices;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.JelAligner
{
public class JelAlignerEG : JelAligner, IConnection
{
/* SAL3262HV model: for 2-inch to 6-inch wafer
SAL3362HV model: for 3-inch to 6-inch wafer
SAL3482HV model: for 4-inch to 8-inch wafer
SAL38C3HV model: for 8-inch to 12-inch wafer*/
public JelAlignerEG(string module, string name, string scRoot, IoSensor[] dis, IoTrigger[] dos, int alignerType = 0, string robotModel = "") :
base(module, name,scRoot,dis,dos,alignerType,robotModel)
{
isSimulatorMode = SC.ContainsItem("System.IsSimulatorMode") ? SC.GetValue<bool>("System.IsSimulatorMode") : false;
_robotModel = robotModel;
_scRoot = scRoot;
_diWaferPresent = dis[0];
//ResetPropertiesAndResponses();
//RegisterSpecialData();
//_enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
//_bodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
//PortName = SC.GetStringValue($"{_scRoot}.{Name}.PortName");
//TimelimitAlginerHome = SC.GetValue<int>($"{_scRoot}.{Name}.TimeLimitAlignerHome");
//TimelimitForAlignWafer = SC.GetValue<int>($"{_scRoot}.{Name}.TimeLimitForAlignWafer");
//_connection = new JelAlignerConnection(PortName);
//_connection.EnableLog(_enableLog);
//if (_connection.Connect())
//{
// EV.PostInfoLog(Module, $"{Module}.{Name} connected");
//}
//_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
}
private IoSensor _diWaferPresent;
public override bool OnTimer()
{
try
{
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstMoveHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{_scRoot}.{Name}.PortName"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
else
{
}
}
return true;
}
HandlerBase handler = null;
DateTime dtstart = DateTime.Now;
lock (_locker)
{
while (_lstMoveHandler.Count > 0 && _lstMonitorHandler.Count == 0)
{
if (!_connection.IsBusy)
{
if (YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd &&
XAxisStatus == JelAxisStatus.NormalEnd)
{
handler = _lstMoveHandler.First.Value;
_connection.Execute(handler);
_lstMoveHandler.RemoveFirst();
}
else
{
_connection.Execute(new JelAlignerReadHandler(this, ""));
}
}
else
{
_connection.MonitorTimeout();
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
_lstMoveHandler.Clear();
OnError($"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
if (DateTime.Now - dtstart > TimeSpan.FromSeconds(150))
{
_lstMonitorHandler.Clear();
_lstMoveHandler.Clear();
OnError("Robot action timeout");
}
}
while (_lstMonitorHandler.Count > 0)
{
if (!_connection.IsBusy)
{
handler = _lstMonitorHandler.First.Value;
_connection.Execute(handler);
_lstMonitorHandler.RemoveFirst();
}
if (DateTime.Now - dtstart > TimeSpan.FromSeconds(150))
{
_lstMonitorHandler.Clear();
_lstMoveHandler.Clear();
OnError("Robot action timeout");
}
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
private void ResetPropertiesAndResponses()
{
}
private void RegisterSpecialData()
{
DATA.Subscribe($"{Module}.{Name}.CurrentReadRoutine", () => CurrentReadRoutine);
DATA.Subscribe($"{Module}.{Name}.CurrentReadSpeedData", () => CurrentReadSpeedData);
DATA.Subscribe($"{Module}.{Name}.CurrentReadAData", () => CurrentReadAData);
DATA.Subscribe($"{Module}.{Name}.IsLeftArmPressureSensorON", () => IsLeftArmPressureSensorON);
DATA.Subscribe($"{Module}.{Name}.IsRightArmPressureSensorON", () => IsRightArmPressureSensorON);
DATA.Subscribe($"{Module}.{Name}.YAxisAndThetaAxisStatus", () => YAxisAndThetaAxisStatus.ToString());
DATA.Subscribe($"{Module}.{Name}.XAxisStatus", () => XAxisStatus.ToString());
DATA.Subscribe($"{Module}.{Name}.CurrentCompoundCommandStatus", () => CurrentCompoundCommandStatus.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadCassetNumber", () => ReadCassetNumber.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadSlotNumber", () => ReadSlotNumber.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadBankNumber", () => ReadBankNumber.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadPosLeftArmPostion", () => ReadPosLeftArmPostion);
DATA.Subscribe($"{Module}.{Name}.ReadPosRightArmPostion", () => ReadPosRightArmPostion.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadPosZAxisPostion", () => ReadPosZAxisPostion.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadPosThetaAxisPostion", () => ReadPosThetaAxisPostion.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadParameterMax", () => ReadParameterMax.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadParameterMin", () => ReadParameterMin.ToString());
DATA.Subscribe($"{Module}.{Name}.ReadParameterValue", () => ReadParameterValue.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingFirstSlotPosition", () => MappingFirstSlotPosition.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingGateWidth", () => MappingGateWidth.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingMaxDetectWidth", () => MappingMaxDetectWidth.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingMinDetectWidth", () => MappingMinDetectWidth.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingSlotsNumber", () => MappingSlotsNumber.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingSpeed", () => MappingSpeed.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingStopPostion", () => MappingStopPostion.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingTopSlotPostion", () => MappingTopSlotPostion.ToString());
DATA.Subscribe($"{Module}.{Name}.IsMappingSensorON", () => IsMappingSensorON.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingWaferResult", () => MappingWaferResult.ToString());
DATA.Subscribe($"{Module}.{Name}.MappingWidthResult", () => MappingWidthResult.ToString());
}
private int _bodyNumber;
private string _robotModel; //T-00902H
//public int BodyNumber { get => _bodyNumber; }
private string _address = "";
//public string Address { get => _address; }
private bool isSimulatorMode;
private string _scRoot;
private PeriodicJob _thread;
//protected JelAlignerConnection _connection;
private R_TRIG _trigError = new R_TRIG();
private R_TRIG _trigCommunicationError = new R_TRIG();
private R_TRIG _trigRetryConnect = new R_TRIG();
private R_TRIG _trigActionDone = new R_TRIG();
private LinkedList<HandlerBase> _lstMoveHandler = new LinkedList<HandlerBase>();
private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
private bool _isAligned;
private bool _isOnHomedPostion;
//public int TimelimitAlginerHome { get; private set; }
//public int TimelimitForAlignWafer { get; private set; }
private object _locker = new object();
private bool _enableLog;
#region ParseHandler
private void ParseRobotStatus(string data)
{
if (data.Length < 2) return;
YAxisAndThetaAxisStatus = (JelAxisStatus)Convert.ToInt16(data.ToArray()[0].ToString());
XAxisStatus = (JelAxisStatus)Convert.ToInt16(data.ToArray()[1].ToString());
if (YAxisAndThetaAxisStatus == JelAxisStatus.SensorError || YAxisAndThetaAxisStatus == JelAxisStatus.CommandError)
{
IsBusy = false;
OnError($"YAxisAndThetaAxisStatus is {YAxisAndThetaAxisStatus}");
}
if (XAxisStatus == JelAxisStatus.SensorError || XAxisStatus == JelAxisStatus.CommandError)
{
IsBusy = false;
OnError($"XAxisStatus is {XAxisStatus}");
}
}
private void ParseRobotPostion(string axis, string data)
{
float _floatvalue;
if (!float.TryParse(data, out _floatvalue)) return;
if (axis == "1")
{
RightArmPostion = _floatvalue;
PositionAxis1 = _floatvalue;
}
if (axis == "2")
{
ThetaAxisPostion = _floatvalue;
PositionAxis2 = _floatvalue;
}
if (axis == "3")
{
LeftArmPostion = _floatvalue;
PositionAxis3 = _floatvalue;
}
if (axis == "4")
{
ZAxisPostion = _floatvalue;
PositionAxis4 = _floatvalue;
}
}
#endregion
public override bool IsNeedChangeWaferSize(WaferSize wz)
{
return false;
}
protected override bool fReset(object[] param)
{
if (!_connection.IsConnected)
{
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
_bodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
PortName = SC.GetStringValue($"{_scRoot}.{Name}.PortName");
TimelimitAlginerHome = SC.GetValue<int>($"{_scRoot}.{Name}.TimeLimitAlignerHome");
TimelimitForAlignWafer = SC.GetValue<int>($"{_scRoot}.{Name}.TimeLimitForAlignWafer");
_connection = new JelAlignerConnection(PortName);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
}
_trigError.RST = true;
_connection.SetCommunicationError(false, "");
_trigCommunicationError.RST = true;
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
_connection.EnableLog(_enableLog);
_trigRetryConnect.RST = true;
_lstMoveHandler.Clear();
_lstMonitorHandler.Clear();
_connection.ForceClear();
lock (_locker)
{
_lstMonitorHandler.AddLast(new JelAlignerRawCommandHandler(this, $"${BodyNumber}RD\r"));
_lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, "WIS1"));
}
return true;
}
protected override bool fMonitorReset(object[] param)
{
_isAligned = false;
return true;
//if (XAxisStatus == JelAxisStatus.NormalEnd
// && (YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
// && _lstMoveHandler.Count == 0
// && _lstMonitorHandler.Count == 0
// && !_connection.IsBusy)
//{
// IsBusy = false;
// return true;
//}
//if (_lstMonitorHandler.Count == 0 && _lstMoveHandler.Count == 0 && !_connection.IsBusy)
// _connection.Execute(new JelAlignerReadHandler(this, ""));
//return false;
}
protected override bool fStartInit(object[] param)
{
lock (_locker)
{
int alignspeed = AlginerSpeedSetPoint * 8191 / 100;
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "W0"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerSetHandler(this, "WSP", alignspeed.ToString()));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WU"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WT"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
_isAligned = false;
_isOnHomedPostion = false;
_dtActionStart = DateTime.Now;
return true;
}
public override WaferSize GetCurrentWaferSize()
{
return WaferSize.WS12;
}
private DateTime _dtActionStart;
protected override bool fMonitorInit(object[] param)
{
_isAligned = false;
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
OnError("Init timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
_isOnHomedPostion = true;
if (IsWaferPresent(0) && WaferManager.Instance.CheckNoWafer(RobotModuleName, 0))
{
WaferManager.Instance.CreateWafer(RobotModuleName, 0,
WaferStatus.Normal, GetCurrentWaferSize());
}
if (!IsWaferPresent(0) && WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
{
EV.PostAlarmLog("System", $"There's no phisical wafer on {RobotModuleName},but it has wafer information on.");
//WaferManager.Instance.DeleteWafer(RobotModuleName, 0);
}
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
protected override bool fStartHome(object[] param)
{
lock (_locker)
{
int alignspeed = AlginerSpeedSetPoint * 8191 / 100;
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "W0"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerSetHandler(this, "WSP", alignspeed.ToString()));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WU"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WT"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
_isAligned = false;
_dtActionStart = DateTime.Now;
return true;
}
protected override bool fMonitorHome(object[] param)
{
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
OnError("Home timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
_isOnHomedPostion = true;
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
public override bool IsReady()
{
return AlignerState == AlignerStateEnum.Idle && !IsBusy;
}
public override bool IsWaferPresent(int slotindex)
{
if (_diWaferPresent != null)
return _diWaferPresent.Value;
return WaferManager.Instance.CheckHasWafer(RobotModuleName, slotindex);
}
public override bool IsNeedPrepareBeforePlaceWafer()
{
return !_isOnHomedPostion;
}
protected override bool fStartLiftup(object[] param) //Ungrip
{
_dtActionStart = DateTime.Now;
lock (_locker)
{
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WU"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
return true;
}
protected override bool fMonitorLiftup(object[] param)
{
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
OnError("Aligner lift up timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
_isAligned = false;
_isOnHomedPostion = false;
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
protected override bool fStartLiftdown(object[] param)
{
_dtActionStart = DateTime.Now;
lock (_locker)
{
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WD"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
return true;
}
protected override bool fMonitorLiftdown(object[] param)
{
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
OnError("Aligner lift down timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
_isAligned = true;
_isOnHomedPostion = false;
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
protected override bool fStartAlign(object[] param)
{
//WaferSize wz = WaferManager.Instance.GetWaferSize(RobotModuleName, 0);
//if (wz != GetCurrentWaferSize())
//{
// EV.PostAlarmLog("System", "Wafer size is not match, can't do alignment");
// return false;
//}
_isOnHomedPostion = false;
double aligneangle = (double)param[0];
while (aligneangle < 0 || aligneangle > 360)
{
if (aligneangle < 0)
aligneangle += 360;
if (aligneangle > 360)
aligneangle -= 360;
}
//int speed = SC.GetValue<int>($"{_scRoot}.{Name}.AlignSpeed");
int intangle = (int)(aligneangle * 76799 / 360);
CurrentNotch = aligneangle;
lock (_locker)
{
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WC")); //Close grip
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WD")); //Align
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
//_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WA")); //Move down
//_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerSetHandler(this, "WOP", intangle.ToString()));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WOF"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WU")); //Move Up
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC")); //Ungrip
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WT"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
_dtActionStart = DateTime.Now;
return true;
}
protected override bool fMonitorAligning(object[] param)
{
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
OnError("Alignment timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
_isOnHomedPostion = true;
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
protected override bool fStop(object[] param)
{
return true;
}
protected override bool FsmAbort(object[] param)
{
return true;
}
protected override bool fClear(object[] param)
{
return true;
}
protected override bool fStartReadData(object[] param)
{
return true;
}
protected override bool fStartSetParameters(object[] param)
{
_dtActionStart = DateTime.Now;
_currentSetParameter = param[0].ToString();
switch (_currentSetParameter)
{
case "WaferSize":
if (GetWaferState() != RobotArmWaferStateEnum.Absent)
{
EV.PostAlarmLog("System", "Can't set wafersize when wafer is not absent");
return false;
}
_currentSetWaferSize = (WaferSize)param[1];
if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
{
WaferManager.Instance.UpdateWaferSize(RobotModuleName, 0, _currentSetWaferSize);
}
string strpara;
switch (_currentSetWaferSize)
{
case WaferSize.WS2:
case WaferSize.WS3:
case WaferSize.WS4:
case WaferSize.WS5:
case WaferSize.WS6:
case WaferSize.WS8:
strpara = _currentSetWaferSize.ToString().Replace("WS", "");
break;
case WaferSize.WS12:
strpara = "9";
break;
default:
return false;
}
lock (_locker)
{
_lstMonitorHandler.AddLast(new JelAlignerMoveHandler(this, "WAS", strpara));
_lstMonitorHandler.AddLast(new JelAlignerReadHandler(this, "WAS"));
}
break;
}
return true;
}
private string _currentSetParameter;
private WaferSize _currentSetWaferSize = WaferSize.WS0;
protected override bool fMonitorSetParamter(object[] param)
{
IsBusy = false;
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(TimelimitForAlignWafer))
OnError("Set parameter timeout");
switch (_currentSetParameter)
{
case "WaferSize":
if (_lstMonitorHandler.Count == 0 && _lstMoveHandler.Count == 0 && !_connection.IsBusy)
{
if (_currentSetWaferSize != Size)
{
OnError($"Fail to set wafer size,set:{_currentSetWaferSize},return:{Size}");
}
if (_currentSetWaferSize == WaferSize.WS12)
{
return true;
}
if (_currentSetWaferSize == WaferSize.WS8)
{
return true;
}
return true;
}
break;
}
return false;
}
protected override bool fStartUnGrip(object[] param)
{
lock (_locker)
{
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WDF"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
_diStartUngrip = DateTime.Now;
return true;
}
private DateTime _diStartUngrip;
protected override bool fMonitorUnGrip(object[] param)
{
if (DateTime.Now - _diStartUngrip > TimeSpan.FromSeconds(10))
OnError("UnGrip timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
protected override bool fStartGrip(object[] param)
{
lock (_locker)
{
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
_diStartUngrip = DateTime.Now;
return true;
}
protected override bool fMonitorGrip(object[] param)
{
if (DateTime.Now - _diStartUngrip > TimeSpan.FromSeconds(10))
OnError("Grip timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy)
{
if (XAxisStatus == JelAxisStatus.NormalEnd && YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
return true;
}
else
{
_connection.Execute(new JelAlignerReadHandler(this, ""));
}
}
return false;
}
protected override bool fResetToReady(object[] param)
{
return true;
}
protected override bool fError(object[] param)
{
return true;
}
public override void OnError(string errortext)
{
_isAligned = false;
_isOnHomedPostion = false;
_lstMonitorHandler.Clear();
_lstMoveHandler.Clear();
base.OnError(errortext);
}
public override bool IsNeedRelease
{
get => !_isOnHomedPostion;
}
protected override bool fStartPrepareAccept(object[] param)
{
_dtActionStart = DateTime.Now;
lock (_locker)
{
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WU"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WUC"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
_lstMoveHandler.AddLast(new JelAlignerMoveHandler(this, "WT"));
_lstMoveHandler.AddLast(new JelAlignerReadHandler(this, ""));
}
return true;
}
protected override bool fMonitorPrepareAccept(object[] param)
{
if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds((double)TimelimitAlginerHome))
OnError("Home timeout");
if (_lstMoveHandler.Count == 0
&& !_connection.IsBusy && XAxisStatus == JelAxisStatus.NormalEnd
&& YAxisAndThetaAxisStatus == JelAxisStatus.NormalEnd)
{
IsBusy = false;
_isAligned = false;
_isOnHomedPostion = true;
return true;
}
if (_lstMoveHandler.Count == 0 && !_connection.IsBusy)
_connection.Execute(new JelAlignerReadHandler(this, ""));
return false;
}
}
}
@@ -0,0 +1,124 @@
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.JelAligner
{
public abstract class JelAlignerHandler : HandlerBase
{
public JelAligner Device { get; }
protected string _command;
protected string _parameter;
protected JelAlignerHandler(JelAligner device, string command, string parameter = null)
: base(BuildMessage(device.BodyNumber, command, parameter))
{
Device = device;
_command = command;
_parameter = parameter;
Name = command;
}
protected JelAlignerHandler(string command)
: base(command)
{
_command = command;
}
private static string BuildMessage(int bodyno, string command, string parameter)
{
return $"${bodyno}{command}{parameter}\r";
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
JelAlignerMessage response = msg as JelAlignerMessage;
ResponseMessage = msg;
if (response.IsAck)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
return true;
}
transactionComplete = false;
return false;
}
}
public class JelAlignerReadHandler : JelAlignerHandler
{
public JelAlignerReadHandler(JelAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
JelAlignerMessage response = msg as JelAlignerMessage;
ResponseMessage = msg;
if (response.IsAck)
{
Device.ParseData(_command, _parameter, response.Data);
SetState(EnumHandlerState.Completed);
transactionComplete = true;
return true;
}
transactionComplete = false;
return false;
}
}
public class JelAlignerSetHandler : JelAlignerHandler
{
public JelAlignerSetHandler(JelAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
LOG.Write($"{device.Name} execute set command {command} {temp} in byte.");
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
JelAlignerMessage response = msg as JelAlignerMessage;
ResponseMessage = msg;
if (response.IsAck)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
return true;
}
transactionComplete = false;
return false;
}
}
public class JelAlignerMoveHandler : JelAlignerHandler
{
public JelAlignerMoveHandler(JelAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
LOG.Write($"{device.Name} execute move command {command} {temp} in byte.");
}
}
public class JelAlignerRawCommandHandler : JelAlignerHandler
{
public JelAlignerRawCommandHandler(JelAligner device, string command)
: base(command)
{
LOG.Write($"{device.Name} execute move command {command} in byte.");
}
}
}
@@ -0,0 +1,677 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.Communications;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
using Newtonsoft.Json;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.SiasunAligner
{
public class SiasunAligner : SerialPortDevice, IConnection
{
public string Address { get; }
public bool IsConnected { get; }
public bool Connect()
{
return true;
}
public bool Disconnect()
{
return true;
}
public string PortStatus { get; set; } = "Closed";
private SiasunAlignerConnection _connection;
public SiasunAlignerConnection Connection
{
get { return _connection; }
}
private R_TRIG _trigError = new R_TRIG();
private R_TRIG _trigCommunicationError = new R_TRIG();
private R_TRIG _trigRetryConnect = new R_TRIG();
private PeriodicJob _thread;
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
public List<IOResponse> IOResponseList { get; set; } = new List<IOResponse>();
private object _locker = new object();
private bool _enableLog;
private string _scRoot;
public SiasunAligner(string module, string name, string scRoot, string portName) : base(module, name)
{
_scRoot = scRoot;
PortName = portName;
}
private void ResetPropertiesAndResponses()
{
foreach (var ioResponse in IOResponseList)
{
ioResponse.ResonseContent = null;
ioResponse.ResonseRecievedTime = DateTime.Now;
}
}
public override bool Initialize(string portName)
{
base.Initialize(portName);
ResetPropertiesAndResponses();
if (_connection != null && _connection.IsConnected && PortName == portName)
return true;
if (_connection != null && _connection.IsConnected)
_connection.Disconnect();
PortName = portName;
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
_connection = new SiasunAlignerConnection(PortName);
_connection.EnableLog(_enableLog);
if (_connection.Connect())
{
PortStatus = "Open";
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
return true;
}
public bool InitConnection(string portName, int bautRate, int dataBits, Parity parity, StopBits stopBits)
{
_connection = new SiasunAlignerConnection(portName, bautRate, dataBits, parity, stopBits);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
return true;
}
private bool OnTimer()
{
try
{
//_connection.MonitorTimeout();
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{ScBasePath}.{Name}.Address"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
else
{
//_lstHandler.AddLast(new SiasunAlignerQueryPinHandler(this, _deviceAddress));
//_lstHandler.AddLast(new SiasunAlignerSetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
}
}
return true;
}
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0)
{
foreach (var monitorHandler in _lstMonitorHandler)
{
_lstHandler.AddLast(monitorHandler);
}
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
_lstHandler.RemoveFirst();
}
}
if (handler != null)
{
_connection.Execute(handler);
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
public override void Monitor()
{
try
{
//_connection.EnableLog(_enableLog);
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
}
public override void Reset()
{
_trigError.RST = true;
_connection.SetCommunicationError(false, "");
_trigCommunicationError.RST = true;
//_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
_trigRetryConnect.RST = true;
base.Reset();
}
public override bool Home(out string reason)
{
return base.Home(out reason);
}
#region Command Functions
public void PerformRawCommand(string command, string comandArgument)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerRawCommandHandler(this, command, comandArgument));
}
}
public void PerformRawCommand(string command)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerRawCommandHandler(this, command));
}
}
public void Align()
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSimpleActionHandler(this,"ALIGN"));
}
}
public void Rotate(string angle)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSimpleActionHandler(this, "ROTATE",angle));
}
}
public void SevoOn()
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSevoOnOffHandler(this, true));
}
}
public void SevoOff()
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSevoOnOffHandler(this, false));
}
}
public void SetAlignAngle(string angle)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSimpleSetHandler(this, "SWAA", angle));
}
}
public void SetWaferSize(string waferSize)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSimpleSetHandler(this, "SWS", waferSize));
}
}
public void Transfer(XferArgument gotoArg)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerXferHandler(this, JsonConvert.SerializeObject(gotoArg)));
}
}
public void Transfer(object gotoArg)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerXferHandler(this, gotoArg.ToString()));
}
}
public void HomeAligner()
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerSimpleActionHandler(this, "ALIGNER HOME/SCAN/ALGN"));
}
}
public void Pick(PickPlaceArgument pickArg)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerPickHandler(this, JsonConvert.SerializeObject(pickArg)));
}
}
public void Pick(object gotoArg)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerPickHandler(this, gotoArg.ToString()));
}
}
public void Place(PickPlaceArgument placeArg)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerPlaceHandler(this, JsonConvert.SerializeObject(placeArg)));
}
}
public void Place(object placeArg)
{
lock (_locker)
{
_lstHandler.AddLast(new SiasunAlignerPlaceHandler(this, placeArg.ToString()));
}
}
internal void NoteActionCompleted(string command)
{
if(command == "ALIGN")
{
AlignCompleted = true;
}
else if(command == "ROTATE")
{
RotatedCompleted = true;
}
else if(command == "XFER")
{
XferCompleted = true;
}
else if(command == "ALIGNER HOME/SCAN/ALGN")
{
HomeCompleted = true;
}
}
internal void NoteQueryResult(string command, string parameter, string queryResult)
{
if (command == "HELLO")
{
if(queryResult == "AG")
{
CommunicationIsOK = true;
}
else
{
CommunicationIsOK = false;
}
}
else if (command == "RWAA")
{
var resultArray = queryResult.Split(',');
if(resultArray.Count() == 1)
{
AlignedAngle = double.Parse(queryResult);
}
}
else if (command == "RWS")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 1)
{
WaferSize = double.Parse(queryResult);
}
}
else if (command == "RBIASXY")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 2)
{
BaisX = double.Parse(queryResult.Split(',')[0]);
BaisY = double.Parse(queryResult.Split(',')[1]);
}
}
else if (command == "RBIASRT")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 2)
{
BaisR = double.Parse(queryResult.Split(',')[0]);
BaisT = double.Parse(queryResult.Split(',')[1]);
}
}
else if (command == "RNOTCH")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 1)
{
Notch = double.Parse(queryResult);
}
}
else if (command == "REER")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 1)
{
Error = "_ERR " + queryResult;
}
}
else if (command == "RWK")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 1)
{
WafeOnOff = queryResult == "1";
}
}
else if (command == "RAR")
{
var resultArray = queryResult.Split(',');
if (resultArray.Count() == 1)
{
IsReady = queryResult == "1";
}
}
}
internal void NoteSetCompleted(string command, string parameter)
{
if(command == "SWAA")
{
AlignAngleSet = double.Parse(parameter);
}
else if(command == "SWS")
{
WaferSizeSet = double.Parse(parameter);
}
}
public void MonitorRawCommand(bool isSelected, string command, string comandArgument)
{
lock (_locker)
{
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(SiasunAlignerRawCommandHandler) && ((SiasunAlignerHandler)handler)._command == command);
if (isSelected)
{
if (!existHandlers.Any())
_lstMonitorHandler.AddFirst(new SiasunAlignerRawCommandHandler(this, command, comandArgument));
}
else
{
if (existHandlers.Any())
{
_lstMonitorHandler.Remove(existHandlers.First());
}
}
}
}
public void MonitorRawCommand(bool isSelected, string command)
{
lock (_locker)
{
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(SiasunAlignerRawCommandHandler) && ((SiasunAlignerHandler)handler)._command == command);
if (isSelected)
{
if (!existHandlers.Any())
_lstMonitorHandler.AddFirst(new SiasunAlignerRawCommandHandler(this, command));
}
else
{
if (existHandlers.Any())
{
_lstMonitorHandler.Remove(existHandlers.First());
}
}
}
}
public void RequestAlignAngle(bool isSelected)
{
SimpleRequest(isSelected, "RWAA");
}
public void RequestWaferSize(bool isSelected)
{
SimpleRequest(isSelected, "RWS");
}
public void RequestBiasXY(bool isSelected)
{
SimpleRequest(isSelected, "RBIASXY");
}
public void RequestBiasRT(bool isSelected)
{
SimpleRequest(isSelected, "RBIASRT");
}
public void RequestNotchAngle(bool isSelected)
{
SimpleRequest(isSelected, "RNOTCH");
}
public void RequestErrorCode(bool isSelected)
{
SimpleRequest(isSelected, "REER");
}
public void RequestHello(bool isSelected)
{
SimpleRequest(isSelected, "HELLO");
}
public void RequestWaferOnOff(bool isSelected)
{
SimpleRequest(isSelected, "RWK");
}
public void RequestReady(bool isSelected)
{
SimpleRequest(isSelected, "RAR");
}
private void SimpleRequest(bool isSelected, string command)
{
lock (_locker)
{
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(SiasunAlignerSimpleQueryHandler) && ((SiasunAlignerSimpleQueryHandler)handler)._command == command);
if (isSelected)
{
if (!existHandlers.Any())
_lstMonitorHandler.AddFirst(new SiasunAlignerSimpleQueryHandler(this, command));
}
else
{
if (existHandlers.Any())
{
_lstMonitorHandler.Remove(existHandlers.First());
}
}
}
}
#endregion
#region Properties
public string Error { get; private set; }
public bool SevoOnOff { get; private set; }
public bool AlignCompleted { get; private set; }
public bool RotatedCompleted { get; private set; }
public double AlignAngleSet { get; private set; }
public double WaferSizeSet { get; private set; }
public double WaferSize { get; private set; }
public bool XferCompleted { get; private set; }
public bool HomeCompleted { get; private set; }
public bool CommunicationIsOK { get; private set; }
public double AlignedAngle { get; private set; }
public double BaisX { get; private set; }
public double BaisY { get; private set; }
public double BaisR { get; private set; }
public double BaisT { get; private set; }
public double Notch { get; private set; }
public bool WafeOnOff { get; private set; }
public bool IsReady { get; private set; }
public string LastPickInfo { get; private set; }
public string LastPlaceInfo { get; private set; }
#endregion
#region Note Functions
private R_TRIG _trigWarningMessage = new R_TRIG();
public void NoteError(string reason)
{
CommunicationIsOK = false;
if (reason != null)
{
_trigWarningMessage.CLK = true;
if (_trigWarningMessage.Q)
{
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
}
Error = reason;
}
else
{
Error = null;
}
}
internal void NoteLastPickInfo(string sendText)
{
LastPickInfo = sendText;
}
internal void NoteLastPlaceInfo(string sendText)
{
LastPlaceInfo = sendText;
}
internal void NoteSevoOnOff(bool isOn)
{
SevoOnOff = isOn;
}
internal void NoteRawCommandInfo(string command, string data)
{
var curIOResponse = IOResponseList.Find(res => res.SourceCommandName == command);
if (curIOResponse != null)
{
IOResponseList.Remove(curIOResponse);
}
IOResponseList.Add(new IOResponse() { SourceCommand = command, ResonseContent = data, ResonseRecievedTime = DateTime.Now });
}
#endregion
}
public class XferArgument
{
public string Arm { get; set; }
public int FromStation { get; set; }
public int FromSlot { get; set; }
public int ToStation { get; set; }
public int ToSlot { get; set; }
public string AlignCommand { get; set; }
}
public class PickPlaceArgument
{
/// <summary>
///
/// </summary>
public int Station { get; set; }
/// <summary>
///
/// </summary>
public int Slot { get; set; }
/// <summary>
///
/// </summary>
public string Arm { get; set; }
/// <summary>
///
/// </summary>
public int Step { get; set; }
/// <summary>
///
/// </summary>
public string Offset { get; set; }
public string AlignCommand { get; set; }
}
}
@@ -0,0 +1,103 @@
using System.IO.Ports;
using System.Linq;
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.SiasunAligner
{
public class SiasunAlignerMessage : AsciiMessage
{
public string Data { get; set; }
public string ErrorText { get; set; }
}
public class SiasunAlignerConnection : SerialPortConnectionBase
{
private static char _endLine = (char)3;
//private bool _isAckMode = false;//should read from config file
private string _cachedBuffer = string.Empty;
public SiasunAlignerConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
: base(portName, baudRate, dataBits, parity, stopBits, _endLine.ToString(), true)
{
}
public override bool SendMessage(byte[] message)
{
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(string rawText)
{
SiasunAlignerMessage msg = new SiasunAlignerMessage();
msg.RawMessage = rawText;
if (rawText.Length <= 0)
{
LOG.Error($"empty response,");
msg.IsFormatError = true;
return msg;
}
if (rawText.Length <= 4)
{
LOG.Error($"too short response,");
msg.IsFormatError = true;
return msg;
}
rawText = rawText.Substring(1, rawText.Length - 2);//remove start char and end char
if(!CheckSum(rawText))
{
LOG.Error($"check sum failed,");
msg.IsFormatError = true;
return msg;
}
rawText = rawText.Substring(2, rawText.Length - 4);// remove length and sum
if (rawText.Contains("_ERR"))
{
msg.IsError = true;
var rewTextArray = rawText.Split(' ');
msg.Data = rewTextArray[1];
}
else if (rawText == "_RDY")
{
msg.Data = rawText;
msg.IsResponse = true;
msg.IsAck = true;
msg.IsComplete = true;
}
else
{
msg.Data = rawText;
msg.IsResponse = true;
msg.IsAck = true;
msg.IsComplete = true;
}
return msg;
}
private bool CheckSum(string responseContent)
{
string responseSum = responseContent.Substring(responseContent.Length - 2);
string checkContent = responseContent.Substring(0, responseContent.Length - 2);
var charArray = checkContent.ToArray();
int sum = charArray.Sum(chr => (int)chr);
string sSum = sum.ToString("X");
if (sSum.Length < 2)
sSum = "0" + sSum;
else
sSum = sSum.Substring(sSum.Length - 2);
return responseSum == sSum;
}
}
}
@@ -0,0 +1,351 @@
using MECF.Framework.Common.Communications;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.SiasunAligner
{
public abstract class SiasunAlignerHandler : HandlerBase
{
public SiasunAligner Device { get; }
public string _command;
protected string _parameter;
protected SiasunAlignerHandler(SiasunAligner device, string command, string parameter = null)
: base(BuildMessage(command, parameter))
{
Device = device;
_command = command;
_parameter = parameter;
Name = command;
}
private static char _startLine = (char)1;
private static char _endLine = (char)3;
private static string BuildMessage( string command, string parameter)
{
command = "ALIG " + command;
string commandContent = parameter == null ? $"{command}" : $"{command} {parameter}";
string sLength = commandContent.Length.ToString("D2");
var charArray = (sLength + commandContent).ToArray();
int sum = charArray.Sum(chr => (int)chr);
string sSum = sum.ToString("X");
if (sSum.Length < 2)
return _startLine + sLength + commandContent + "0" + sSum + _endLine.ToString();
else
return _startLine + sLength + commandContent + sSum.Substring(sSum.Length - 2) + _endLine.ToString();
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
SiasunAlignerMessage response = msg as SiasunAlignerMessage;
ResponseMessage = msg;
if (response.IsAck)
{
SetState(EnumHandlerState.Acked);
}
if (response.IsResponse)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
return true;
}
transactionComplete = false;
return false;
}
}
public class SiasunAlignerRawCommandHandler : SiasunAlignerHandler
{
public SiasunAlignerRawCommandHandler(SiasunAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as SiasunAlignerMessage;
Device.NoteRawCommandInfo(_command, result.RawMessage);
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerXferHandler : SiasunAlignerHandler
{
public SiasunAlignerXferHandler(SiasunAligner device, string jsonParameter)
: base(device, "XFER", BuildCommandParameter(jsonParameter))
{
}
static string BuildCommandParameter(string jsonParameter)
{
JObject jsonObject = JObject.Parse(jsonParameter);
StringBuilder paraBuilder = new StringBuilder();
foreach (var item in jsonObject)
{
if (item.Key.Contains("Slot") || item.Key == "Arm")
paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
else if(item.Value!=null && item.Value.ToString().Length > 0)
paraBuilder.Append(" " + item.Value);
}
return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.NoteActionCompleted(_command);
}
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerPickHandler : SiasunAlignerHandler
{
public SiasunAlignerPickHandler(SiasunAligner 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 SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.NoteLastPickInfo(SendText);
}
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerPlaceHandler : SiasunAlignerHandler
{
public SiasunAlignerPlaceHandler(SiasunAligner 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 SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.NoteLastPlaceInfo(SendText);
}
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerSimpleActionHandler : SiasunAlignerHandler
{
public SiasunAlignerSimpleActionHandler(SiasunAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.NoteActionCompleted(_command);
}
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerSimpleSetHandler : SiasunAlignerHandler
{
public SiasunAlignerSimpleSetHandler(SiasunAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.NoteSetCompleted(_command,_parameter);
}
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerSevoOnOffHandler : SiasunAlignerHandler
{
public SiasunAlignerSevoOnOffHandler(SiasunAligner device, bool isOn)
: base(device, isOn ? "SVON" : "SVOFF")
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
Device.NoteError(null);
Device.NoteSevoOnOff(_command == "SVON");
}
ResponseMessage = msg;
handled = true;
return true;
}
}
public class SiasunAlignerSimpleQueryHandler : SiasunAlignerHandler
{
public SiasunAlignerSimpleQueryHandler(SiasunAligner device, string command, string parameter = null)
: base(device, command, parameter)
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as SiasunAlignerMessage;
if (result.IsError)
{
Device.NoteError(result.Data);
}
else
{
var resultArray = result.Data.Split(' ');
if(resultArray.Count() >= 2 && resultArray[0] == _command)
{
Device.NoteError(null);
Device.NoteQueryResult(_command, _parameter, string.Join(",", resultArray, 1, resultArray.Count()-1));
}
else
{
Device.NoteError($"Invalid Response '{result.Data}' for command: {_command}");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
}
@@ -0,0 +1,854 @@
using System;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.DataCenter;
using Aitex.Core.Util;
using Aitex.Sorter.Common;
using Aitex.Core.RT.Device;
using MECF.Framework.Common.Communications;
using MECF.Framework.Common.SubstrateTrackings;
using System.Collections.Generic;
using Aitex.Core.RT.SCCore;
using System.IO.Ports;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TazmoAligners
{
public enum TazmoState1
{
StandbyNoWafer = 0x100,
StandbyWithWafer,
OperationEndNormaly, // Normal
Operating,
Calibrationing = 0x106,
Pause,
Interlock,
Initialization,
StandbyDueToUninitialized = 0x110,
WaferLostDuringAlignment,
AlignmentOperationTimeOver,
CannotDeterminTheWaferSize = 0x114,
WaferNotSetToAligner = 0x115,
OverTheDetectinRangeOfTheLineSensor = 0x117,
SamplingOperationNotProcessed,
CannotExecuteTheAlignment,
CannotPerformTheInitialization,
ReceivingErrorOfDIO,
StepOutError,
CommandExecuteError,
InputValueOfLineSensorAbnormal,
CannotPerformAlignerInitializationStoppedByInterlock,
}
public enum TazmoStatus
{
PossibleToOperate =0,
NeedInit,
Abnormal = 9,
}
public enum LiftStatus
{
Up =0,
Down,
Busy,
Unknown =9,
}
public enum NotchDetectionStatus
{
NotComplete=0,
Complete =1,
Error =9,
}
public class TazmoAligner : BaseDevice, IDevice
{
public enum AlignerType
{
Mechnical =0,
Vaccum,
}
public string Address
{
get
{
return "";
}
}
public virtual bool IsConnected
{
get { return true; }
}
public virtual bool Disconnect()
{
return true;
}
public virtual bool Connect()
{
return true;
}
public const string delimiter = "\r";
public int LastErrorCode { get; set; }
public int Status { get; set; }
public int ErrorCode { get; set; }
public int ElapseTime { get; set; }
public int Notch { get; set; }
public bool Initalized { get; set; }
private AlignerType _tazmotype;
public AlignerType TazmoType { get => _tazmotype; }
public bool Communication
{
get
{
return !_commErr;
}
}
public virtual bool Error
{
get
{
return (int)TaAlignerStatus1 >= 0x111 || _commErr;
}
}
public bool Busy { get { return _connection.IsBusy || _lstHandler.Count != 0; } }
public DeviceState State
{
get
{
if (!Initalized)
{
return DeviceState.Unknown;
}
if (Error)
{
return DeviceState.Error;
}
if (Busy)
return DeviceState.Busy;
return DeviceState.Idle;
}
}
public TazmoState1 TaAlignerStatus1
{
get;set;
}
public TazmoStatus TaAlignerStatus2Status
{
get;set;
}
public LiftStatus TaAlignerStatus2Lift
{
get;set;
}
public NotchDetectionStatus TaAlignerStatus2Notch
{
get;set;
}
public int TaAlignerStatus2DeviceStatus
{ get; set; }
public int TaAlignerStatus2ErrorCode
{
get;set;
}
public int TaAlignerStatus2LastErrorCode
{
get;set;
}
public bool TaExecuteSuccss
{
get;set;
}
public virtual bool WaferOnAligner
{
get
{
return true;
}
}
//private int _deviceAddress;
public TazmoAlignerConnection Connection
{
get => _connection;
}
private TazmoAlignerConnection _connection;
//private int _presetNumber;
private R_TRIG _trigError = new R_TRIG();
private R_TRIG _trigWarningMessage = new R_TRIG();
private R_TRIG _trigCommunicationError = new R_TRIG();
private R_TRIG _trigRetryConnect = new R_TRIG();
private PeriodicJob _thread;
private static Object _locker = new Object();
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
private bool _enableLog = true;
private bool _commErr = false;
private int _defaultChuckPosition;
//private bool _exceuteErr = false;
//private string _addr;
private DeviceTimer _timerQuery = new DeviceTimer();
private string AlarmMechanicalAlignmentError = "MechanicalAlignmentError";
public TazmoAligner(string module, string name)
: base()
{
Name = name;
WaferManager.Instance.SubscribeLocation(name, 1);
}
public bool Initialize()
{
string portName = SC.GetStringValue($"{Name}.Address");
int bautRate = SC.GetValue<int>($"{Name}.BaudRate");
int dataBits = SC.GetValue<int>($"{Name}.DataBits");
Enum.TryParse(SC.GetStringValue($"{Name}.Parity"), out Parity parity);
Enum.TryParse(SC.GetStringValue($"{Name}.StopBits"), out StopBits stopBits);
//_deviceAddress = SC.GetValue<int>($"{Name}.DeviceAddress");
_enableLog = SC.GetValue<bool>($"{Name}.EnableLogMessage");
_tazmotype = (AlignerType)(SC.ContainsItem($"{Name}.AlignerType") ? SC.GetValue<int>($"{Name}.AlignerType") : 0);
_defaultChuckPosition = SC.ContainsItem("Aligner.DefaultChuckPosition") ?
SC.GetValue<int>("Aligner.DefaultChuckPosition") : 1;
_connection = new TazmoAlignerConnection(portName, bautRate, dataBits, parity, stopBits);
_connection.EnableLog(_enableLog);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
DEVICE.Register(String.Format("{0}.{1}", Name, "Init"), (out string reason, int time, object[] param) =>
{
bool ret = Init(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerInit"), (out string reason, int time, object[] param) =>
{
bool ret = Init(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Home"), (out string reason, int time, object[] param) =>
{
bool ret = Home(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerHome"), (out string reason, int time, object[] param) =>
{
bool ret = Home(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Reset"), (out string reason, int time, object[] param) =>
{
bool ret = Clear(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerReset"), (out string reason, int time, object[] param) =>
{
bool ret = Clear(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Reset Error");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Grip"), (out string reason, int time, object[] param) =>
{
bool ret = Grip(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Hold Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerGrip"), (out string reason, int time, object[] param) =>
{
bool ret = Grip(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Hold Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Release"), (out string reason, int time, object[] param) =>
{
bool ret = Release(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Release Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerRelease"), (out string reason, int time, object[] param) =>
{
bool ret = Release(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Release Wafer");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "LiftUp"), (out string reason, int time, object[] param) =>
{
bool ret = LiftUp(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Up");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerLiftUp"), (out string reason, int time, object[] param) =>
{
bool ret = LiftUp(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Up");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "LiftDown"), (out string reason, int time, object[] param) =>
{
bool ret = LiftDown(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Down");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerLiftDown"), (out string reason, int time, object[] param) =>
{
bool ret = LiftDown(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Lifter Down");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Stop"), (out string reason, int time, object[] param) =>
{
bool ret = Stop(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Stop Align");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerStop"), (out string reason, int time, object[] param) =>
{
bool ret = Stop(out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "Stop Align");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "Align"), (out string reason, int time, object[] param) =>
{
double angle = double.Parse((string)param[0]);
bool ret = Align(angle, out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "PreAlign");
return true;
}
return false;
});
DEVICE.Register(String.Format("{0}.{1}", Name, "AlignerAlign"), (out string reason, int time, object[] param) =>
{
double angle = double.Parse((string)param[0]);
bool ret = Align(angle, out reason);
if (ret)
{
reason = string.Format("{0} {1}", Name, "PreAlign");
return true;
}
return false;
});
DATA.Subscribe($"{Name}.State", () => State);
DATA.Subscribe($"{Name}.AlignerState", () => State.ToString());
DATA.Subscribe($"{Name}.Busy", () => Busy);
DATA.Subscribe($"{Name}.ErrorCode", () => ErrorCode);
DATA.Subscribe($"{Name}.Error", () => Error);
DATA.Subscribe($"{Name}.ElapseTime", () => ElapseTime);
DATA.Subscribe($"{Name}.Notch", () => Notch);
DATA.Subscribe($"{Name}.WaferOnAligner", () => WaferOnAligner);
// string str = string.Empty;
EV.Subscribe(new EventItem(0, "Event", AlarmMechanicalAlignmentError, "Aligner error", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
// _timerQuery.Start(_queryPeriod);
return true;
}
private bool OnTimer()
{
try
{
_connection.MonitorTimeout();
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{Name}.Address"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
}
return true;
}
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0)
{
//_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
//_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
if (handler != null) _connection.Execute(handler);
_lstHandler.RemoveFirst();
}
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
public void Terminate()
{
}
public void Monitor()
{
try
{
_connection.EnableLog(_enableLog);
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
}
public void Reset()
{
_trigError.RST = true;
_trigWarningMessage.RST = true;
_connection.SetCommunicationError(false, "");
_trigCommunicationError.RST = true;
_enableLog = SC.GetValue<bool>($"{Name}.EnableLogMessage");
_trigRetryConnect.RST = true;
}
internal void NoteError(string reason)
{
_trigWarningMessage.CLK = true;
if (_trigWarningMessage.Q)
{
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
}
}
#region Command
public virtual bool ResetCPU(out string reason)
{
lock(_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.CPUresetMotion,null));
}
reason = "";
return true;
}
public virtual bool Init(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.InitializeMotion, null));
if (_tazmotype == AlignerType.Vaccum)
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MoveTheAlignerChuckToSpecifiedPosition, _defaultChuckPosition.ToString("0")));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if(_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual void Pause()
{
lock (_locker)
{
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.PauseMotion, null));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
}
public virtual void CancelPause()
{
lock (_locker)
{
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.CancelthepauseMotion, null));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
}
public virtual bool Home(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MovealignertohomepositionMotion, null));
if (_tazmotype == AlignerType.Mechnical)
{
string para1 = $"A," + "0000";
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.SetalignmentangleetcSet, para1));
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MovetopickpositionMotion, "A"));
}
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool HomeForSwap(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MovealignertohomepositionMotion, null));
}
reason = "";
return true;
}
public virtual void MoveChuck(int position)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MoveTheAlignerChuckToSpecifiedPosition, position.ToString("0")));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
}
public virtual bool Clear(out string reason)
{
lock (_locker)
{
_lstHandler.Clear();
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.CancelerrorSet, null));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool Grip(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.ClosealignerchuckMotion, null));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool Release(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.OpenalignerchuckMotion, null));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool LiftUp(out string reason)
{
lock (_locker)
{
string para1 = $"A," +"0000";
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.SetalignmentangleetcSet, para1));
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MovetopickpositionMotion, "A"));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool LiftDown(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.MovealignertohomepositionMotion, ""));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool MoveToReady(out string reason)
{
reason = "";
return true;
}
public virtual bool Stop(out string reason)
{
reason = string.Empty;
reason = "";
return true;
}
public virtual bool Align(double angle, out string reason)
{
lock (_locker)
{
int anglevalue = (int)angle * 10;
string para1 = $"1," + anglevalue.ToString("0000") + ",000";
if (_tazmotype == AlignerType.Mechnical)
{
anglevalue = (int)angle * 100;
para1 = $"1," + anglevalue.ToString("00000");
}
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.SetalignmentangleetcSet, para1));
_lstHandler.AddLast(new TwinTransactionHandler(this, TazmoCommand.SeriesofalignmentMotion, "1,5"));
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
public virtual bool QueryStatus(out string reason)
{
lock (_locker)
{
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
if (_tazmotype == AlignerType.Mechnical)
_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
}
reason = "";
return true;
}
#endregion
}
}
@@ -0,0 +1,94 @@
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TazmoAligners
{
public class TazmoAlignerMessage:AsciiMessage
{
public string Data { get; set; }
}
public class TazmoAlignerMessageBIN:BinaryMessage
{
public byte[] CMD { get; set; }
public byte[] Data { get; set; }
}
public class TazmoAlignerConnection: SerialPortConnectionBase
{
private List<byte> _lstCacheBuffer = new List<byte>();
public TazmoAlignerConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
: base(portName, baudRate, dataBits, parity, stopBits, "\r", false)
{
}
public override bool SendMessage(byte[] message)
{
LOG.Write($"{Address} send message:{Encoding.ASCII.GetString(message)}");
_lstCacheBuffer.Clear();
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(byte[] rawBuffer)
{
_lstCacheBuffer.AddRange(rawBuffer);
byte[] temps = _lstCacheBuffer.ToArray();
TazmoAlignerMessageBIN msg = new TazmoAlignerMessageBIN();
msg.RawMessage = _lstCacheBuffer.ToArray();
if (temps[0] ==0x6)
{
msg.IsAck = true;
_lstCacheBuffer.RemoveRange(0,1);
}
if (temps.Length == 1 && temps[0] == 0x15 )
{
msg.IsNak = true;
_lstCacheBuffer.Clear();
}
if (temps.Length == 1 && temps[0] == 0x11)
{
msg.IsBusy = true;
_lstCacheBuffer.Clear();
}
if (temps.Length >= 3 && (Encoding.Default.GetString(temps.Take(3).ToArray()) == "ERR") && temps.LastOrDefault() == 0xD)
{
int index1 = Array.IndexOf(temps, (byte)44);
int index2 = Array.IndexOf(temps, (byte)0xD);
msg.Data = temps.Skip(index1 + 1).Take(index2 - index1 - 1).ToArray();
msg.IsError = true;
_lstCacheBuffer.Clear();
}
if(temps.Length >3 && temps.LastOrDefault() == 0xD && Encoding.Default.GetString(temps.Take(3).ToArray()) != "ERR")
{
_lstCacheBuffer.Clear();
msg.IsResponse = true;
if(Array.IndexOf(temps,(byte)44)!=-1) // to ,
{
msg.CMD = temps.Take(Array.IndexOf(temps, (byte)44)).ToArray();
int index1 = Array.IndexOf(temps, (byte)44);
int index2 = Array.IndexOf(temps, (byte)0xD);
msg.Data = temps.Skip(index1 + 1).Take(index2 - index1 - 1).ToArray();
}
else
{
msg.CMD = temps.Take(temps.Length - 1).ToArray();
}
}
LOG.Write($"{Address} received message:{Encoding.ASCII.GetString(temps)}");
return msg;
}
}
}
@@ -0,0 +1,417 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TazmoAligners
{
public static class TazmoCommand
{
public static readonly string CPUresetMotion = "CPI";
public static readonly string InitializeMotion = "RST";
public static readonly string PauseMotion = "PAU";
public static readonly string CancelthepauseMotion = "CNT";
public static readonly string MovealignertohomepositionMotion = "HOM";
public static readonly string MovetopickpositionMotion = "PRP";
public static readonly string SeriesofalignmentMotion = "ALG";
public static readonly string Alignmentpartialmovement1Motion = "SRH";
public static readonly string Alignmentpartialmovement2Motion = "OCH";
public static readonly string Alignmentpartialmovement1_2Motion = "ALN";
public static readonly string Alignmentpartialmovement3, movetodeliverypositionMotion = "ULD";
public static readonly string Readrobotoffsetamountafteralignmentunit1_100Status = "POS";
public static readonly string Readrobotoffsetamountafteralignmentunit1_1000Status = "RPS";
public static readonly string ClearrobotoffsetamountafteralignmentSet = "CPS";
public static readonly string RequeststatusStatus = "STS";
public static readonly string Requeststatus2Status = "STU";
public static readonly string CheckwaferpresenceMotion = "WCH";
public static readonly string ReadwafertypeStatus = "RWF";
public static readonly string CancelerrorSet = "ERF";
public static readonly string ReaderrorlogStatus = "RER";
public static readonly string Readerrorlog2Status = "DER";
public static readonly string ClearerrorlogSet = "CER";
public static readonly string SetdefaultvalueMotion = "DEF";
public static readonly string SetalignmentoffsetvalueSet = "REV";
public static readonly string ReadalignmentoffsetvalueStatus = "RRE";
public static readonly string SetalignmentangleetcSet = "DWL";
public static readonly string ReadalignmentangleetcStatus = "UPL";
public static readonly string ReadsoftwareproductNoStatus = "PNO";
public static readonly string ReadmodelnameStatus = "RMN";
public static readonly string ReadsoftwareversionStatus = "VER";
public static readonly string Readalignmenttype_chuckpositionStatus = "TYP";
public static readonly string ReadmotorcontrolIC_readregisterStatus = "RRG";
public static readonly string ReadalignmentcountStatus = "ADM";
public static readonly string ReadIOsignalStatus = "RIO";
public static readonly string TurnwaferonetimeatslowspeedMotion = "TRN";
public static readonly string ClosealignerchuckMotion = "VVN";
public static readonly string OpenalignerchuckMotion = "VVF";
public static readonly string AscenddeliverychuckMotion = "ZUP";
public static readonly string DescenddeliverychuckMotion = "ZDN";
public static readonly string Movetodeliveryposition, withoutlinesensorcheckMotion = "PRR";
public static readonly string Movetohomeposition_withoutlinesensorcheckMotion = "HOE";
public static readonly string TurnwaferforthespecifiednumberoftimeatthespecifiedspeedMotion = "TUR";
public static readonly string MoveTheAlignerChuckToSpecifiedPosition = "NYG";
/// <summary>
/// A
/// </summary>
}
public class TazmoAlignerHandler : HandlerBase
{
public TazmoAligner Device { get; set; }
public string Command;
protected TazmoAlignerHandler(TazmoAligner device, string command,string para) : base(BuildMesage(command,para))
{
Device = device;
Command = command;
Name = command;
}
public static byte[] BuildMesage(string data, string para)
{
List<byte> ret = new List<byte>();
foreach(char c in data)
{
ret.Add((byte)c);
}
if (!string.IsNullOrEmpty(para))
{
ret.Add((byte)0x2C);
foreach (char b in para) ret.Add((byte)b);
}
ret.Add(0x0D);
return ret.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
TazmoAlignerMessageBIN response = msg as TazmoAlignerMessageBIN;
ResponseMessage = msg;
transactionComplete = false;
if (response.IsAck)
{
SetState(EnumHandlerState.Acked);
transactionComplete = true;
}
if(response.IsBusy)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsComplete)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsError)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsNak)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsEvent)
{
SendAck();
if (response.CMD == Encoding.ASCII.GetBytes(Command))
{
}
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsResponse)
{
SendAck();
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
return true;
}
public void SendAck()
{
Device.Connection.SendMessage(new byte[] { 0x06 });
}
public virtual void ParseStatus1(byte[] data)
{
try
{
if (data.Length < 3) return;
int state1code = Convert.ToInt32(Encoding.ASCII.GetString(data), 16);
Device.TaAlignerStatus1 = (TazmoState1)state1code;
if (state1code >= 0x111) EV.PostAlarmLog("Aligner", $"Tazmo Aligner occurred error:{((TazmoState1)state1code).ToString()}");
}
catch(Exception ex)
{
LOG.Write("Parse Tazmo Status1 exception:" +ex);
}
}
public virtual void ParseStatus2(byte[] data)
{
if (data == null || data.Length < 10) return;
try
{
Device.TaAlignerStatus2Status = (TazmoStatus)Convert.ToInt32(Encoding.ASCII.GetString(new byte[]{ data[0]}));
Device.TaAlignerStatus2Lift = (LiftStatus)Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[2] }));
Device.TaAlignerStatus2Notch = (NotchDetectionStatus)Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[3] }));
Device.TaAlignerStatus2DeviceStatus = Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[7] }),16);
Device.TaAlignerStatus2ErrorCode = Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[8] }),16);
Device.TaAlignerStatus2LastErrorCode = data[9];
}
catch (Exception ex)
{
LOG.Write($"Parse status2 exception:{ex}");
}
}
public virtual bool PaserData(byte[] data)
{
return true;
}
}
public class SingleTransactionHandler : TazmoAlignerHandler
{
public SingleTransactionHandler(TazmoAligner device, string command,string para) : base(device, BuildData(command),para)
{
}
private static string BuildData(string command)
{
return command;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
TazmoAlignerMessageBIN response = msg as TazmoAlignerMessageBIN;
ResponseMessage = msg;
Device.TaExecuteSuccss = true;
transactionComplete = false;
if (response.IsAck)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsBusy)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if(response.IsNak)
{
SetState(EnumHandlerState.Completed);
Device.TaExecuteSuccss = false;
transactionComplete = true;
//ParseError(response.Data);
}
if(response.IsError)
{
SetState(EnumHandlerState.Completed);
Device.TaExecuteSuccss = false;
transactionComplete = true;
ParseStatus1(response.Data);
}
if(response.IsResponse)
{
SetState(EnumHandlerState.Completed);
Device.TaExecuteSuccss = true;
transactionComplete = true;
if (Encoding.Default.GetString(response.CMD) == "STS") ParseStatus1(response.Data);
if (Encoding.Default.GetString(response.CMD) == "STU") ParseStatus2(response.Data);
}
return true;
}
}
public class TwinTransactionHandler:TazmoAlignerHandler
{
public TwinTransactionHandler(TazmoAligner device,string command,string para): base(device, BuildData(command),para)
{
}
private static string BuildData(string command)
{
return command;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
TazmoAlignerMessageBIN response = msg as TazmoAlignerMessageBIN;
ResponseMessage = msg;
Device.TaExecuteSuccss = true;
transactionComplete = false;
if (response.IsAck)
{
SetState(EnumHandlerState.Acked);
transactionComplete = false;
}
if (response.IsBusy)
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
}
if (response.IsNak)
{
SetState(EnumHandlerState.Completed);
Device.TaExecuteSuccss = false;
transactionComplete = true;
//ParseError(response.Data);
}
if (response.IsError)
{
SetState(EnumHandlerState.Completed);
Device.TaExecuteSuccss = false;
transactionComplete = true;
ParseStatus1(response.Data);
}
if (response.IsResponse)
{
string command = Encoding.Default.GetString(response.CMD);
if (command == "RST" || command == "HOM")
Device.Initalized = true;
SetState(EnumHandlerState.Completed);
SendAck();
Device.TaExecuteSuccss = true;
transactionComplete = true;
}
return true;
}
}
public class MoveToPickHandler : TazmoAlignerHandler
{
public MoveToPickHandler(TazmoAligner device, string specPos) : base(device, BuildData(specPos),null)
{ }
private static string BuildData(string data)
{
return TazmoCommand.MovetopickpositionMotion + "," + data;
}
}
public class QueryStatus1 : TazmoAlignerHandler
{
public QueryStatus1(TazmoAligner device) : base(device, BuildData(),null)
{ }
private static string BuildData()
{
return TazmoCommand.RequeststatusStatus;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
TazmoAlignerMessageBIN response = msg as TazmoAlignerMessageBIN;
ResponseMessage = msg;
if (response.RawMessage == new byte[] { 0x06 }) //ACK
{
SetState(EnumHandlerState.Completed);
transactionComplete = false; ;
return true;
}
if (response.RawMessage == new byte[] { 0x11 })
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
//Device.Busy = true;
return true;
}
if (response.RawMessage.Length >= 8 && Encoding.ASCII.GetString(response.RawMessage.Take(3).ToArray()) == Command)
{
byte[] data = response.RawMessage.Skip(4).Take(3).ToArray();
ParseStatus1(data);
SetState(EnumHandlerState.Completed);
transactionComplete = true;
//Device.Busy = false;
SendAck();
return true;
}
transactionComplete = false;
return false;
}
}
public class QueryStatus2 : TazmoAlignerHandler
{
public QueryStatus2(TazmoAligner device) : base(device, BuildData(), null)
{ }
private static string BuildData()
{
return TazmoCommand.Requeststatus2Status;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
TazmoAlignerMessageBIN response = msg as TazmoAlignerMessageBIN;
ResponseMessage = msg;
if (response.RawMessage == new byte[] { 0x06 }) //ACK
{
SetState(EnumHandlerState.Completed);
transactionComplete = false; ;
return true;
}
if (response.RawMessage == new byte[] { 0x11 })
{
SetState(EnumHandlerState.Completed);
transactionComplete = true;
//Device.Busy = true;
return true;
}
if(response.RawMessage.Length >= 15 && Encoding.ASCII.GetString(response.RawMessage.Take(3).ToArray()) == Command)
{
byte[] data = response.RawMessage.Skip(4).Take(3).ToArray();
int state1code = Convert.ToInt32(Encoding.ASCII.GetString(data),16);
Device.TaAlignerStatus1 = (TazmoState1)state1code;
SetState(EnumHandlerState.Completed);
transactionComplete = true;
//Device.Busy = false;
SendAck();
return true;
}
transactionComplete = false;
return false;
}
}
}
@@ -0,0 +1,137 @@
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
using System;
using System.Linq;
using System.Text;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.YaskawaAligner
{
public class YaskawaRobotMessage : AsciiMessage
{
public int UNo { get; set; }
public int SeqNo { get; set; }
public string Status { get; set; }
public string Ackcd { get; set; }
public string Command { get; set; }
public string[] Data { get; set; }
public string ErrorCode { get; set; }
public string EvNo { get; set; }
public string EvDate { get; set; }
public string EvData { get; set; }
}
public class YaskawaAlignerConnection : TCPPortConnectionBase
{
private YaskawaAligner _aligner;
public YaskawaAlignerConnection(YaskawaAligner pa, string ipaddress)
: base(ipaddress, "\r", true)
{
_aligner = pa;
}
protected override MessageBase ParseResponse(string rawMessage)
{
YaskawaRobotMessage msg = new YaskawaRobotMessage();
try
{
msg.RawMessage = rawMessage.Replace("\r", "");
string[] msgdata = msg.RawMessage.Split(',');
msg.UNo = Convert.ToInt16(msgdata[1]);
msg.IsAck = false;
msg.IsComplete = false;
msg.IsFormatError = false;
msg.IsEvent = false;
if (msgdata[0] == "$") msg.IsAck = true;
if (msgdata[0] == "!") msg.IsComplete = true;
if (msgdata[0] == "?")
{
msg.IsFormatError = true;
}
if (msgdata[0] == ">" && msgdata[2] == "EVNT")
{
msg.IsEvent = true;
msg.EvNo = msgdata[3];
msg.EvDate = msgdata[4];
msg.EvData = msgdata[5];
return msg;
}
if (_aligner.IsEnableSeqNo)
{
msg.SeqNo = Convert.ToInt16(msgdata[2]);
msg.Status = msgdata[3];
msg.Ackcd = msgdata[4];
msg.Command = msgdata[5];
msg.Data = msgdata.Skip(6).Take(msgdata.Length - 6 - (_aligner.IsEnableCheckSum ? 1 : 0)).ToArray();
}
else
{
msg.Status = msgdata[2];
msg.Ackcd = msgdata[3];
msg.Command = msgdata[4];
msg.Data = msgdata.Skip(6).Take(msgdata.Length - 5 - (_aligner.IsEnableCheckSum ? 1 : 0)).ToArray();
}
_aligner.ParseStatus(msg.Status);
return msg;
}
catch (Exception ex)
{
LOG.Write(ex);
msg.IsFormatError = true;
return msg;
}
}
protected override void OnEventArrived(MessageBase msg)
{
YaskawaRobotMessage evt = msg as YaskawaRobotMessage;
if (evt.EvNo == "100")
{
string errocode = evt.EvData.Substring(1, evt.EvData.Length - 1);
_aligner.NotifyAlarmByErrorCode(errocode);
if (Convert.ToInt32(errocode,16) > 0xF0)
_aligner.OnError($"Robot occurred error:{evt.EvData} on {evt.EvDate}.");
else
EV.PostWarningLog("Robot", $"Robot occurred error:{evt.EvData} on {evt.EvDate}.");
}
if (evt.EvNo == "140")
{
}
}
public void SendAck()
{
if (_aligner.IsEnableSeqNo)
{
_aligner.CurrentSeqNo = _aligner.SeqnoGenerator.create();
_aligner.SeqnoGenerator.release(_aligner.CurrentSeqNo);
}
string commandstr = $",{_aligner.UnitNumber}" + (_aligner.IsEnableSeqNo ? $",{_aligner.CurrentSeqNo:D2}" : "") + ",ACKN";
if (_aligner.IsEnableCheckSum)
{
commandstr += ",";
commandstr = commandstr + Checksum(Encoding.ASCII.GetBytes(commandstr)) + "\r";
}
commandstr = "$" + commandstr;
SendMessage(commandstr);
}
private string Checksum(byte[] bytes)
{
int sum = 0;
foreach (byte code in bytes)
{
sum += code;
}
string hex = String.Format("{0:X2}", sum % 256);
return hex;
}
}
}
@@ -0,0 +1,139 @@
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
using System;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.YaskawaAligner
{
public abstract class YaskawaAlignerHandler : HandlerBase
{
public YaskawaAligner Device { get; }
public string _commandType;
public string _command;
public string _parameter;
private int _seqNO;
public YaskawaAlignerHandler(YaskawaAligner device, string command, string parameter = null)
: base(BuildMessage(command, parameter))
{
Device = device;
_command = command;
_parameter = parameter;
Name = command;
}
protected static string BuildMessage(string command, string parameter)
{
if (string.IsNullOrEmpty(parameter))
return command;
return $"{command},{parameter}";
}
private static string Checksum(byte[] bytes)
{
int sum = 0;
foreach (byte code in bytes)
{
sum += code;
}
string hex = String.Format("{0:X2}", sum % 256);
return hex;
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
YaskawaRobotMessage response = msg as YaskawaRobotMessage;
ResponseMessage = msg;
if (msg.IsError)
{
Device.OnError(response.RawMessage);
transactionComplete = true;
return true;
}
if (msg.IsAck)
{
SetState(EnumHandlerState.Acked);
}
if (response.IsComplete)
{
SetState(EnumHandlerState.Completed);
Device.SenACK();
Device.OnActionDone(null);
transactionComplete = true;
return true;
}
transactionComplete = false;
return false;
}
protected virtual void NoteCommandResult(YaskawaRobotMessage response)
{
}
}
public class YaskawaAlignerReadHandler : YaskawaAlignerHandler
{
public YaskawaAlignerReadHandler(YaskawaAligner aligner, string command, string parameter = null)
: base(aligner, command, parameter)
{
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
LOG.Write($"{aligner.Name} execute read command {command} {temp} in ASCII.");
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
YaskawaRobotMessage response = msg as YaskawaRobotMessage;
if (Device.ParseReadData(_command, response.Data))
{
Device.OnActionDone(null);
transactionComplete = true;
return true;
}
response.IsError = true;
return base.HandleMessage(response, out transactionComplete);
}
}
public class YaskawaAlignerSetHandler : YaskawaAlignerHandler
{
public YaskawaAlignerSetHandler(YaskawaAligner pa, string command, string parameter = null)
: base(pa, command, parameter)
{
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
LOG.Write($"{pa.Name} execute set command {command} {temp} in ASCII.");
}
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
{
YaskawaRobotMessage response = msg as YaskawaRobotMessage;
if (response.IsComplete)
{
Device.OnActionDone(null);
transactionComplete = true;
return true;
}
return base.HandleMessage(response, out transactionComplete);
}
}
public class YaskawaAlignerMotionHandler : YaskawaAlignerHandler
{
public YaskawaAlignerMotionHandler(YaskawaAligner pa, string command, string parameter = null)
: base(pa, command, parameter)
{
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
LOG.Write($"{pa.Name} execute motion command {command} {temp} in ASCII.");
}
}
}