You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
8.6 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "JelExcecute.h"
JelExcecute::JelExcecute()
{
}
JelExcecute::~JelExcecute()
{
}
bool JelExcecute::InitJelRobot(int serialPort, int baudRate)
{
m_nPort = serialPort;
m_nBaud = baudRate;
m_RobotComm.SetWorkMode(FALSE, 100);
std::string strCom = std::to_string(m_nBaud) + ",N,8,1";
m_nPort = 2;
if (m_RobotComm.Open(m_nPort, (char*)strCom.c_str()))
{
//m_RobotComm.SetWnd(gChildPCS_WaferTransfer->GetSafeHwnd());
m_RobotComm.SetNotify(std::bind(&JelExcecute::OnRobotCommRecv, this));
CRobotCmdInfo RobotCmd;
RobotCmd.m_RobotCmdType = _RobotCmd_ResetErr;
SendRobotCmd(RobotCmd);
Sleep(1000);
RobotCmd.m_RobotCmdType = _RobotCmd_Org;
RobotCmd.m_WaitCmdTime = 60;
bool issuccess = SendRobotCmd(RobotCmd);
if (!issuccess)
{
return false;
}
Sleep(500);
//初始化准直器
RobotCmd.m_RobotCmdType = _RobotCmd_Init_Align;
issuccess = SendRobotCmd(RobotCmd);
if (!issuccess)
{
return false;
}
}
else
{
return false;
}
return true;
}
bool JelExcecute::SendRobotCmd(CRobotCmdInfo& RobotCmd)
{
eGlobalVariableType AlarmType = _GlobalVar_NULL;
{
//先把串口缓冲数据读取掉
char Buf[256];
memset(Buf, 0, 256);
m_RobotComm.ReadBuf(Buf, 256);
}
m_IsbJelCommRecv = false;//是否收到串口消息
//获取需要执行的指令
RobotJel_GetSendCmd(RobotCmd);
AlarmType = RobotJel_SendCmdToRobotExt(RobotCmd);
if (AlarmType != _GlobalVar_NULL)
{
return false;
}
return true;
}
void JelExcecute::OnRobotCommRecv()
{
m_IsbJelCommRecv = true;//是否收到串口消息
}
void JelExcecute::RobotJel_GetSendCmd(CRobotCmdInfo& RobotCmd)
{
RobotCmd.m_WaitCmdTime = m_nWaitTime;
if (RobotCmd.m_RobotCmdType == _RobotCmd_Check_ARM_EXIST_WAFER)
{
if (RobotCmd.m_armPos == "up")
{
RobotCmd.m_SendCmdStr = "$1CS4";
}
else if (RobotCmd.m_armPos == "down")
{
RobotCmd.m_SendCmdStr = "$1CS8";
}
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_ImmediateReadFeedback;
RobotCmd.m_WaitCmdTime = m_nWaitTime;
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_ResetErr) //机械手清楚错误$1RD $2RD是清楚准直器错误
{
RobotCmd.m_SendCmdStr = "$1RD";
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_SendOnly;
}
else if(RobotCmd.m_RobotCmdType == _RobotCmd_Org)
{
RobotCmd.m_SendCmdStr = "$1G2";
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_RunToCassMappingPoint)
{
std::string smdStr = "$1G";
if (RobotCmd.LoadportId == POS_CASS_LEFT)
{
smdStr.append(std::to_string(SCRIPT_X_RUN_TO_MAPPING_POS_INDEX + 4 * 0));
}
if (RobotCmd.LoadportId == POS_CASS_CENTER)
{
smdStr.append(std::to_string(SCRIPT_X_RUN_TO_MAPPING_POS_INDEX + 4 * 1));
}
if (RobotCmd.LoadportId == POS_CASS_RIGHT)
{
smdStr.append(std::to_string(SCRIPT_X_RUN_TO_MAPPING_POS_INDEX + 4 * 2));
}
RobotCmd.m_SendCmdStr = smdStr;
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;//等待完成
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_Mapping)
{
std::string smdStr = "$1G";
if (RobotCmd.LoadportId == POS_CASS_LEFT)
{
smdStr.append(std::to_string(SCRIPT_MAPPING_INDEX + 0));
}
if (RobotCmd.LoadportId == POS_CASS_CENTER)
{
smdStr.append(std::to_string(SCRIPT_MAPPING_INDEX + 1));
}
if (RobotCmd.LoadportId == POS_CASS_RIGHT)
{
smdStr.append(std::to_string(SCRIPT_MAPPING_INDEX + 2));
}
RobotCmd.m_SendCmdStr = smdStr;
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;//等待完成
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_ReadMappingData)
{
RobotCmd.m_SendCmdStr = "$1G274";
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_ImmediateReadFeedback;//等待完成
}
else if (RobotCmd.m_RobotCmdType == _RObotCmd_Switch_bank)
{
std::string cmdStr = "$1G";
cmdStr.append(std::to_string(SCRIPT_BANK_INDEX + RobotCmd.m_bankIndex));
RobotCmd.m_SendCmdStr = cmdStr;
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_SelectCass)
{
std::string cmdStr = "$1G";
cmdStr.append(std::to_string(SCRIPT_CASS_START_INDEX + (RobotCmd.m_cassIndex - 1)));
RobotCmd.m_SendCmdStr = cmdStr;
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_SelectSlot)
{
std::string cmdStr = "$1G";
if (RobotCmd.m_cassIndex <= 3)
{
cmdStr.append(std::to_string(SCRIPT_SLOT_START_INDEX + (RobotCmd.m_Slot - 1)));
}
else
{
cmdStr.append(std::to_string(SCRIPT_SLOT_START_INDEX));
}
RobotCmd.m_SendCmdStr = cmdStr;
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_X_Move)
{
std::string cmdStr = "$1G";
int xMoveIndex = SCRIPT_X_MOVE_INDEX;
if (RobotCmd.m_dealWaferType == DEAL_WAFER_TAKE)
{
if (RobotCmd.m_bankIndex == BANK_WAFER)
{
xMoveIndex = xMoveIndex + 4 * (RobotCmd.m_cassIndex - 1) + 2;
}
else if (RobotCmd.m_bankIndex == BANK_RING)
{
xMoveIndex = xMoveIndex + 4 * (RobotCmd.m_cassIndex - 1) + 0;
}
}
else if(RobotCmd.m_dealWaferType == DEAL_WAFER_RETURN)
{
if (RobotCmd.m_bankIndex == BANK_WAFER)
{
xMoveIndex = xMoveIndex + 4 * (RobotCmd.m_cassIndex - 1) + 3;
}
else if (RobotCmd.m_bankIndex == BANK_RING)
{
xMoveIndex = xMoveIndex + 4 * (RobotCmd.m_cassIndex - 1) + 1;
}
}
cmdStr.append(std::to_string(xMoveIndex));
RobotCmd.m_SendCmdStr = cmdStr;
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;
}
else if (RobotCmd.m_RobotCmdType == _RobotCmd_TakeWafer)
{
if (RobotCmd.m_dealWaferType == DEAL_WAFER_TAKE)
{
if (RobotCmd.m_bankIndex == BANK_WAFER)
{
RobotCmd.m_SendCmdStr = "1G52";
}
else if (RobotCmd.m_bankIndex == BANK_RING)
{
RobotCmd.m_SendCmdStr = "1G50";
}
}
else if (RobotCmd.m_dealWaferType == DEAL_WAFER_RETURN)
{
if (RobotCmd.m_bankIndex == BANK_WAFER)
{
RobotCmd.m_SendCmdStr = "1G53";
}
else if (RobotCmd.m_bankIndex == BANK_RING)
{
RobotCmd.m_SendCmdStr = "1G51";
}
}
RobotCmd.m_RobotCmdSendType = _RobotCmdSendType_WaitCmdEnd;
}
}
eGlobalVariableType JelExcecute::RobotJel_SendCmdToRobotExt(CRobotCmdInfo &RobotCmd)
{
std::string RetStr;
std::string SendCmd = RobotCmd.m_SendCmdStr;
bool bOvertime = false;
std::string ErrMsg;
{
int len = SendCmd.length();
SendCmd += " ";//增加2 字节来存放<CR><LF>
char *pStr = (char*)SendCmd.c_str();
pStr[len++] = 0x0d;//<CR>
pStr[len++] = 0x0a;//<LF>
char Buf[COM_BUF_LEN];
memset(Buf, 0, COM_BUF_LEN);
memcpy(Buf, pStr, len);
m_RobotComm.WriteBuf(Buf, len);
if (RobotCmd.m_RobotCmdSendType == _RobotCmdSendType_SendOnly)//只发送指令
{
return _GlobalVar_NULL;
}
//立即读取反馈
if (RobotCmd.m_RobotCmdSendType == _RobotCmdSendType_ImmediateReadFeedback)
{
m_armIsExistWafer = false;
Sleep(2000);
m_IsbJelCommRecv = false;//重置
memset(Buf, 0, COM_BUF_LEN);
m_RobotComm.ReadBuf(Buf, COM_BUF_LEN);
std::string RetStr(Buf);
//>$10表示有料,>$11表示无料
int findIndex = 0;
findIndex = RetStr.find(">$11");
findIndex >= 0 ? m_armIsExistWafer = true : m_armIsExistWafer = false;
if (RetStr.find(">") != -1)//反馈">"表示执行中
{
RobotCmd.m_RevStr = RetStr;
}
else
{
ErrMsg = "Read Feed back Err";
}
}
else//异步等待读取
{
int WaitDelay = RobotCmd.m_WaitCmdTime * 1000;//总共等待的时间ms
int CheckDelay = 200;//每次循环延时
int CurDelay = 0;//当前的总延时
bOvertime = false;
ErrMsg = "";
while (1)
{
if (m_IsbJelCommRecv)//收到新的消息时再去读取
{
Sleep(CheckDelay);
m_IsbJelCommRecv = false;//重置
memset(Buf, 0, COM_BUF_LEN);
m_RobotComm.ReadBuf(Buf, COM_BUF_LEN);
std::string RetStr(Buf);
if (RetStr.find(">") != -1)//反馈">"表示执行中
{
//发送后只等待反馈<
if (RobotCmd.m_RobotCmdSendType == _RobotCmdSendType_WaitFeedback)
{
RobotCmd.m_RevStr = RetStr;
break;
}
}
if (RetStr.find(RobotCmd.m_SendCmdStr) != -1)//反馈发送cmd表示执行结束
{
break;
}
else if (RetStr.find("ERROR") != -1)
{
ErrMsg = "手臂有片或无片错误";
break;
}
}
CurDelay += CheckDelay;
if (CurDelay > WaitDelay)
{
bOvertime = true;
break;
}
Sleep(CheckDelay);
}
}
}
if (bOvertime)//检测超时
{
std::string AddInfo;
AddInfo = "Cmd Over Time:";
AddInfo += RobotCmd.m_SendCmdStr;
//设置报警信息
{
RobotCmd.m_ErrStr = AddInfo;
return _GlobalVar_Alarm_Robot_CmdOverTime;
}
}
//ERR:code:Description
if (ErrMsg != "")//执行错误
{
std::string AddInfo = RobotCmd.m_SendCmdStr;
AddInfo += "Cmd Execute Error:";
AddInfo += ErrMsg;
//设置报警信息
{
RobotCmd.m_ErrStr = AddInfo;
return _GlobalVar_Alarm_Robot_StateErr;
}
}
return _GlobalVar_NULL;
}