123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.ModuleLibrary.VceModules;
- using System;
- using System.Collections.Generic;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using Venus_Core;
- namespace Venus_RT.Devices.VCE
- {
- //定义Vce动作
- public enum VceCommand
- {
- Home,
- DoorClose,
- DoorOpen,
- CheckGoto,
- Goto,
- GotoLP,
- Load,
- UnLoad,
- Map,
- ReadMap,
- ClearError,
- }
- public enum VceMessageHead
- {
- Action,
- Read,
- Set,
- Petrify
- }
- public sealed class VceMessage
- {
- private Dictionary<VceCommand, string> _Command2Msg = new Dictionary<VceCommand, string>()
- {
- //Action
- {VceCommand.Home, "HM" },
- {VceCommand.Load, "LOAD" },
- {VceCommand.UnLoad, "UNLOAD"},
- {VceCommand.Map, "MP" },
- {VceCommand.CheckGoto, "GC" },
- {VceCommand.Goto, "GO" },
- {VceCommand.GotoLP, "LP" },
- {VceCommand.DoorOpen, "DO" },
- {VceCommand.DoorClose, "DC" },
- //Read
- {VceCommand.ReadMap, "MI" },
- //Set
- {VceCommand.ClearError, "ER" },
- };
- private Dictionary<VceMessageHead, string> _Type2Head = new Dictionary<VceMessageHead, string>()
- {
- {VceMessageHead.Action, "A"},
- {VceMessageHead.Read, "R"},
- {VceMessageHead.Set, "S"},
- {VceMessageHead.Petrify, "P"},
- };
- public VceMessageHead Head { get; set; }
- public VceCommand Command { get; set; }
- public string Param { get; set; }
- public string toString()
- {
- if (string.IsNullOrEmpty(Param))//含尾参
- return $"00,{_Type2Head[Head]},{_Command2Msg[Command]}";
- else//不含尾参 目前只允许一个
- return $"00,{_Type2Head[Head]},{_Command2Msg[Command]},{Param}";
- }
- }
- /// <summary>
- /// 泓浒Vce驱动 下发指令等
- /// </summary>
- public class HongHuVce : VceModuleBase
- {
- #region 私有变量
- private AsyncSerialPort _serialport;
- private string _portname;
- private string _newline = "\r";//终止符 0D
- private object _locker = new object();
- private bool _IsAsciiMode;
- private LinkedList<string> _lstAsciiMsgs = new LinkedList<string>();
- private PeriodicJob _thread;
- private Regex _match_ReadMsg = new Regex(@"\d\d,X,.*");
- private Regex _matchErrorCode = new Regex(@"(?<=_BKGERR )(.*)");
- private ModuleName _moduleName;
- private RState _status;
- private string _currentMsg;
- private VceMessage _currentVceMessage;
- private bool _HasReceiveMsg;
- //待补充
- private Dictionary<string, string> _ErrorCode2Reason = new Dictionary<string, string>()
- {
- {"A1","Action Timeout" },
- {"A3","Hardware (CAN or VCN) or configuration failed" },
- {"A4","Open Door Prevented Motion" },
- {"A5","Platform Action Time-out" },
- {"A6","Door Action Timeout" },
- {"A7","由于动作连锁导致的异常" },
- {"A8","Wafer Slideout" },
- {"A9","Door safety LED is blocked" },
- {"A11","No cassette present" },
- {"A12","Cassette present prior PICK" },
- {"A13","Cassette NOT present during PICK" },
- {"A14","Cassette NOT present prior PLACE" },
- {"A15","Cassette present after PLACE" },
- {"A16","Cassette Present on VCE platform (Servo Arm)" },
- {"A17","No new cassette at station after Load" },
- {"A18","Proximity sensor blocked but Cassette A not present" },
- {"A19","Cassette present at station A (Fixed Buffer)" },
- {"A20","Proximity sensor A is blocked (Fixed Buffer)" },
- {"A21","Cassette NOT at station A" },
- {"A34","Door Clamped sensor is not ON after clamp (only VCE4!)" },
- {"A36","Door Not Covered (sensor)" },
- {"C0","Illegal Slot Number" },
- {"C1","设备收到非法的操作指令" },
- {"C2","Illegal pitch value (too big)" },
- {"C3","Illegal Cassette type offset" },
- {"C4","Illegal number of Slots" },
- {"C5","Illegal Partial step size" },
- {"C7","Illegal Find Bias" },
- {"C8","Unknown Configuration" },
- {"C9","Bad command: command cannot be executed with current HW configuration" },
- {"C10","VCE is busy" },
- {"C12","Bad Fixture Thickness" },
- {"C13","Command is NOT executable (file's operation exception)" },
- {"C19","VCEConfig.xml is corrupted" },
- {"C20","VCEDefaultSettting.xml is corrupted" },
- {"CAN1","CAN Error,Replace the board (MCC2B or MCC-GEN5 or MCC-GEN5 EN)" },
- {"CAN2","CAN Abort,Replace the board (MCC2B or MCC-GEN5 or MCC-GEN5 EN)" },
- {"CAN3","CAN Timeout,Replace the board (MCC2B or MCC-GEN5 or MCC-GEN5 EN)" },
- {"H1","Two hand safety switch are not OFF before R-axis motion" },
- {"H2","Two hands safety switch timeout" },
- {"H3","One or both safety switches are release before R-axis motion is complete" },
- {"M0","VCE is NOT Referenced" },
- {"M1","Motion Timeout" },
- {"M4","Door over speed" },
- {"M10","Motion was Aborted" },
- {"M11","FET over Temperature" },
- {"M12","FET over Current" },
- {"M13","Torque Limit" },
- {"M14","Hard Track Error Codes" },
- {"M16","Hardware (servo) Motion Error Codes" },
- {"M17","Safety Motion Button was Pushed" },
- {"M20","Z-brake request before ENABLE_Z_MOVE" },
- {"M21","CPLD Detected a difference from the Dual Up Sensors" },
- {"M22","Door Closed Error" },
- {"M23","Z-brake chip U8 has an output fault" },
- {"M24","Unsafe to move: See a safety node (ENABLE_Z_MOVE) or servo following error" },
- {"M25","Servo Following Error" },
- {"NO_ACT","No actions" },
- {"P2","Map NOT Available" },
- {"P3","SPS Excessive Offset" },
- {"P4","SPS Excessive Thickness" },
- {"P12","FB is too large to map" },
- {"P13","FB is too small to map" },
- {"R1","R-axis is not referenced" },
- {"R2","Extended position is NOT defined" },
- {"R3","Door NOT Opened" },
- {"R4","Wrong Z-axis position: platform must be between UP and DOWN position" },
- {"R5","R-axis Limit is exceeded" },
- {"R6","R-axis is NOT Homed (it is not IN)" },
- {"R7","R-axis Orientation is NOT set" },
- {"R9","R-axis is NOT Extended" },
- {"S0","Cannot configure Main VCN" },
- {"S1","Cannot configure R-axis VCN" },
- {"S4","Command String Error: Bad command or parameter, invalid value, etc." },
- {"S5","Illegal data entry" },
- {"S10","VCEDefaultSetting.XML file is corrupted. Configuration stop" },
- {"S11","Not valid for current configuration" },
- {"S20","MiscOutput is already in use" },
- {"S21","MiscOutput is used by current configuration" },
- {"S22","MiscOutput was deleted: it is used by current configuration" },
- {"T5","VCN timeout" },
- {"U1","USB not found or ‘Upgrade’ directory doesn’t exist" },
- {"U2","Script file couldn't be opened" },
- {"U3","Script file not found" },
- {"U4","File from the list is not found" },
- {"U5","Couldn’t create ‘Upgrade’ directory" },
- {"U6","Couldn’t copy files" },
- {"U10"," upgrade.txt file is missing" },
- {"V2","Cannot disable VCN" },
- {"230","Robot Extended" },
- {"231","Front buffer extended" },
- {"232","Valve drive fault" },
- {"236","Door Safety LED is broken" },
- {"250","FET Q10 is open circuit" },
- {"251","FET Q10 is shorted" },
- {"260","Atmospheric Robot is Extended" },
- {"261","ERGO Obstructs the Door" },
- {"262","Door drive fault" },
- {"263","Vacuum Robot is Extended" },
- {"264","User Misc Output Drive Fault" },
- {"265","Safety Hub Output Fault" },
- {"306","Illegal command ID number" },
- {"309","Command ID is not supported in thatCOMM FLOW" },
- {"390","Invalid Checksum" },
- {"414","Command ID in use" },
- {"673","GEN5 EN: inputs are in ERROR state" },
- {"674","GEN5 EN: inputs are in HALT state" },
- {"675","GEN5 EN: inputs are in illegal transition" },
- {"L13","由于检测到突片,动作被禁止" },
- {"L14","检测到安全开关错误" },
- {"K114","防夹光栅报警" },
- {"K115","舱门上限报警" },
- {"K116","舱门下限报警 " },
- {"K118","位置未被引用" },
- {"K119","Z 轴报警" },
- {"K120","R 轴报警 " },
- {"K123","Z 轴未使能" },
- {"K124","R 轴未使能" },
- };
- //
-
- #endregion
- #region 暴露变量
- public override bool IsConnected => _serialport.IsOpen();
- public override RState Status => _status;
- public override bool IsReady => _status == RState.Init || _status == RState.End;
- public override bool IsError => _status == RState.Failed || _status == RState.Timeout;
- public override bool IsInit => _status == RState.Init;
- private string[] _slotMap = new string[25];
- public string SlotMap
- {
- get
- {
- WaferInfo[] wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Name));
- string slot = "";
- for (int i = 0; i < 25; i++)
- {
- slot += wafers[i].IsEmpty ? "0" : "1";
- }
- return slot;
- }
- }
- private bool _OutDoorIsOpen = false;
- public override bool OutDoorIsOpen => _OutDoorIsOpen;
- #endregion
- //传入slot数量
- public HongHuVce(int slot, ModuleName moduleName) : base(slot, moduleName)
- {
- _moduleName = moduleName;
- _IsAsciiMode = true;
- _portname = SC.GetStringValue($"{moduleName}.Port");
- //_portname = "COM162";
- _serialport = new AsyncSerialPort(_portname, 9600, 8, Parity.None, StopBits.One, _newline, _IsAsciiMode);
- _serialport.Open();
- _status = RState.Init;
- _serialport.OnDataChanged += onDataChange;
- _thread = new PeriodicJob(50, fnTimer, "VCE", true);
- CarrierManager.Instance.DeleteCarrier(_moduleName.ToString());
- WaferManager.Instance.DeleteWafer(_moduleName, 0, 25);
- CarrierManager.Instance.SubscribeLocation(_moduleName.ToString(), 1);
- Action<ModuleName, int> _subscribeLoc = (ModuleName module, int waferCount) => {
- if (ModuleHelper.IsInstalled(module))
- {
- WaferManager.Instance.SubscribeLocation(module, waferCount);
- }
- };
- _subscribeLoc(_moduleName, slot);
- }
- /// <summary>
- /// 对处理过的数据list进行处理
- /// 将每条数据进行解析
- /// </summary>
- /// <returns></returns>
- private bool fnTimer()
- {
- lock (_locker)
- {
- //采用ascii传输
- if (_IsAsciiMode)
- {
- //有数据尚未处理
- while (_lstAsciiMsgs.Count > 0)
- {
- string _needHandle = _lstAsciiMsgs.First.Value;
- HandleSingleMsg(_needHandle);
- _lstAsciiMsgs.RemoveFirst();
- }
- }
- //采用binary
- else
- {
- }
- }
- return true;
- }
- /// <summary>
- /// 处理单条信息的函数
- /// 1、判断结束 2、判断错误
- /// </summary>
- /// <param name="msg">需要处理的单条回复</param>
- private void HandleSingleMsg(string msg)
- {
- //
- msg = msg.Trim();
- if (!string.IsNullOrEmpty(msg))
- {
- //action set petrify _BKGRDY结束
- switch (_currentVceMessage.Head)
- {
- case VceMessageHead.Action:
- case VceMessageHead.Set:
- case VceMessageHead.Petrify:
- switch (msg)
- {
- //设备收到 开始运行 目前状态在下发
- case "_RDY":
- LOG.Write(eEvent.EV_VCE_COMMON_INFO, _moduleName, $"vce start {_currentVceMessage.Head}");
- break;
- //设备执行完毕
- case "_BKGRDY":
- if (_currentVceMessage.Command == VceCommand.DoorOpen)
- {
- _OutDoorIsOpen = true;
- }
- if (_currentVceMessage.Command == VceCommand.DoorClose)
- {
- _OutDoorIsOpen = false;
- }
- LOG.Write(eEvent.EV_VCE_COMMON_INFO, _moduleName, $"vce {_currentVceMessage.Head} over");
- _status = RState.End;
- break;
- //异常处理
- default:
- _status = RState.Failed;
- string reason;
- Errorhandle(msg, out reason);
- LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, reason);
- break;
- }
- break;
- case VceMessageHead.Read:
- //如果收到的信息符合
- if (_match_ReadMsg.IsMatch(msg))
- {
- //收到消息 用于结束
- _HasReceiveMsg = true;
- switch (_currentVceMessage.Command)
- {
- //处理wafer 信息为map数据
- case VceCommand.ReadMap:
- ReadMapData(msg);
- break;
- }
- }
- //_RDY查询结束
- else
- {
- if (msg == "_RDY")
- {
- if (_HasReceiveMsg)
- {
- _status = RState.End;
- }
- else
- {
- LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, $"Read Message is over but not receive msg! raw message:{_currentMsg}");
- _status = RState.Failed;
- }
- }
- else
- {
- _status = RState.Failed;
- LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, $"Read Message is invalid: receive message {msg} and send message {_currentMsg}");
- }
- }
- break;
- }
- }
- }
- private void ReadMapData(string msg)
- {
- string waferinfo = "";
- string[] waferitems = msg.Split(',');
- //智能模式 可以识别叠片
- for (int i = 3; i < waferitems.Length - 1; ++i)
- {
- //如果包含只需要逐个检查
- if (waferitems[i].Contains('?'))
- {
- foreach (char j in waferitems[i])
- {
- if (j == '?')
- break;
- else
- waferinfo += j;
- }
- }
- else
- waferinfo += waferitems[i];
- }
- for (int i = 0; i < waferinfo.Length; ++i)
- {
- int slotnum = i;
- if (slotnum < 25)
- {
- switch (waferinfo[i])
- {
- case '0':
- WaferManager.Instance.CreateWafer(_moduleName, slotnum, WaferStatus.Empty);
- break;
- case 'X':
- WaferManager.Instance.CreateWafer(_moduleName, slotnum, WaferStatus.Normal);
- break;
- case 'C':
- WaferManager.Instance.CreateWafer(_moduleName, slotnum, WaferStatus.Crossed);
- break;
- }
- }
- }
- //2进制模式
- //for (int i = 3; i < waferitems.Length - 1; i++)
- //{
- // //从16进制字符转义回二进制
- // string wafersingleinfo = Convert.ToString(Convert.ToInt32(waferitems[i], 16), 2);
- // if (wafersingleinfo.Length < 4)
- // wafersingleinfo = wafersingleinfo.PadLeft(4, '0');//补位
- // waferinfo = wafersingleinfo + waferinfo;//添加到数据中
- //}
- ////请将数据按照反向槽位进行解析存入到wafermanager中
- //for (int i = waferinfo.Length - 1; i > 0; i--)
- //{
- // int slotnum = waferinfo.Length - i - 1;
- // if (slotnum < 25)
- // {
- // if (waferinfo[i] == '1')
- // {
- // WaferManager.Instance.CreateWafer(_moduleName, slotnum, WaferStatus.Normal);
- // }
- // else
- // {
- // WaferManager.Instance.CreateWafer(_moduleName, slotnum, WaferStatus.Empty);
- // }
- // }
- //}
- }
- private void Errorhandle(string msg,out string reason)
- {
- if (_matchErrorCode.IsMatch(msg))
- {
- //若是匹配
- //包含原因
- string errorcode = _matchErrorCode.Match(msg).Value;
- if (_ErrorCode2Reason.ContainsKey(errorcode))
- {
- reason = _ErrorCode2Reason[errorcode];
- }
- else
- {
- reason = "未找到相关Error Code";
- }
- }
- else
- {
- //若不匹配
- reason = "回复消息不符合标准格式";
- }
- }
- /// <summary>
- /// 处理新到的数据
- /// 利用linkedlist处理拆包 粘包情况
- /// </summary>
- /// <param name="newline">新到数据</param>
- private void onDataChange(string oneLineMessage)
- {
- lock (_locker)
- {
- if (string.IsNullOrEmpty(_newline))//没有CR
- {
- _lstAsciiMsgs.AddLast(oneLineMessage);//将消息添加到最后
- return;
- }
- string[] array = oneLineMessage.Split(_newline.ToCharArray());//按照cr分开通讯数据
- foreach (string text in array)
- {
- if (!string.IsNullOrEmpty(text))
- {
- _lstAsciiMsgs.AddLast(text + _newline);//存进list中等待处理
- }
- }
- }
- }
- public override bool HomeALL()
- {
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Home ,Param = "ALL" };
- _currentMsg = _currentVceMessage.toString() + _newline ;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool Home(string axis)
- {
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Home, Param = axis };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool CloseDoor()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.DoorClose };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- /// <summary>
- /// 开门提示
- /// 在honghuVCE中没有ATM信号的内部卡控 可能会导致开门的压差
- /// 因此每一次都要增加判断,只要引用此处功能的,前面都需要有判断
- ///
- /// </summary>
- /// <returns></returns>
- public override bool OpenDoor()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.DoorOpen };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool Load()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Load };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool UnLoad()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.UnLoad };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool Map()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Map };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool ReadMap()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Read, Command = VceCommand.ReadMap, Param = "S" };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- _HasReceiveMsg = false;
- return _serialport.Write(_currentMsg);
- }
- public override bool Goto(int Targetslot)
- {
- if (!CheckVceStatus())
- return false;
- LOG.Write(eEvent.EV_VCE_COMMON_INFO,ModuleName.VCE1, $"SlotNum:{Targetslot}");
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Goto, Param = (Targetslot+1).ToString().PadLeft(2,'0') };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool GotoLP()
- {
- if (!CheckVceStatus())
- return false;
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.GotoLP };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- public override bool ClearError()
- {
- _currentVceMessage = new VceMessage { Head = VceMessageHead.Set, Command = VceCommand.ClearError };
- _currentMsg = _currentVceMessage.toString() + _newline;
- _status = RState.Running;
- return _serialport.Write(_currentMsg);
- }
- }
- }
|