123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- 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
- }
- }
-
|