#include "stdafx.h" #include "Animatics_Proto.h" #include "math.h" #define MAX_IN_BUFF_SIZE 1024 //***** Static Data ***** static char *outBuff = NULL; //================================================================ HANDLE g_machine_event=NULL; //================================================================ int SmartMotor_Proto::g_machine_Thread_State=THREAD_PAUSED; HANDLE SmartMotor_Proto::g_machine_Thread_Id=NULL; HANDLE SmartMotor_Proto::g_machine_Serial_Mutex; //================================================================ struct_smartmotor_machine SmartMotor_Proto::g_machine; CLogger *SmartMotor_Proto::g_pLogger; HANDLE SmartMotor_Proto::g_hHomedEvent = NULL; //=========================================================================== // Worker Thread to send command to and receive data from smart motor. //=========================================================================== unsigned __stdcall SmartMotor_Proto::g_machine_Thread(LPVOID pThis) { SmartMotor_Proto* _This = (SmartMotor_Proto*)pThis; for (;;) { TRACE0("g_machine_Thread in loop set.\n"); if (g_machine_Thread_State == THREAD_EXIT) ExitThread(0); WaitForSingleObject(g_machine_event,INFINITE); TRACE0("g_machine_Thread obtained event.\n"); switch (g_machine_Thread_State) { case THREAD_EXIT: { ExitThread(0); } case THREAD_PAUSED: break; case THREAD_RUNNING_STATE: { _This->smartmotor_motion_get_motion_status(); break; } default: ExitThread(0); } }; g_machine_Thread_State = THREAD_EXIT; ExitThread(0); }; //****************************************************************************** SmartMotor_Proto::SmartMotor_Proto() { g_machine.x.address=1; g_machine.y.address=2; g_machine.z.address=3; g_machine.x._Move_Speed_Gear=1; g_machine.x._l_move_dis=0; g_machine.x._d_move_dis=0; g_machine.x._l_cur_pos=0; g_machine.x._d_cur_pos=0; g_machine.x._dSet_Zero_Pos=0; g_machine.x._lSet_Zero_Pos=0; g_machine.x.s_machine_status.StatusWord[0]=0; g_machine.x.s_machine_status.StatusWord[1]=0; g_machine.x.s_machine_status.DriverRdy=FALSE; g_machine.x.s_machine_status.MotorOff=FALSE; g_machine.x.s_machine_status.VoltageFault=FALSE; g_machine.x.s_machine_status.PosErr=FALSE; g_machine.x.s_machine_status.OverHeat=FALSE; g_machine.x.s_machine_status.NegLimit=FALSE; g_machine.x.s_machine_status.PosLimit=FALSE; g_machine.y._Move_Speed_Gear=1; g_machine.y._l_move_dis=0; g_machine.y._d_move_dis=0; g_machine.y._l_cur_pos=0; g_machine.y._d_cur_pos=0; g_machine.y._dSet_Zero_Pos=0; g_machine.y._lSet_Zero_Pos=0; g_machine.y.s_machine_status.StatusWord[0]=0; g_machine.y.s_machine_status.StatusWord[1]=0; g_machine.y.s_machine_status.DriverRdy=FALSE; g_machine.y.s_machine_status.MotorOff=FALSE; g_machine.y.s_machine_status.VoltageFault=FALSE; g_machine.y.s_machine_status.PosErr=FALSE; g_machine.y.s_machine_status.OverHeat=FALSE; g_machine.y.s_machine_status.NegLimit=FALSE; g_machine.y.s_machine_status.PosLimit=FALSE; g_machine.z._Move_Speed_Gear=1; g_machine.z._l_move_dis=0; g_machine.z._d_move_dis=0; g_machine.z._l_cur_pos=0; g_machine.z._d_cur_pos=0; g_machine.z._dSet_Zero_Pos=0; g_machine.z._lSet_Zero_Pos=0; g_machine.z.s_machine_status.StatusWord[0]=0; g_machine.z.s_machine_status.StatusWord[1]=0; g_machine.z.s_machine_status.DriverRdy=FALSE; g_machine.z.s_machine_status.MotorOff=FALSE; g_machine.z.s_machine_status.VoltageFault=FALSE; g_machine.z.s_machine_status.PosErr=FALSE; g_machine.z.s_machine_status.OverHeat=FALSE; g_machine.z.s_machine_status.NegLimit=FALSE; g_machine.z.s_machine_status.PosLimit=FALSE; g_machine.s_status._bXHomed=FALSE; g_machine.s_status._bYHomed=FALSE; g_machine.s_status._bZHomed=FALSE; g_machine.s_status._bXYZHomed=FALSE; g_machine.s_status._machine_running=FALSE; g_machine.s_status._bXMoving=FALSE; g_machine.s_status._bYMoving=FALSE; g_machine.s_status._bZMoving=FALSE; g_machine.s_status._bXYZMoving=FALSE; _reset_config_parameter(); m_bHomingActive=false; g_pLogger = new CLogger(_T("\\UtilityDebug.Log")); }; //****************************************************************************** SmartMotor_Proto::~SmartMotor_Proto() { if (g_pLogger) { g_pLogger->Send(_T("Destruct Csmartmotor_Proto.\r\n")); delete g_pLogger; g_pLogger = NULL; } } //=========================================================================== double SmartMotor_Proto::ScaleToMM(long lCount, double dResolution) { double dMM = 0.0; dMM = (lCount* dResolution) /1000 ; return dMM; } //=========================================================================== long SmartMotor_Proto::MMtoScale(double lDistanceMM, double dResolution) { long lCounts(0); if (dResolution) lCounts = static_cast (lDistanceMM *1000 / dResolution); else ASSERT(0); return lCounts; } //===================================================================================== long SmartMotor_Proto::_4char2long(unsigned char *cBuff) { union { long l_value; char c_array[5]; }; memset (c_array, 0, 5); c_array[0] = cBuff[3]; c_array[1] = cBuff[2]; c_array[2] = cBuff[1]; c_array[3] = cBuff[0]; return(l_value); } //===================================================================================== long SmartMotor_Proto::_3char2long(unsigned char *cBuff) { union { long l_value; char c_array[5]; }; memset (c_array, 0, 5); c_array[0] = cBuff[2]; c_array[1] = cBuff[1]; c_array[2] = cBuff[0]; return(l_value); } //======================================================================== void SmartMotor_Proto::_reverse_dword(DWORD *dWord) { BYTE cBuff[4]; BYTE *dwBuff = (BYTE *)dWord; for ( int ii = 0 ; ii < 4 ; ++ii ) cBuff[ii]= dwBuff[ii]; dwBuff[0] = cBuff[3]; dwBuff[1] = cBuff[2]; dwBuff[2] = cBuff[1]; dwBuff[3] = cBuff[0]; } //****************************************************************************** void SmartMotor_Proto::_scale2inch(unsigned long scale, double &inch) { UNREFERENCED_PARAMETER(scale); UNREFERENCED_PARAMETER(inch); } //****************************************************************************** void SmartMotor_Proto::_inch2scale(unsigned long &scale, double inch) { UNREFERENCED_PARAMETER(scale); UNREFERENCED_PARAMETER(inch); } //****************************************************************************** // convert a string of characters into its binary form void SmartMotor_Proto::_char2bin(unsigned char *cBuff, BYTE *cBytes, int iLen) { memset(cBytes, 0, MAX_BUFF_SIZE); for (int i=0;i>8; Val = MSB|LSB; } //****************************************************************************** double SmartMotor_Proto::TimeInSecs(void) { double Secs; LARGE_INTEGER HPCounterTicksPerSecond; BOOL HasHPCounter = QueryPerformanceFrequency(&HPCounterTicksPerSecond); if (HasHPCounter == TRUE) { // Use high resolution clock. double HPCounterTicksPersec = (DWORD)((double) HPCounterTicksPerSecond.QuadPart); LARGE_INTEGER HPTicks; QueryPerformanceCounter(&HPTicks); Secs = ((double)HPTicks.QuadPart / HPCounterTicksPersec); } else { // Use clock with less resolution. Secs = GetTickCount(); Secs /= 1000.0; } return Secs; } #pragma warning(disable:4996) //============================================================================== //****************************************************************************** void SmartMotor_Proto::_reset_config_parameter() { for(INT i=0;i<5;i++) { g_machine.s_machine_config.x_axis._speed_[i]=0; g_machine.s_machine_config.x_axis._accel_[i]=0; g_machine.s_machine_config.x_axis._decel_[i]=0; g_machine.s_machine_config.y_axis._speed_[i]=0; g_machine.s_machine_config.y_axis._accel_[i]=0; g_machine.s_machine_config.y_axis._decel_[i]=0; g_machine.s_machine_config.z_axis._speed_[i]=0; g_machine.s_machine_config.z_axis._accel_[i]=0; g_machine.s_machine_config.z_axis._decel_[i]=0; } g_machine.s_machine_config.x_axis._neg_working_limit=0; g_machine.s_machine_config.x_axis._pos_working_limit=200; g_machine.s_machine_config.x_axis._scale_resolution=0.4; g_machine.s_machine_config.y_axis._neg_working_limit=0; g_machine.s_machine_config.y_axis._pos_working_limit=200; g_machine.s_machine_config.y_axis._scale_resolution=0.4; g_machine.s_machine_config.z_axis._neg_working_limit=0; g_machine.s_machine_config.z_axis._pos_working_limit=200; g_machine.s_machine_config.z_axis._scale_resolution=0.4; } //========================================================================================= SSI_STATUS_SMARTMOTOR SmartMotor_Proto::SaveSmartMotorConfig() { FILE* m_pOutFile; char *outBuff = NULL; // char tmp; CString csAppPath; GetAppPath(csAppPath); CString csSO7ConfigFile =csAppPath+_T("\\smartmotor_config.ini"); _wfopen_s(&m_pOutFile, csSO7ConfigFile, _T("wt")); if (!m_pOutFile) { free(outBuff); }; outBuff="[HARDWARE]"; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile, "\n"); //=================================X================================== outBuff="SPEED_X1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._speed_[0]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_X1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._accel_[0]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_X1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._decel_[0]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_X2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._speed_[1]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_X2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._accel_[1]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_X2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._decel_[1]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_X3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._speed_[2]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_X3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._accel_[2]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_X3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._decel_[2]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_X4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._speed_[3]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_X4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._accel_[3]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_X4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._decel_[3]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_X5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._speed_[4]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_X5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._accel_[4]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_X5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.x_axis._decel_[4]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); //=================================Y================================== outBuff="SPEED_Y1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._speed_[0]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Y1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._accel_[0]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Y1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._decel_[0]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Y2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._speed_[1]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Y2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._accel_[1]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Y2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._decel_[1]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Y3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._speed_[2]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Y3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._accel_[2]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Y3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._decel_[2]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Y4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._speed_[3]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Y4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._accel_[3]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Y4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._decel_[3]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Y5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._speed_[4]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Y5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._accel_[4]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Y5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.y_axis._decel_[4]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); //=================================Z================================== outBuff="SPEED_Z1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._speed_[0]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Z1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._accel_[0]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Z1="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._decel_[0]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Z2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._speed_[1]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Z2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._accel_[1]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Z2="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._decel_[1]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Z3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._speed_[2]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Z3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._accel_[2]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Z3="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._decel_[2]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Z4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._speed_[3]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Z4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._accel_[3]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Z4="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._decel_[3]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="SPEED_Z5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._speed_[4]); fprintf(m_pOutFile, "\n"); outBuff="ACCELERATION_Z5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._accel_[4]); fprintf(m_pOutFile, "\n"); outBuff="DECELERATION_Z5="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%d", g_machine.s_machine_config.z_axis._decel_[4]); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); //===========worktable===================== outBuff="[WORKTABLE]"; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile, "\n"); outBuff="X_SCALE_RESOLUTION="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.x_axis._scale_resolution); fprintf(m_pOutFile, "\n"); outBuff="Y_SCALE_RESOLUTION="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.y_axis._scale_resolution); fprintf(m_pOutFile, "\n"); outBuff="Z_SCALE_RESOLUTION="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.z_axis._scale_resolution); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="X_NEG_WORKING_LIMIT="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.x_axis._neg_working_limit); fprintf(m_pOutFile, "\n"); outBuff="Y_NEG_WORKING_LIMIT="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.y_axis._neg_working_limit); fprintf(m_pOutFile, "\n"); outBuff="Z_NEG_WORKING_LIMIT="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.z_axis._neg_working_limit); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); outBuff="X_POS_WORKING_LIMIT="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.x_axis._pos_working_limit); fprintf(m_pOutFile, "\n"); outBuff="Y_POS_WORKING_LIMIT="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.y_axis._pos_working_limit); fprintf(m_pOutFile, "\n"); outBuff="Z_POS_WORKING_LIMIT="; fprintf(m_pOutFile,"%s", outBuff); fprintf(m_pOutFile,"%.3f", g_machine.s_machine_config.z_axis._pos_working_limit); fprintf(m_pOutFile, "\n"); fprintf(m_pOutFile,"%s", ";\n"); fclose(m_pOutFile); return SSI_STATUS_SMARTMOTOR_NORMAL; } //****************************************************************************** //log file shows the machine speed data SSI_STATUS_SMARTMOTOR SmartMotor_Proto::LoadSmartMotorConfig() { FILE *hConfigFile = NULL; char szLine[MAX_BUFF_SIZE]; char *token = NULL; char seps[] = " =,\t\n"; char cTemp[20]={0}; CString csAppPath; GetAppPath(csAppPath); CString csSO7ConfigFile =csAppPath+_T("\\smartmotor_config.ini");//iniFile _wfopen_s(&hConfigFile,csSO7ConfigFile,_T("rt")); if(hConfigFile) { while (!feof(hConfigFile)) { fgets(szLine,MAX_BUFF_SIZE,hConfigFile);//read a line if((szLine[0]!=';')&&(strlen(szLine)>2)) { token = strtok(szLine,seps); //============================X============================ if(!_stricmp(token,"SPEED_X1"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._speed_[0]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_X1")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._accel_[0]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_X1")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._decel_[0]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_X2"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._speed_[1]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_X2")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._accel_[1]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_X2")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._decel_[1]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_X3"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._speed_[2]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_X3")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._accel_[2]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_X3")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._decel_[2]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_X4"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._speed_[3]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_X4")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._accel_[3]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_X4")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._decel_[3]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_X5"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._speed_[4]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_X5")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._accel_[4]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_X5")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._decel_[4]=atoi(cTemp); } } //===========================Y============================ else if(!_stricmp(token,"SPEED_Y1"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._speed_[0]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Y1")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._accel_[0]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Y1")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._decel_[0]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Y2"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._speed_[1]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Y2")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._accel_[1]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Y2")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._decel_[1]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Y3"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._speed_[2]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Y3")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._accel_[2]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Y3")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._decel_[2]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Y4"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._speed_[3]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Y4")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._accel_[3]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Y4")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._decel_[3]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Y5"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._speed_[4]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Y5")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._accel_[4]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Y5")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._decel_[4]=atoi(cTemp); } } //===========================Z============================ else if(!_stricmp(token,"SPEED_Z1"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._speed_[0]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Z1")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._accel_[0]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Z1")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._decel_[0]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Z2"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._speed_[1]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Z2")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._accel_[1]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Z2")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._decel_[1]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Z3"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._speed_[2]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Z3")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._accel_[2]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Z3")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._decel_[2]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Z4"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._speed_[3]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Z4")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._accel_[3]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Z4")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._decel_[3]=atoi(cTemp); } } //-------------------------------------------- else if(!_stricmp(token,"SPEED_Z5"))// { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._speed_[4]=atoi(cTemp); } } else if(!_stricmp(token,"ACCELERATION_Z5")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._accel_[4]=atoi(cTemp); } } else if(!_stricmp(token,"DECELERATION_Z5")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._decel_[4]=atoi(cTemp); } } //=====================[WORKTABLE]======================== else if(!_stricmp(token, "X_SCALE_RESOLUTION")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._scale_resolution=atof(cTemp); } } else if(!_stricmp(token, "Y_SCALE_RESOLUTION")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._scale_resolution=atof(cTemp); } } else if(!_stricmp(token, "Z_SCALE_RESOLUTION")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._scale_resolution=atof(cTemp); } } else if(!_stricmp(token, "X_NEG_WORKING_LIMIT")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._neg_working_limit=atof(cTemp); } } else if(!_stricmp(token, "Y_NEG_WORKING_LIMIT")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._neg_working_limit=atof(cTemp); } } else if(!_stricmp(token, "Z_NEG_WORKING_LIMIT")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._neg_working_limit=atof(cTemp); } } else if(!_stricmp(token, "X_POS_WORKING_LIMIT")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.x_axis._pos_working_limit=atof(cTemp); } } else if(!_stricmp(token, "Y_POS_WORKING_LIMIT")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.y_axis._pos_working_limit=atof(cTemp); } } else if(!_stricmp(token, "Z_POS_WORKING_LIMIT")) { token = strtok( NULL, seps); if (token) { strcpy(cTemp,token); g_machine.s_machine_config.z_axis._pos_working_limit=atof(cTemp); } } } } fclose(hConfigFile); } return SSI_STATUS_SMARTMOTOR_NORMAL; } //****************************************************************************** SSI_STATUS_SMARTMOTOR SmartMotor_Proto::GetAppPath(CString &Path) { Path=_T(""); // Speed optimization - noticed slow in GlowCode if (Path.IsEmpty()) { CString tmpPath; GetModuleFileName(NULL,tmpPath.GetBuffer(255),255); tmpPath.ReleaseBuffer(); tmpPath.TrimRight(); int nLastSlash = tmpPath.ReverseFind('\\'); if (nLastSlash >= 0) tmpPath = tmpPath.Left(nLastSlash); else tmpPath.Empty(); Path=tmpPath; } return SSI_STATUS_SMARTMOTOR_NORMAL; }; //****************************************************************************** SSI_STATUS_SMARTMOTOR SmartMotor_Proto::ExtractAppPath(CString &Path) { CString tmpPath = Path; tmpPath.TrimRight(); tmpPath.TrimLeft(); int nLastSlash = tmpPath.ReverseFind('\\'); if (nLastSlash > -1) { // complete path tmpPath = Path.Left(nLastSlash); Path = tmpPath; } else { // not a complete path Path=""; }; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //****************************************************************************** //set up the thread //****************************************************************************** SSI_STATUS_SMARTMOTOR SmartMotor_Proto::Create_thread() { //Set initial state of the machine g_machine.s_status._machine_running = false; SSI_STATUS_SMARTMOTOR Status=SSI_STATUS_SMARTMOTOR_NORMAL; UNREFERENCED_PARAMETER(Status); // ******************************************************************** // g_machine_event = CreateEvent(NULL, // default security attributes FALSE, // manual reset event object NULL, // signaled NULL); // unamed object g_machine_Thread_Id = CreateThread( (LPSECURITY_ATTRIBUTES) NULL, 0, (LPTHREAD_START_ROUTINE) g_machine_Thread, (LPVOID) this, 0, NULL); g_machine_Thread_State = THREAD_RUNNING_STATE; // ******************************************************************** // Prepare and start EP_S07_81 Thread - Use async commit. // g_machine_Serial_Mutex = CreateMutex(NULL, // default security attributes FALSE, // initial owner NULL); // name // ********************************************************************* g_hHomedEvent = CreateEvent(NULL, // default security attributes TRUE, // manual reset event object FALSE, // initial state is signaled NULL); // unamed object return SSI_STATUS_SMARTMOTOR_NORMAL; } //****************************************************************************** SSI_STATUS_SMARTMOTOR SmartMotor_Proto::Exit_thread() { SSI_STATUS_SMARTMOTOR Status=SSI_STATUS_SMARTMOTOR_NORMAL; g_machine_Thread_State = THREAD_EXIT; SetEvent(g_machine_event); if (g_machine_Thread_Id) { DWORD dwCode = STILL_ACTIVE; while (dwCode == STILL_ACTIVE) { GetExitCodeThread(g_machine_Thread_Id,&dwCode); Sleep(1); } } SetEvent(g_machine_event); CloseHandle(g_machine_event); g_machine_Thread_State = THREAD_EXIT; ReleaseMutex(g_machine_Serial_Mutex); CloseHandle(g_machine_Serial_Mutex); return Status; } //****************************************************************************** SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_start_machine() { Create_thread(); InitSmartMotor(); StartSmartMotor(); LoadSmartMotorConfig(); //smartmotor_motion_Dcc_Home(); g_machine_Thread_State = THREAD_RUNNING_STATE; g_machine.s_status._machine_running = true; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //=============================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_shutdown_machine() { StopSmartMotor(); Exit_thread(); g_machine.s_status._machine_running = false; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //**********************************************************************// //**********************************************************************// //========================================================================== BOOL SmartMotor_Proto::InitSmartMotor() { try { // Create SMIHost object and interfaces HRESULT hr = CommInterface.CreateInstance(__uuidof(SMIHost)); if(FAILED(hr)) { AfxMessageBox(_T("Cannot create an instance of \"SMIHost\" class!")); return FALSE; } hr = CommInterface.QueryInterface(__uuidof(ISMICMotion),&CMotionInterface); if(FAILED(hr)) { AfxMessageBox(_T("The interface \"ISMICMotion\" not found!")); return FALSE; } hr = CommInterface.QueryInterface(__uuidof(ISMIPath),&PathInterface); if(FAILED(hr)) { AfxMessageBox(_T("The interface \"ISMIPath\" not found!")); return FALSE; } CString Str = _T("N/A"); long Version = CommInterface->EngineVersion; if(Version) { Str.Format(_T("IntegMotorInterface Version: %d.%d%d%d"), HIBYTE(HIWORD(Version)), LOBYTE(HIWORD(Version)), HIBYTE(LOWORD(Version)), LOBYTE(LOWORD(Version))); } return TRUE; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); return FALSE; } } //========================================================================== void SmartMotor_Proto::StartSmartMotor() { try { CommInterface->BaudRate = 19200; CommInterface->OpenPort(_bstr_t(_T("COM1"))); CommInterface->InitRS485(3, 1); CommInterface->DefaultMotor = 0; CommInterface->WriteCommand(("RUN")); } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); } } //========================================================================== void SmartMotor_Proto::StopSmartMotor() { try { CommInterface->DefaultMotor = 0; CommInterface->WriteCommand(_bstr_t("c=1")); CommInterface->WriteCommand(("S")); CommInterface->WriteCommand(("OFF")); CommInterface->ClosePort(); } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); } } //======================================================================== // Move the stage left/right until the index location is non-zero //======================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_Dcc_Home() { try { g_machine.s_status._bXYZHomed=FALSE; g_machine.s_status._bXHomed=FALSE; g_machine.s_status._bYHomed=FALSE; g_machine.s_status._bZHomed=FALSE; CommInterface->DefaultMotor=0; CommInterface->WriteCommand(_bstr_t("c=1")); m_bHomingActive=true; return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); return SSI_STATUS_SMARTMOTOR_COMMERR; } } SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_IS_Homed() { try { if (g_machine.s_status._bXYZHomed && m_bHomingActive) { m_bHomingActive=false; SetEvent(g_hHomedEvent); } return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); return SSI_STATUS_SMARTMOTOR_COMMERR; } } //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_startup(double dScaleResolutionX, double dScaleResolutionY, double dScaleResolutionZ) { g_machine.s_machine_config.x_axis._scale_resolution = dScaleResolutionX; g_machine.s_machine_config.y_axis._scale_resolution = dScaleResolutionY; g_machine.s_machine_config.z_axis._scale_resolution = dScaleResolutionZ; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_get_position_xyz(double & dX, double & dY, double & dZ) { //WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_GET_POS_XYZ(); g_machine.x._d_cur_pos=ScaleToMM(g_machine.x._l_cur_pos,g_machine.s_machine_config.x_axis._scale_resolution); g_machine.y._d_cur_pos=ScaleToMM(g_machine.y._l_cur_pos,g_machine.s_machine_config.y_axis._scale_resolution); g_machine.z._d_cur_pos=ScaleToMM(g_machine.z._l_cur_pos,g_machine.s_machine_config.z_axis._scale_resolution); dX=g_machine.x._d_cur_pos; dY=g_machine.y._d_cur_pos; dZ=g_machine.z._d_cur_pos; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_get_pos_pulse_xyz(long & lX, long & lY, long & lZ) { //WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_GET_POS_XYZ(); lX=g_machine.x._l_cur_pos; lY=g_machine.y._l_cur_pos; lZ=g_machine.z._l_cur_pos; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_set_position_xyz(double dX, double dY, double dZ, bool bWait) { WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_MOVETOX_ABS(dX); _send_cmd_SMARTMOTOR_MOVETOY_ABS(dY); _send_cmd_SMARTMOTOR_MOVETOZ_ABS(dZ); #pragma message("Test settle wait comparing the status bit to the scale monitor") if (bWait) { const long lSleep = 20; const long lMaxLoopCnt = 10000/lSleep; // use max homing time of 20 seconds long lLoopCnt = 0; Sleep(lSleep); while (g_machine.s_status._bXYZMoving && lLoopCnt < lMaxLoopCnt) { Sleep(lSleep); smartmotor_motion_get_motion_status(); ++lLoopCnt; } } return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_move_rel_dis_xyz(double dX, double dY, double dZ, bool bWait) { WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_MOVETOX_REL(dX); _send_cmd_SMARTMOTOR_MOVETOY_REL(dY); _send_cmd_SMARTMOTOR_MOVETOZ_REL(dZ); if (bWait) { const long lSleep = 20; const long lMaxLoopCnt = 10000/lSleep; // use max homing time of 20 seconds long lLoopCnt = 0; Sleep(lSleep); while (g_machine.s_status._bXYZMoving && lLoopCnt < lMaxLoopCnt) { Sleep(lSleep); smartmotor_motion_get_motion_status(); ++lLoopCnt; } } return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_stop_xyz() { //WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_DECEL_STOPX(); _send_cmd_SMARTMOTOR_DECEL_STOPY(); _send_cmd_SMARTMOTOR_DECEL_STOPZ(); return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_stop_xyz_S() { //WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_ABRUPT_STOPX(); _send_cmd_SMARTMOTOR_ABRUPT_STOPY(); _send_cmd_SMARTMOTOR_ABRUPT_STOPZ(); return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_get_home_status() { //WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done if(!g_machine.s_status._bXHomed) _send_cmd_SMARTMOTOR_GET_HOME_STATUS_X(); if(!g_machine.s_status._bYHomed) _send_cmd_SMARTMOTOR_GET_HOME_STATUS_Y(); if(!g_machine.s_status._bZHomed) _send_cmd_SMARTMOTOR_GET_HOME_STATUS_Z(); g_machine.s_status._bXYZHomed=g_machine.s_status._bXHomed && g_machine.s_status._bYHomed && g_machine.s_status._bZHomed; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //================================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_get_motion_status() { // WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_GET_MOVE_STATUS_X(); _send_cmd_SMARTMOTOR_GET_MOVE_STATUS_Y(); _send_cmd_SMARTMOTOR_GET_MOVE_STATUS_Z(); g_machine.s_status._bXYZMoving=g_machine.s_status._bXMoving || g_machine.s_status._bYMoving || g_machine.s_status._bZMoving; return SSI_STATUS_SMARTMOTOR_NORMAL; }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::smartmotor_motion_get_status_word() { // WaitForSingleObject(g_hHomedEvent, INFINITE); // machine start and homing is done _send_cmd_SMARTMOTOR_GET_STATUS_WORD0(); _send_cmd_SMARTMOTOR_GET_STATUS_WORD16(); g_machine.x.s_machine_status.DriverRdy = g_machine.x.s_machine_status.StatusWord[0] & HBIT0; g_machine.x.s_machine_status.MotorOff = g_machine.x.s_machine_status.StatusWord[0] & HBIT1; g_machine.x.s_machine_status.VoltageFault = g_machine.x.s_machine_status.StatusWord[0] & HBIT3; g_machine.x.s_machine_status.PosErr = g_machine.x.s_machine_status.StatusWord[0] & HBIT6; g_machine.x.s_machine_status.OverHeat = g_machine.x.s_machine_status.StatusWord[0] & HBIT8; g_machine.x.s_machine_status.NegLimit = g_machine.x.s_machine_status.StatusWord[1] & HBIT3; g_machine.x.s_machine_status.PosLimit = g_machine.x.s_machine_status.StatusWord[1] & HBIT2; g_machine.y.s_machine_status.DriverRdy = g_machine.y.s_machine_status.StatusWord[0] & HBIT0; g_machine.y.s_machine_status.MotorOff = g_machine.y.s_machine_status.StatusWord[0] & HBIT1; g_machine.y.s_machine_status.VoltageFault = g_machine.y.s_machine_status.StatusWord[0] & HBIT3; g_machine.y.s_machine_status.PosErr = g_machine.y.s_machine_status.StatusWord[0] & HBIT6; g_machine.y.s_machine_status.OverHeat = g_machine.y.s_machine_status.StatusWord[0] & HBIT8; g_machine.y.s_machine_status.NegLimit = g_machine.y.s_machine_status.StatusWord[1] & HBIT3; g_machine.y.s_machine_status.PosLimit = g_machine.y.s_machine_status.StatusWord[1] & HBIT2; g_machine.z.s_machine_status.DriverRdy = g_machine.z.s_machine_status.StatusWord[0] & HBIT0; g_machine.z.s_machine_status.MotorOff = g_machine.z.s_machine_status.StatusWord[0] & HBIT1; g_machine.z.s_machine_status.VoltageFault = g_machine.z.s_machine_status.StatusWord[0] & HBIT3; g_machine.z.s_machine_status.PosErr = g_machine.z.s_machine_status.StatusWord[0] & HBIT6; g_machine.z.s_machine_status.OverHeat = g_machine.z.s_machine_status.StatusWord[0] & HBIT8; g_machine.z.s_machine_status.NegLimit = g_machine.z.s_machine_status.StatusWord[1] & HBIT3; g_machine.z.s_machine_status.PosLimit = g_machine.z.s_machine_status.StatusWord[1] & HBIT2; return SSI_STATUS_SMARTMOTOR_NORMAL; }; ////======================================================================== //SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_calculate_straightline_motion(double dSpeedMM) //{ // // return SSI_STATUS_SMARTMOTOR_NORMAL; //} //**********************************************************************// //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_POS_XYZ() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); Sleep(10); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(_bstr_t("RPA")); g_machine.x._l_cur_pos=atoi(CommInterface->ReadResponse()); Sleep(10); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(_bstr_t("RPA")); g_machine.y._l_cur_pos=atoi(CommInterface->ReadResponse()); Sleep(10); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(_bstr_t("RPA")); g_machine.z._l_cur_pos=atoi(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVETOX_ABS(double dis) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("MP")); g_machine.x._l_move_dis=MMtoScale(dis,g_machine.s_machine_config.x_axis._scale_resolution); csTmp.Format(_T("PT=%d"),g_machine.x._l_move_dis); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.x_axis._speed_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.x_axis._accel_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.x_axis._decel_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVETOY_ABS(double dis) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("MP")); g_machine.y._l_move_dis=MMtoScale(dis,g_machine.s_machine_config.y_axis._scale_resolution); csTmp.Format(_T("PT=%d"),g_machine.y._l_move_dis); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.y_axis._speed_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.y_axis._accel_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.y_axis._decel_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVETOZ_ABS(double dis) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("MP")); g_machine.z._l_move_dis=MMtoScale(dis,g_machine.s_machine_config.z_axis._scale_resolution); csTmp.Format(_T("PT=%d"),g_machine.z._l_move_dis); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.z_axis._speed_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.z_axis._accel_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.z_axis._decel_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVETOX_REL(double dis) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("MP")); g_machine.x._l_move_dis=MMtoScale(dis,g_machine.s_machine_config.x_axis._scale_resolution); csTmp.Format(_T("PRT=%d"),g_machine.x._l_move_dis); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.x_axis._speed_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.x_axis._accel_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.x_axis._decel_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVETOY_REL(double dis) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("MP")); g_machine.y._l_move_dis=MMtoScale(dis,g_machine.s_machine_config.y_axis._scale_resolution); csTmp.Format(_T("PRT=%d"),g_machine.y._l_move_dis); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.y_axis._speed_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.y_axis._accel_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.y_axis._decel_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVETOZ_REL(double dis) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("MP")); g_machine.z._l_move_dis=MMtoScale(dis,g_machine.s_machine_config.z_axis._scale_resolution); csTmp.Format(_T("PRT=%d"),g_machine.z._l_move_dis); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.z_axis._speed_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.z_axis._accel_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.z_axis._decel_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVEX(BOOL dir) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("MV")); if (dir) { csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.x_axis._speed_[g_machine.x._Move_Speed_Gear]); } else { csTmp.Format(_T("VT=%d"),-g_machine.s_machine_config.x_axis._speed_[g_machine.x._Move_Speed_Gear]); } CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.x_axis._accel_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.x_axis._decel_[g_machine.x._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("XS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVEY(BOOL dir) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("MV")); if (dir) { csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.y_axis._speed_[g_machine.y._Move_Speed_Gear]); } else { csTmp.Format(_T("VT=%d"),-g_machine.s_machine_config.y_axis._speed_[g_machine.y._Move_Speed_Gear]); } CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.y_axis._accel_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.y_axis._decel_[g_machine.y._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("YS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_MOVEZ(BOOL dir) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CString csTmp; CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("MV")); if (dir) { csTmp.Format(_T("VT=%d"),g_machine.s_machine_config.z_axis._speed_[g_machine.z._Move_Speed_Gear]); } else { csTmp.Format(_T("VT=%d"),-g_machine.s_machine_config.z_axis._speed_[g_machine.z._Move_Speed_Gear]); } CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("AT=%d"),g_machine.s_machine_config.z_axis._accel_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); csTmp.Format(_T("DT=%d"),g_machine.s_machine_config.z_axis._decel_[g_machine.z._Move_Speed_Gear]); CommInterface->WriteCommand(_bstr_t(csTmp)); CommInterface->WriteCommand(("ZS")); CommInterface->WriteCommand(("G")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_ABRUPT_STOPX() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("S")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_ABRUPT_STOPY() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("S")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_ABRUPT_STOPZ() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("S")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_DECEL_STOPX() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("X")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_DECEL_STOPY() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("X")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_DECEL_STOPZ() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("X")); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_COMM_CMDX(CString _command) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(_bstr_t(_command)); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_COMM_CMDY(CString _command) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(_bstr_t(_command)); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_COMM_CMDZ(CString _command) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(_bstr_t(_command)); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_COMM_RESPONSEX(CString &_response) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; _response=static_cast(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_COMM_RESPONSEY(CString &_response) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.y.address; _response=static_cast(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_COMM_RESPONSEZ(CString &_response) { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.z.address; _response=static_cast(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_HOME_STATUS_X() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(_bstr_t("Rhh")); g_machine.s_status._bXHomed=(atoi)(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_HOME_STATUS_Y() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(_bstr_t("Rhh")); g_machine.s_status._bYHomed=(atoi)(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_HOME_STATUS_Z() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(_bstr_t("Rhh")); g_machine.s_status._bZHomed=(atoi)(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_MOVE_STATUS_X() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("RBt")); g_machine.s_status._bXMoving=atoi(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_MOVE_STATUS_Y() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("RBt")); g_machine.s_status._bYMoving=atoi(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_MOVE_STATUS_Z() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("RBt")); g_machine.s_status._bZMoving=atoi(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } }; //============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_STATUS_WORD0() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("RW(0)")); g_machine.x.s_machine_status.StatusWord[0]=atoi(CommInterface->ReadResponse()); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("RW(0)")); g_machine.y.s_machine_status.StatusWord[0]=atoi(CommInterface->ReadResponse()); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("RW(0)")); g_machine.z.s_machine_status.StatusWord[0]=atoi(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } };//============================================================== SSI_STATUS_SMARTMOTOR SmartMotor_Proto::_send_cmd_SMARTMOTOR_GET_STATUS_WORD16() { try { WaitForSingleObject(g_machine_Serial_Mutex, INFINITE); CommInterface->DefaultMotor=g_machine.x.address; CommInterface->WriteCommand(("RW(16)")); g_machine.x.s_machine_status.StatusWord[1]=atoi(CommInterface->ReadResponse()); CommInterface->DefaultMotor=g_machine.y.address; CommInterface->WriteCommand(("RW(16)")); g_machine.y.s_machine_status.StatusWord[1]=atoi(CommInterface->ReadResponse()); CommInterface->DefaultMotor=g_machine.z.address; CommInterface->WriteCommand(("RW(16)")); g_machine.z.s_machine_status.StatusWord[1]=atoi(CommInterface->ReadResponse()); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_NORMAL; } catch(_com_error e) { MessageBox(NULL,e.Description(),_T("IntegMotorInterface Error!"),MB_ICONWARNING); ReleaseMutex(g_machine_Serial_Mutex); return SSI_STATUS_SMARTMOTOR_COMMERR; } };