diff --git a/.gitignore b/.gitignore index 5e53141..e3e326c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ *.licenses HSI_HexagonMI_EF3/x64/Debug/ .vscode/ +HSI_HexagonMI_EF3/obj/ +HSI_SEVENOCEAN_EF1_CsTest/bin/ diff --git a/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj b/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj index 4781a76..5cba9b4 100644 --- a/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj +++ b/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj @@ -107,7 +107,7 @@ copy "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)HSI_SEVENOCEAN_EF1_CsTest\bin\Debug\HSI.dll" -copy "$(TargetDir)$(ProjectName).dll" "C:\Hexagon\Metus2021\HSI_Sevenocean_EF3.dll" +copy "$(TargetDir)$(ProjectName).dll" "C:\Hexagon\Metus2020R1\HSI_Sevenocean_EF3.dll" copy "$(TargetDir)$(ProjectName).dll" "E:\HexagonProjects\2022-05-直线电机平台\EF3-Interfac\PcDmis\Base\Interfac\Msi\Hsi\Tools\UsbUtility\HSI_Sevenocean_EF1_WPFTest\bin\x64\Debug\HSI.dll" diff --git a/HSI_HexagonMI_EF3/HSI_Motion.cpp b/HSI_HexagonMI_EF3/HSI_Motion.cpp index 71a6813..b8d184c 100644 --- a/HSI_HexagonMI_EF3/HSI_Motion.cpp +++ b/HSI_HexagonMI_EF3/HSI_Motion.cpp @@ -81,7 +81,7 @@ void ErrorsHandler() { ErrorStr[Received] = '\0'; printf("Motion Error: %d [%s]\n", ErrorCode, ErrorStr); - g_pLogger->SendAndFlushWithTime(L"[ACS Motion] Motion Error %d%S\n", ErrorCode,ErrorStr); + g_pLogger->SendAndFlushWithTime(L"[ACS Motion] Motion Error %d%S\n", ErrorCode, ErrorStr); } } else @@ -140,7 +140,7 @@ HSI_Motion::HSI_Motion() m_IsStartInput = 0; //Ƿý̤عܣ1Ϊã0ΪرգĬ0 m_IsUsePPS = false; m_MSTRunFlag = false; //MSTб־trueMSTѾfalseMSTֹͣ - m_SendDataLength = 16; // ڷݳ + m_SendDataLength = 8; // ڷݳ m_LightType = 1; m_IsUseFourthSpeed = 0; m_ETIPort = 1; //ⲿ˿ں @@ -225,7 +225,7 @@ HSI_Motion::HSI_Motion() CString dir = L"\\Log\\" + csTime += L"_EF3.Log"; g_pLogger = new CLogger(dir); g_pLogger2 = new CLogger(L"\\Log\\EF3_SumTime.Log"); - + //λ for (int i = 0; i < 5; i++) { @@ -280,7 +280,7 @@ HSI_Motion::HSI_Motion() //Ƿ־ GetAppPath(m_AppPath); m_LogIsOpen[0] = GetPrivateProfileInt(L"LOG", L"LOG_IS_OPEN_0", 0, m_AppPath + _T("\\Config\\EF3_Motion.ini")); - g_pLogger->IsEnabledLog = m_LogIsOpen[0] == 1 ? true : false; + g_pLogger->IsEnabledLog = m_LogIsOpen[0] == 1 ? true : false; g_pLogger->SendAndFlushWithTime(L"\n"); g_pLogger->SendAndFlushWithTime(L"==========================================================\n"); @@ -432,7 +432,7 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) } #endif // OFFLINE - + m_SO7_Serial.SetTimeouts(1000, 1000); m_bConnected = true; g_pLogger->SendAndFlushWithTime(L"[Startup] Serial: [COM%d] is open success\n", m_EF3COMPort); @@ -450,8 +450,9 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) { //ԴACS g_pLogger->SendAndFlushWithTime(L"[ACS Motion] In\n"); - g_pLogger->SendAndFlushWithTime(L"[ACS Motion] Wait for opening of communication with the controller... \n"); - + g_pLogger->SendAndFlushWithTime( + L"[ACS Motion] Wait for opening of communication with the controller... \n"); + #ifdef OFFLINE //ģʽ handleACS = acsc_OpenCommSimulator(); #else @@ -475,16 +476,17 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) } #endif //ʹܵ - int Axes[] = { ACSC_AXIS_0, ACSC_AXIS_1, ACSC_AXIS_4, -1 }; - if(!acsc_EnableM(handleACS, Axes,NULL)) + int Axes[] = {ACSC_AXIS_0, ACSC_AXIS_1, ACSC_AXIS_4, -1}; + if (!acsc_EnableM(handleACS, Axes, nullptr)) { g_pLogger->SendAndFlushWithTime(L"[ACS Motion] ACS Motors Enable Failed!\n"); ErrorsHandler(); - }else + } + else { g_pLogger->SendAndFlushWithTime(L"[ACS Motion] ACS Motors Enable Success!\n"); } - + m_bACSConnected = true; g_pLogger->SendAndFlushWithTime(L"[ACS Motion] ACS Initialization Success!\n"); @@ -497,18 +499,18 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) g_pLogger->SendAndFlushWithTime(L"[ACS Motion] GET ACS Controller Version failed!\n"); ErrorsHandler(); } - Firmware[Received-1] = '\0'; + Firmware[Received - 1] = '\0'; //printf("%s", Firmware); - + //https://www.cnblogs.com/MichaelOwen/articles/2128771.html //g_pLogger->SendAndFlushWithTime(L"%s%s\n", _T("[ACS Motion] ACS Controller Version: "), L""); g_pLogger->SendAndFlushWithTime(L"[ACS Motion] ACS Controller Version: %S\n", Firmware); //ȡSPiiPlus C Library version unsigned int Ver = acsc_GetLibraryVersion(); - /* printf("SPiiPlus C Library version is %d.%d.%d.%d\n", HIBYTE(HIWORD(Ver)), LOBYTE(HIWORD(Ver)), - HIBYTE(LOWORD(Ver)), - LOBYTE(LOWORD(Ver)));*/ + /* printf("SPiiPlus C Library version is %d.%d.%d.%d\n", HIBYTE(HIWORD(Ver)), LOBYTE(HIWORD(Ver)), + HIBYTE(LOWORD(Ver)), + LOBYTE(LOWORD(Ver)));*/ g_pLogger->SendAndFlushWithTime(L"[ACS Motion] SPiiPlus C Library version is %d.%d.%d.%d\n", HIBYTE(HIWORD(Ver)), LOBYTE(HIWORD(Ver)), HIBYTE(LOWORD(Ver)), LOBYTE(LOWORD(Ver))); @@ -737,14 +739,16 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) m_Thread_State = HSI_THREAD_PAUSED; g_pLogger->SendAndFlushWithTime(L"[Startup] SetpositionXyz Enable\n"); - //CreateThreadData(); //ȡEF3״̬߳ + //ȡEF3״̬߳ + //CreateThreadData(); //SetEvent(m_hTriggerEventData); //m_Thread_StateData = HSI_THREAD_RUNNING; //g_pLogger->SendAndFlushWithTime(L"[Startup] Read EF3 Status Run\n"); + //JOGеλ˶߳ //if (m_DeviceType != 3) //{ - // CreateThreadJOGStop(); ////JOGеλ˶߳ + // CreateThreadJOGStop(); // SetEvent(m_hTriggerEventJOGStop); // m_Thread_StateJOGStop = HSI_THREAD_PAUSED; //} @@ -768,6 +772,26 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) g_pLogger->SendAndFlushWithTime(L"[Startup] m_IsProbe Enable\n"); } g_pLogger->SendAndFlushWithTime(L"[Startup] Out\n"); + + //ģʽãʱģʽ + //if (m_IsUseRocker == 1) + { + // + m_cSendData[0] = 0x01; + m_cSendData[1] = 0x06; + m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2); + Sleep(5); + + m_cSendData[0] = 0x01; + m_cSendData[1] = 0x01; + m_cSendData[2] = 0x02; + m_cSendData[3] = 0x03; + m_cSendData[4] = 0xE8; + m_WriteByte = Send_Command(0, (const char*)m_cSendData, 5); + Sleep(5); + + g_pLogger->SendAndFlushWithTime(L"[Startup] Set EF3 Timing latch Success\n"); + } } else { @@ -1047,9 +1071,8 @@ HSI_STATUS HSI_Motion::HomeMachine(bool bHomed) { return HSI_STATUS_NORMAL; } - if (g_pHSI_Motion &&(handleACS != ACSC_INVALID)) + if (g_pHSI_Motion && (handleACS != ACSC_INVALID)) { - //жǷҪؼ bool home(false); IsHomed(home); @@ -1087,14 +1110,14 @@ HSI_STATUS HSI_Motion::HomeMachine(bool bHomed) } //ȴ˶ ʽ1 - /* acsc_WaitMotionEnd(handleACS, ACSC_AXIS_1, INFINITE); - g_pLogger->SendAndFlushWithTime(L"[HomeMachine] X homed\n"); - - acsc_WaitMotionEnd(handleACS, ACSC_AXIS_0, INFINITE); - g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Y homed\n"); + /* acsc_WaitMotionEnd(handleACS, ACSC_AXIS_1, INFINITE); + g_pLogger->SendAndFlushWithTime(L"[HomeMachine] X homed\n"); - acsc_WaitMotionEnd(handleACS, ACSC_AXIS_4, INFINITE); - g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Z homed\n");*/ + acsc_WaitMotionEnd(handleACS, ACSC_AXIS_0, INFINITE); + g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Y homed\n"); + + acsc_WaitMotionEnd(handleACS, ACSC_AXIS_4, INFINITE); + g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Z homed\n");*/ //ȴ˶ ʽ2 do @@ -1102,9 +1125,9 @@ HSI_STATUS HSI_Motion::HomeMachine(bool bHomed) //ٴζȡؼұ־λϸɻص IsHomed(home); Sleep(200); + } + while (!home); - } while (!home); - g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Go Home success\n"); g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Out\n"); } @@ -1481,7 +1504,7 @@ HSI_STATUS HSI_Motion::IsHomed(bool& bHomed) rStatus = HSI_STATUS_FAILED; bHomed = false; } - + g_pLogger->SendAndFlushWithTime(L"[IsHomed] ACS Read YAW_HOME_DONE X:[%d] Y:[%d] Z:[%d]\n", isHomed[0], isHomed[1], isHomed[2]); @@ -1581,7 +1604,7 @@ HSI_STATUS HSI_Motion::JogOld(UINT AxisTypes, double Speed) int DecCurve(1); int JogSpeed(1); bool bJOGDir = Speed > 0 ? true : false; - byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes));//JogOld + byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes)); //JogOld jogAxisNum = AxisNumber; jogDirFlag = bJOGDir; m_Thread_State = HSI_THREAD_PAUSED; @@ -1870,7 +1893,7 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) int DecCurve(1); int JogSpeed(1); bool bJOGDir = Speed > 0 ? true : false; //˶ - byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes));//Jog + byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes)); //Jog jogAxisNum = AxisNumber; jogDirFlag = bJOGDir; m_Thread_State = HSI_THREAD_PAUSED; @@ -1891,24 +1914,26 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) //Ƿعж if (m_Home_Machine_Axis[AxisNumber] == 0) { - g_pLogger->SendAndFlushWithTime(L"[Jog] Current Axis[%d] not homed \n",AxisNumber); + g_pLogger->SendAndFlushWithTime(L"[Jog] Current Axis[%d] not homed \n", AxisNumber); return rStatus; } // JOG˶ Ӽ JOG_SPEED_ACC_DEC - double now_pos[5] = { 0 }; - double Prf_pos[5] = { 0 }; - double limitpos[4] = { 0 }; + double now_pos[5] = {0}; + double Prf_pos[5] = {0}; + double limitpos[4] = {0}; int RemainPul = 0; int limitSDPul = 0; double time; /*GetPositionXyz(1, now_pos[0], now_pos[1], now_pos[2], time);*/ //GetPositionEncPrfMulti(1, now_pos, Prf_pos, 1); - + JogSpeed = abs(SpeedPercent(AxisNumber, Speed, DriveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve)); - g_pLogger->SendAndFlushWithTime(L"[Jog] Speed: [%d], DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n", Speed, DriveSpeed, AccCurve, AccLine, DecCurve, DecLine); + g_pLogger->SendAndFlushWithTime( + L"[Jog] Speed: [%d], DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n", + Speed, DriveSpeed, AccCurve, AccLine, DecCurve, DecLine); if (m_DeviceType != 3) { @@ -2014,7 +2039,9 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) } //ٶ - g_pLogger->SendAndFlushWithTime(L"[Jog] StartSpeed: [%d], DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n", StartSpeed, DriveSpeed, AccCurve, AccLine, DecCurve, DecLine); + g_pLogger->SendAndFlushWithTime( + L"[Jog] StartSpeed: [%d], DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n", + StartSpeed, DriveSpeed, AccCurve, AccLine, DecCurve, DecLine); // ͣж if ((StartSpeed < 250) && (DriveSpeed < 6)) @@ -2027,7 +2054,7 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) } //ӡǰٶ - double motionParam[5] = { 0 }; + double motionParam[5] = {0}; GetMotorParam(jogAxisNum, motionParam); g_pLogger->SendAndFlushWithTime( L"[Jog] Axis= %d, Velocity = %.2f, Acceleration= %.2f, Deceleration= %.2f, KillDeceleration= %.2f, Jerk= %.2f\n", @@ -2041,8 +2068,9 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) //int acsDirection = bJOGDir ? ACSC_POSITIVE_DIRECTION : ACSC_NEGATIVE_DIRECTION; //򣬻 if (!acsc_Jog(handleACS, 0, jogAxisNum, StartSpeed, nullptr)) { - printf("[Jog] [%d] [%s] ƶʧ", AxisTypes, bJOGDir? "" : ""); - g_pLogger->SendAndFlushWithTime(L"[Jog] failed, Aixs:[%d] JOGDir:[%S]\n", AxisTypes, bJOGDir ? "Positive" : "Negative"); + printf("[Jog] [%d] [%s] ƶʧ", AxisTypes, bJOGDir ? "" : ""); + g_pLogger->SendAndFlushWithTime(L"[Jog] failed, Aixs:[%d] JOGDir:[%S]\n", AxisTypes, + bJOGDir ? "Positive" : "Negative"); ErrorsHandler(); } @@ -2073,7 +2101,7 @@ HSI_STATUS HSI_Motion::JoyStick(UINT AxisTypes, long Speed) int DecCurve(1); int JogSpeed(1); bool bJOGDir = Speed > 0 ? true : false; - byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes));//JoyStick + byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes)); //JoyStick jogAxisNum = AxisNumber; jogDirFlag = bJOGDir; m_Thread_State = HSI_THREAD_PAUSED; @@ -2369,7 +2397,7 @@ HSI_STATUS HSI_Motion::StopJogOld() g_pLogger->SendAndFlushWithTime(L"[StopJog] PushButtonTime = %d\n", t_use); Sleep(t_use); } - unsigned char m_SendJogData[64] = { 0 }; + unsigned char m_SendJogData[64] = {0}; if (m_IsUseJerk == 0) { m_SendJogData[0] = CT_MOTOR; @@ -2441,10 +2469,10 @@ HSI_STATUS HSI_Motion::StopJog() m_WriteByte = Send_Command(0, (const char*)m_SendJogData, m_SendDataLength); }*/ - int Axes[] = { ACSC_AXIS_0, ACSC_AXIS_1, ACSC_AXIS_4, -1 }; - if(handleACS !=ACSC_INVALID) + int Axes[] = {ACSC_AXIS_0, ACSC_AXIS_1, ACSC_AXIS_4, -1}; + if (handleACS != ACSC_INVALID) { - if(!acsc_HaltM(handleACS, Axes, NULL))//ֹͣJOG˶ + if (!acsc_HaltM(handleACS, Axes, nullptr)) //ֹͣJOG˶ { g_pLogger->SendAndFlushWithTime(L"[StopJog] ACS acsc_HaltM error!\n"); ErrorsHandler(); @@ -2542,7 +2570,7 @@ HSI_STATUS HSI_Motion::GetPositionEncPrfMultiOld(UINT AxisTypes, double* EncPos, CString tempStr; if (g_pHSI_Motion) { - g_pLogger->SendAndFlushWithTime(L"[GetPositionEncPrfMulti] In\n"); + g_pLogger->SendAndFlushWithTime(L"[GetPositionEncPrfMulti] In\n"); if (m_SO7_Serial.m_RecvData[0] == 2) { EncPos[1] = (m_SO7_Serial.m_RecvData[1] << 24 | m_SO7_Serial.m_RecvData[2] << 16 | m_SO7_Serial.m_RecvData[ @@ -2606,6 +2634,7 @@ HSI_STATUS HSI_Motion::GetPositionEncPrfMultiOld(UINT AxisTypes, double* EncPos, } return rStatus; } + HSI_STATUS HSI_Motion::GetPositionEncPrfMulti(UINT AxisTypes, double* EncPos, double* PrfPos, int Count) { auto rStatus = HSI_STATUS_NORMAL; @@ -2618,48 +2647,48 @@ HSI_STATUS HSI_Motion::GetPositionEncPrfMulti(UINT AxisTypes, double* EncPos, do { EncPos[1] = (m_SO7_Serial.m_RecvData[1] << 24 | m_SO7_Serial.m_RecvData[2] << 16 | m_SO7_Serial.m_RecvData[ 3] << 8 | m_SO7_Serial.m_RecvData[4]) * m_Resolution[1]; - EncPos[2] = (m_SO7_Serial.m_RecvData[5] << 24 | m_SO7_Serial.m_RecvData[6] << 16 | m_SO7_Serial.m_RecvData[ - 7] << 8 | m_SO7_Serial.m_RecvData[8]) * m_Resolution[2]; - EncPos[3] = (m_SO7_Serial.m_RecvData[9] << 24 | m_SO7_Serial.m_RecvData[10] << 16 | m_SO7_Serial.m_RecvData[ - 11] << 8 | m_SO7_Serial.m_RecvData[12]) * m_Resolution[3]; - EncPos[4] = (m_SO7_Serial.m_RecvData[13] << 24 | m_SO7_Serial.m_RecvData[14] << 16 | m_SO7_Serial.m_RecvData - [15] << 8 | m_SO7_Serial.m_RecvData[16]) * m_Resolution[4]; + EncPos[2] = (m_SO7_Serial.m_RecvData[5] << 24 | m_SO7_Serial.m_RecvData[6] << 16 | m_SO7_Serial.m_RecvData[ + 7] << 8 | m_SO7_Serial.m_RecvData[8]) * m_Resolution[2]; + EncPos[3] = (m_SO7_Serial.m_RecvData[9] << 24 | m_SO7_Serial.m_RecvData[10] << 16 | m_SO7_Serial.m_RecvData[ + 11] << 8 | m_SO7_Serial.m_RecvData[12]) * m_Resolution[3]; + EncPos[4] = (m_SO7_Serial.m_RecvData[13] << 24 | m_SO7_Serial.m_RecvData[14] << 16 | m_SO7_Serial.m_RecvData + [15] << 8 | m_SO7_Serial.m_RecvData[16]) * m_Resolution[4]; - PrfPos[1] = (m_SO7_Serial.m_RecvData[17] << 24 | m_SO7_Serial.m_RecvData[18] << 16 | m_SO7_Serial.m_RecvData - [19] << 8 | m_SO7_Serial.m_RecvData[20]) * m_Resolution[1]; - PrfPos[2] = (m_SO7_Serial.m_RecvData[21] << 24 | m_SO7_Serial.m_RecvData[22] << 16 | m_SO7_Serial.m_RecvData - [23] << 8 | m_SO7_Serial.m_RecvData[24]) * m_Resolution[2]; - PrfPos[3] = (m_SO7_Serial.m_RecvData[25] << 24 | m_SO7_Serial.m_RecvData[26] << 16 | m_SO7_Serial.m_RecvData - [27] << 8 | m_SO7_Serial.m_RecvData[28]) * m_Resolution[3]; - PrfPos[4] = (m_SO7_Serial.m_RecvData[29] << 24 | m_SO7_Serial.m_RecvData[30] << 16 | m_SO7_Serial.m_RecvData - [31] << 8 | m_SO7_Serial.m_RecvData[32]) * m_Resolution[4]; + PrfPos[1] = (m_SO7_Serial.m_RecvData[17] << 24 | m_SO7_Serial.m_RecvData[18] << 16 | m_SO7_Serial.m_RecvData + [19] << 8 | m_SO7_Serial.m_RecvData[20]) * m_Resolution[1]; + PrfPos[2] = (m_SO7_Serial.m_RecvData[21] << 24 | m_SO7_Serial.m_RecvData[22] << 16 | m_SO7_Serial.m_RecvData + [23] << 8 | m_SO7_Serial.m_RecvData[24]) * m_Resolution[2]; + PrfPos[3] = (m_SO7_Serial.m_RecvData[25] << 24 | m_SO7_Serial.m_RecvData[26] << 16 | m_SO7_Serial.m_RecvData + [27] << 8 | m_SO7_Serial.m_RecvData[28]) * m_Resolution[3]; + PrfPos[4] = (m_SO7_Serial.m_RecvData[29] << 24 | m_SO7_Serial.m_RecvData[30] << 16 | m_SO7_Serial.m_RecvData + [31] << 8 | m_SO7_Serial.m_RecvData[32]) * m_Resolution[4]; - if (m_IsHavePattern & 0x01) - m_EncPos[1] = EncPos[1]; - else - m_EncPos[1] = PrfPos[1]; - if (m_IsHavePattern & 0x02) - m_EncPos[2] = EncPos[2]; - else - m_EncPos[2] = PrfPos[2]; - if (m_IsHavePattern & 0x04) - m_EncPos[3] = EncPos[3]; - else - m_EncPos[3] = PrfPos[3]; - if (m_IsHavePattern & 0x08) - m_EncPos[4] = EncPos[4]; - else - m_EncPos[4] = PrfPos[4]; + if (m_IsHavePattern & 0x01) + m_EncPos[1] = EncPos[1]; + else + m_EncPos[1] = PrfPos[1]; + if (m_IsHavePattern & 0x02) + m_EncPos[2] = EncPos[2]; + else + m_EncPos[2] = PrfPos[2]; + if (m_IsHavePattern & 0x04) + m_EncPos[3] = EncPos[3]; + else + m_EncPos[3] = PrfPos[3]; + if (m_IsHavePattern & 0x08) + m_EncPos[4] = EncPos[4]; + else + m_EncPos[4] = PrfPos[4]; - m_PrfPos[1] = PrfPos[1]; - m_PrfPos[2] = PrfPos[2]; - m_PrfPos[3] = PrfPos[3]; - m_PrfPos[4] = PrfPos[4]; + m_PrfPos[1] = PrfPos[1]; + m_PrfPos[2] = PrfPos[2]; + m_PrfPos[3] = PrfPos[3]; + m_PrfPos[4] = PrfPos[4]; - //begin_position[1] = EncPos[1] / m_Resolution[1]; - //begin_position[2] = EncPos[2] / m_Resolution[1]; - //begin_position[3] = EncPos[3] / m_Resolution[1]; - //begin_position[4] = EncPos[4] / m_Resolution[1]; + //begin_position[1] = EncPos[1] / m_Resolution[1]; + //begin_position[2] = EncPos[2] / m_Resolution[1]; + //begin_position[3] = EncPos[3] / m_Resolution[1]; + //begin_position[4] = EncPos[4] / m_Resolution[1]; } else { @@ -2677,6 +2706,7 @@ HSI_STATUS HSI_Motion::GetPositionEncPrfMulti(UINT AxisTypes, double* EncPos, do } return rStatus; } + //=========================================================================== /** * \brief ȡᵱǰ˶λ @@ -3495,7 +3525,9 @@ HSI_STATUS HSI_Motion::SetPositionXyz(UINT AxisTypes, double PositionX, double P LimitOver(HSI_MOTION_AXIS_Y, PositionY); LimitOver(HSI_MOTION_AXIS_Z, PositionZ); LimitOver(HSI_MOTION_AXIS_R, m_PositionA); - g_pLogger->SendAndFlushWithTime(L"[SetPositionXyz] LimitOver, Pos[1] = %.4f, Pos[2] = %.4f, Pos[3] = %.4f, m_PositionA = %.4f\n",PositionX, PositionY, PositionZ, m_PositionA); + g_pLogger->SendAndFlushWithTime( + L"[SetPositionXyz] LimitOver, Pos[1] = %.4f, Pos[2] = %.4f, Pos[3] = %.4f, m_PositionA = %.4f\n", + PositionX, PositionY, PositionZ, m_PositionA); //SetpositionXyzĿλ m_PosThread[1] = PositionX; @@ -3504,16 +3536,16 @@ HSI_STATUS HSI_Motion::SetPositionXyz(UINT AxisTypes, double PositionX, double P m_PosThread[4] = m_PositionA; //ӡǰλãĿλ - /* g_pLogger->SendAndFlushWithTime( - L"[SetPositionXyzNowPos] Pos[1] = %.4f,Pos[2] = %.4f,Pos[3] = %.4f,Pos[4] = %.4f, Resolution[1] = %.4f\n", - m_PosThread[1] * m_Resolution[1], m_PosThread[2] * m_Resolution[2], m_PosThread[3] * m_Resolution[3], - m_PosThread[4] * m_Resolution[4], m_Resolution[1]); - g_pLogger->SendAndFlushWithTime( - L"[SetPositionXyzTagPos] Pos[1] = %.4f, Pos[2] = %.4f, Pos[3] = %.4f\n", PositionX, - PositionY, PositionZ);*/ + /* g_pLogger->SendAndFlushWithTime( + L"[SetPositionXyzNowPos] Pos[1] = %.4f,Pos[2] = %.4f,Pos[3] = %.4f,Pos[4] = %.4f, Resolution[1] = %.4f\n", + m_PosThread[1] * m_Resolution[1], m_PosThread[2] * m_Resolution[2], m_PosThread[3] * m_Resolution[3], + m_PosThread[4] * m_Resolution[4], m_Resolution[1]); + g_pLogger->SendAndFlushWithTime( + L"[SetPositionXyzTagPos] Pos[1] = %.4f, Pos[2] = %.4f, Pos[3] = %.4f\n", PositionX, + PositionY, PositionZ);*/ //ӡᵱǰ˶ - byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes));//Ż + byte AxisNumber = static_cast(AxisConvertIndex(AxisTypes)); //Ż double motionParam[5] = {0}; GetMotorParam(AxisNumber, motionParam); g_pLogger->SendAndFlushWithTime( @@ -3526,7 +3558,7 @@ HSI_STATUS HSI_Motion::SetPositionXyz(UINT AxisTypes, double PositionX, double P //ʼ˶ָλã˶ int Axes[] = {ACSC_AXIS_0, ACSC_AXIS_1,ACSC_AXIS_4, -1}; //Ҫ˶ double Points[] = {PositionY, PositionX, PositionZ}; //Ŀλõ - if (!acsc_ToPointM(handleACS, 0, Axes, Points, nullptr))//ƶλ + if (!acsc_ToPointM(handleACS, 0, Axes, Points, nullptr)) //ƶλ { g_pLogger->SendAndFlushWithTime(L"[SetPositionXyz] ACS Multi Motion Error\n"); ErrorsHandler(); @@ -3617,32 +3649,32 @@ HSI_STATUS HSI_Motion::GetMotorParam(int AXIS, double motionParam[5]) g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] In\n"); // ٶȡٶȡ١ɱٶȡ - if (!acsc_GetVelocity(handleACS, AXIS, motionParam+0, nullptr)) + if (!acsc_GetVelocity(handleACS, AXIS, motionParam + 0, nullptr)) { g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetVelocity error\n"); rStatus = HSI_ACS_ERROR; ErrorsHandler(); } - if (!acsc_GetAcceleration(handleACS, AXIS, motionParam+1, nullptr)) + if (!acsc_GetAcceleration(handleACS, AXIS, motionParam + 1, nullptr)) { g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetAcceleration error\n"); rStatus = HSI_ACS_ERROR; ErrorsHandler(); } - if (!acsc_GetDeceleration(handleACS, AXIS, motionParam+2, nullptr)) + if (!acsc_GetDeceleration(handleACS, AXIS, motionParam + 2, nullptr)) { g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetDeceleration error\n"); rStatus = HSI_ACS_ERROR; ErrorsHandler(); } - if (!acsc_GetKillDeceleration(handleACS, AXIS, motionParam+3, nullptr)) + if (!acsc_GetKillDeceleration(handleACS, AXIS, motionParam + 3, nullptr)) { g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetKillDeceleration error\n"); rStatus = HSI_ACS_ERROR; ErrorsHandler(); } - if (!acsc_GetJerk(handleACS, AXIS, motionParam+4, nullptr)) + if (!acsc_GetJerk(handleACS, AXIS, motionParam + 4, nullptr)) { g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetJerk error\n"); rStatus = HSI_ACS_ERROR; @@ -3916,7 +3948,7 @@ HSI_STATUS HSI_Motion::Load_EF3_Motion_Inifile(CString GoogolIniFile) csAppPath); m_SpeedMax[i] = GetPrivateProfileInt(L"SET_POSITION_SPEED", L"SPEED_RUNMAX_" + axisNum[i], 150, csAppPath); } - for (int i = 0; i < 5; i++)// i + for (int i = 0; i < 5; i++) // i { for (int j = 1; j < 5; j++) //j λ { @@ -3925,12 +3957,14 @@ HSI_STATUS HSI_Motion::Load_EF3_Motion_Inifile(CString GoogolIniFile) float speed = (atof(T2A(temp))); /*m_JogDriveSpeed[j][i] = GetPrivateProfileInt(L"JOG_SPEED", L"JOG_DRIVESPEED_" , 10, csAppPath);*/ m_JogDriveSpeed[j][i] = speed / (m_Resolution[j] * 50); - g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_JogDriveSpeed[%d][%d]: %.4f %ld\n", i,j,speed,m_JogDriveSpeed[i][j]);//ӡļ λٶ - + g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_JogDriveSpeed[%d][%d]: %.4f %ld\n", i, j, + speed, m_JogDriveSpeed[i][j]); //ӡļ λٶ + GetPrivateProfileString(L"JOG_SPEED", L"JOG_STARTSPEED_" + strGear[i] + axisNum[j], L"10", temp.GetBufferSetLength(50), 10, csAppPath); speed = (atof(T2A(temp))); - m_JogStartSpeed[j][i] = GetPrivateProfileInt(L"JOG_SPEED", L"JOG_STARTSPEED_" + strGear[i] + axisNum[j], 10, csAppPath); + m_JogStartSpeed[j][i] = GetPrivateProfileInt(L"JOG_SPEED", L"JOG_STARTSPEED_" + strGear[i] + axisNum[j], + 10, csAppPath); //m_JogStartSpeed[j][i] = speed / (m_Resolution[j] * 50); m_JogAccLine[j][i] = GetPrivateProfileInt(L"JOG_SPEED", L"JOG_LINE_" + strGear[i] + axisNum[j], 10, csAppPath); @@ -4233,7 +4267,7 @@ void HSI_Motion::UpdateMotionState() 0, m_precisionCount[1], m_precisionCount[2], m_precisionCount[3], m_precisionCount[4] }; //ʱҪԭѡ,ȡؼ - tempPrecision[1] = m_Home_Machine_Axis[1] == 0 ? 10000000 : m_precisionCount[1]; + tempPrecision[1] = m_Home_Machine_Axis[1] == 0 ? 10000000 : m_precisionCount[1]; tempPrecision[2] = m_Home_Machine_Axis[2] == 0 ? 10000000 : m_precisionCount[2]; tempPrecision[3] = m_Home_Machine_Axis[3] == 0 ? 10000000 : m_precisionCount[3]; tempPrecision[4] = m_Home_Machine_Axis[4] == 0 ? 10000000 : m_precisionCount[4]; @@ -4258,7 +4292,7 @@ void HSI_Motion::UpdateMotionState() //-----------TEST End-------------------- //Ŀλ ͵ǰλ Сڻؼ - + if ((fabs(m_PosThread[1] - prfpos[1]) <= tempPrecision[1] * m_Resolution[1]) && ( fabs(m_PosThread[2] - prfpos[2]) <= tempPrecision[2] * m_Resolution[2]) && ( fabs(m_PosThread[3] - prfpos[3]) <= tempPrecision[3] * m_Resolution[3]) && (fabs( @@ -4324,7 +4358,9 @@ void HSI_Motion::UpdateMotionState() g_pLogger->SendAndFlushWithTime( L"[UpdateMotionState] m_PosThread[1] = %.4f,m_PosThread[2] = %.4f,m_PosThread[3] = %.4f\n", m_PosThread[1], m_PosThread[2], m_PosThread[3]); - g_pLogger->SendAndFlushWithTime(L"[UpdateMotionState] Pos[1] = %.4f,Pos[2] = %.4f,Pos[3] = %.4f PntToPntDistance = %.4f\n",prfpos[1], prfpos[2], prfpos[3], PntToPntDistance); + g_pLogger->SendAndFlushWithTime( + L"[UpdateMotionState] Pos[1] = %.4f,Pos[2] = %.4f,Pos[3] = %.4f PntToPntDistance = %.4f\n", prfpos[1], + prfpos[2], prfpos[3], PntToPntDistance); if (timeoutflag) //λʱ { @@ -4851,6 +4887,7 @@ HSI_STATUS HSI_Motion::GetDIOOld(UINT IOChannel, UINT& _Status) } return rStatus; } + HSI_STATUS HSI_Motion::GetDIO(UINT IOChannel, UINT& _Status) { auto rStatus = HSI_STATUS_NORMAL; @@ -4910,6 +4947,7 @@ HSI_STATUS HSI_Motion::GetDIO(UINT IOChannel, UINT& _Status) //-----------TEST End------------------ return rStatus; } + //=========================================================================== /** * \brief @@ -4970,6 +5008,7 @@ HSI_STATUS HSI_Motion::SetDIOOld(UINT IOChannel, UINT _Status) } return rStatus; } + HSI_STATUS HSI_Motion::SetDIO(UINT IOChannel, UINT _Status) { auto rStatus = HSI_STATUS_NORMAL; @@ -5029,6 +5068,7 @@ HSI_STATUS HSI_Motion::SetDIO(UINT IOChannel, UINT _Status) //-----------TEST End------------------ return rStatus; } + //=========================================================================== HSI_STATUS HSI_Motion::GetAxisStatus(int* _Status) { @@ -5093,10 +5133,10 @@ HSI_STATUS HSI_Motion::AbortMotion() // g_IsClose = true; g_pLogger->SendAndFlushWithTime(L"[AbortMotion] In\n"); - int Axes[] = { ACSC_AXIS_0, ACSC_AXIS_1, ACSC_AXIS_4, -1 }; + int Axes[] = {ACSC_AXIS_0, ACSC_AXIS_1, ACSC_AXIS_4, -1}; if (handleACS != ACSC_INVALID) { - if (!acsc_HaltM(handleACS, Axes, NULL))//ֹͣJOG˶ + if (!acsc_HaltM(handleACS, Axes, nullptr)) //ֹͣJOG˶ { g_pLogger->SendAndFlushWithTime(L"[AbortMotion] ACS acsc_HaltM error!\n"); ErrorsHandler(); @@ -5106,6 +5146,7 @@ HSI_STATUS HSI_Motion::AbortMotion() // } return rStatus; } + //=========================================================================== /** * \brief ر @@ -5266,7 +5307,7 @@ HSI_STATUS HSI_Motion::DCCPPStartPoint(double* startPoint) } //=========================================================================== -HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis) +HSI_STATUS HSI_Motion::DCCScanSetDataOld(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis) { WaitForSingleObject(g_WR_ToMove_Mutex, INFINITE); auto rStatus = HSI_STATUS_NORMAL; @@ -5687,8 +5728,431 @@ HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType return rStatus; } +HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis) +{ + WaitForSingleObject(g_WR_ToMove_Mutex, INFINITE); + auto rStatus = HSI_STATUS_NORMAL; + if (g_pHSI_Motion) + { + //λΪλ,÷һƶλãٿʼôλ(λ)յλ + g_pLogger->SendAndFlushWithTime(L"[DCCScanSetData] In AxisTypes:%d eType:%d lTrigNumber:%d dTrigDis:ld\n", + AxisTypes, eType, lTrigNumber, dTrigDis); + int axisNum; + unsigned char m_SendDCCData[64] = {0}; + m_SendDCCData[0] = CT_MOTOR; + m_SendDCCData[1] = CT_TRIGGER_DATA; + m_SendDCCData[2] = 0x01; + iTriggleNum = lTrigNumber; + double limit = 0.0; + //memset(m_cSendData,0,64); + if (AxisTypes & HSI_MOTION_AXIS_X) + { + iaxisNum = AXIS_X; + axisNum = 1; + } + else if (AxisTypes & HSI_MOTION_AXIS_Y) + { + iaxisNum = AXIS_Y; + axisNum = 2; + } + else if (AxisTypes & HSI_MOTION_AXIS_Z) + { + iaxisNum = AXIS_Z; + axisNum = 3; + } + else + { + iaxisNum = AXIS_X; + axisNum = 1; + } + switch (eType) + { + case HSI_SCAN_MOTION_SPEC_LOCA: + { + if (dTrigDis[0] > 0.0001) + { + iMotionDirection = 0; + } + else + { + iMotionDirection = 1; + } + + switch (iaxisNum) + { + case AXIS_X: + { + if (!m_IsUsePPS) + { + begin_position[1] = begin_position[1] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[1] = begin_position[1] - 20; + } + else + { + begin_position[1] = begin_position[1] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000.0; + } + else + { + limit = -1000.0; + } + break; + } + case AXIS_Y: + { + if (!m_IsUsePPS) + { + begin_position[2] = begin_position[2] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[2] = begin_position[2] - 20; + } + else + { + begin_position[2] = begin_position[2] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000.0; + } + else + { + limit = -1000.0; + } + break; + } + case AXIS_Z: + { + if (!m_IsUsePPS) + { + begin_position[3] = begin_position[3] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[3] = begin_position[3] - 20; + } + else + { + begin_position[3] = begin_position[3] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000.0; + } + else + { + limit = -1000.0; + } + break; + } + default: + break; + } + + iScanMotionType = HSI_SCAN_MOTION_SPEC_LOCA; + if (lTrigNumber > 100) + { + return HSI_STATUS_FAILED; + } + int num = lTrigNumber / 14; + int i = 0; + for (i = 0; i < num; i++) + { + m_SendDCCData[3] = i; + for (size_t j = 14 * i, z = 4; j < 14 * (i + 1); ++j) + { + m_SendDCCData[z++] = static_cast(dTrigDis[j] / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[z++] = (static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[z++] = (static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[z++] = static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 24; + } + m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + Sleep(1); + } + if ((num > 0) && (lTrigNumber % 14 != 0)) + { + m_SendDCCData[3] = i; + int j = 0, z = 0; + for (j = 14 * i, z = 4; j < lTrigNumber; ++j) + { + m_SendDCCData[z++] = static_cast(dTrigDis[j] / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[z++] = (static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[z++] = (static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[z++] = static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 24; + } + m_SendDCCData[z++] = static_cast(limit / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[z++] = (static_cast(limit / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[z++] = (static_cast(limit / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[z++] = static_cast(limit / m_Resolution[axisNum]) >> 24; + m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + Sleep(10); + } + else if (num == 0) + { + m_SendDCCData[3] = 0; + int j = 0, z = 0; + for (j = 0, z = 4; j < lTrigNumber; ++j) + { + m_SendDCCData[z++] = static_cast(dTrigDis[j] / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[z++] = (static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[z++] = (static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[z++] = static_cast(dTrigDis[j] / m_Resolution[axisNum]) >> 24; + } + m_SendDCCData[z++] = static_cast(limit / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[z++] = (static_cast(limit / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[z++] = (static_cast(limit / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[z++] = static_cast(limit / m_Resolution[axisNum]) >> 24; + m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + Sleep(10); + } + break; + } + case HSI_SCAN_MOTION_EQ_DIS: + { + if (dTrigDis[0] > 0.0001) + { + iMotionDirection = 0; + } + else + { + iMotionDirection = 1; + } + switch (iaxisNum) + { + case AXIS_X: + { + if (!m_IsUsePPS) + { + begin_position[1] = begin_position[1] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[1] = begin_position[1] - 20; + } + else + { + begin_position[1] = begin_position[1] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000; + } + else + { + limit = -1000; + } + break; + } + case AXIS_Y: + { + if (!m_IsUsePPS) + { + begin_position[2] = begin_position[2] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[2] = begin_position[2] - 20; + } + else + { + begin_position[2] = begin_position[2] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000; + } + else + { + limit = -1000; + } + break; + } + case AXIS_Z: + { + if (!m_IsUsePPS) + { + begin_position[3] = begin_position[3] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[3] = begin_position[3] - 20; + } + else + { + begin_position[3] = begin_position[3] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000; + } + else + { + limit = -1000; + } + break; + } + default: + break; + } + iScanMotionType = HSI_SCAN_MOTION_EQ_DIS; + m_SendDCCData[3] = 0x00; + m_SendDCCData[4] = static_cast(dTrigDis[0] / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[5] = (static_cast(dTrigDis[0] / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[6] = (static_cast(dTrigDis[0] / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[7] = static_cast(dTrigDis[0] / m_Resolution[axisNum]) >> 24; + m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + Sleep(10); + break; + } + case HSI_SCAN_MOTION_EQ_DIS_II: + { + if (dTrigDis[1] > 0.0001) + { + iMotionDirection = 0; + } + else + { + iMotionDirection = 1; + } + + switch (iaxisNum) + { + case AXIS_X: + { + if (!m_IsUsePPS) + { + begin_position[1] = begin_position[1] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[1] = begin_position[1] - 20; + } + else + { + begin_position[1] = begin_position[1] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000; + } + else + { + limit = -1000; + } + break; + } + case AXIS_Y: + { + if (!m_IsUsePPS) + { + begin_position[2] = begin_position[2] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[2] = begin_position[2] - 20; + } + else + { + begin_position[2] = begin_position[2] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000; + } + else + { + limit = -1000; + } + break; + } + case AXIS_Z: + { + if (!m_IsUsePPS) + { + begin_position[3] = begin_position[3] + dTrigDis[0] / m_Resolution[axisNum]; + } + else + { + if (iMotionDirection == 0) + { + begin_position[3] = begin_position[3] - 20; + } + else + { + begin_position[3] = begin_position[3] + 20; + } + } + if (iMotionDirection == 0) + { + limit = 1000; + } + else + { + limit = -1000; + } + break; + } + default: + break; + } + + iScanMotionType = HSI_SCAN_MOTION_EQ_DIS_II; + m_SendDCCData[3] = 0x00; + int i = 0, j = 0; + for (i = 0, j = 4; i < 2; ++i) + { + m_SendDCCData[j++] = static_cast(dTrigDis[i] / m_Resolution[axisNum]) & 0xff; + m_SendDCCData[j++] = (static_cast(dTrigDis[i] / m_Resolution[axisNum]) >> 8) & 0xff; + m_SendDCCData[j++] = (static_cast(dTrigDis[i] / m_Resolution[axisNum]) >> 16) & 0xff; + m_SendDCCData[j++] = static_cast(dTrigDis[i] / m_Resolution[axisNum]) >> 24; + } + m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + g_pLogger->SendAndFlushWithTime(L"[DCCScanSetData] Send_Command: %s\n", (const char*)m_SendDCCData); + Sleep(10); + break; + } + default: + break; + } + g_pLogger->SendAndFlushWithTime(L"[DCCScanSetData] Out\n"); + } + ReleaseMutex(g_WR_ToMove_Mutex); + return rStatus; +} + //=========================================================================== -HSI_STATUS HSI_Motion::DCCScanStart() +HSI_STATUS HSI_Motion::DCCScanStartOld() { WaitForSingleObject(g_WR_ToMove_Mutex, INFINITE); auto rStatus = HSI_STATUS_NORMAL; @@ -5750,8 +6214,79 @@ HSI_STATUS HSI_Motion::DCCScanStart() return rStatus; } +HSI_STATUS HSI_Motion::DCCScanStart() +{ + WaitForSingleObject(g_WR_ToMove_Mutex, INFINITE); + auto rStatus = HSI_STATUS_NORMAL; + if (g_pHSI_Motion) + { + if (!setLightFlag) + { + unsigned char m_SetTriggerLightData[64] = {0}; + m_SetTriggerLightData[0] = CT_LIGHT; + m_SetTriggerLightData[1] = 0x03; + m_SetTriggerLightData[53] = 0; + m_WriteByte = Send_Command(0, (const char*)m_SetTriggerLightData, m_SendDataLength); + Sleep(1); + } + setLightFlag = false; + g_pLogger->SendAndFlushWithTime(L"[DCCScanStart] In\n"); + unsigned char m_SendDCCData[64] = {0}; + m_SendDCCData[0] = CT_MOTOR; + m_SendDCCData[1] = CT_TRIGGER_DATA; + m_SendDCCData[2] = 0x00; + m_SendDCCData[3] = iaxisNum; + m_SendDCCData[4] = iScanMotionType; + m_SendDCCData[5] = ((iTriggleNum) & 0xff); + m_SendDCCData[6] = (iTriggleNum >> 8) & 0xff; + m_SendDCCData[7] = iMotionDirection; + switch (iaxisNum) + { + case AXIS_X: m_SendDCCData[8] = begin_position[1] & 0xff; + m_SendDCCData[9] = (begin_position[1] >> 8) & 0xff; + m_SendDCCData[10] = (begin_position[1] >> 16) & 0xff; + m_SendDCCData[11] = (begin_position[1] >> 24) & 0xff; + m_SendDCCData[12] = m_SetPotion_DriveSpeed[1] & 0xff; + m_SendDCCData[13] = (m_SetPotion_DriveSpeed[1] >> 8) & 0xff; + break; + case AXIS_Y: m_SendDCCData[8] = begin_position[2] & 0xff; + m_SendDCCData[9] = (begin_position[2] >> 8) & 0xff; + m_SendDCCData[10] = (begin_position[2] >> 16) & 0xff; + m_SendDCCData[11] = (begin_position[2] >> 24) & 0xff; + m_SendDCCData[12] = m_SetPotion_DriveSpeed[2] & 0xff; + m_SendDCCData[13] = (m_SetPotion_DriveSpeed[2] >> 8) & 0xff; + break; + case AXIS_Z: + m_SendDCCData[8] = begin_position[3] & 0xff; + m_SendDCCData[9] = (begin_position[3] >> 8) & 0xff; + m_SendDCCData[10] = (begin_position[3] >> 16) & 0xff; + m_SendDCCData[11] = (begin_position[3] >> 24) & 0xff; + m_SendDCCData[12] = m_SetPotion_DriveSpeed[3] & 0xff; + m_SendDCCData[13] = (m_SetPotion_DriveSpeed[3] >> 8) & 0xff; + break; + default: + break; + } + g_pLogger->SendAndFlushWithTime( + L"[DCCScanStart] iaxisNum:%d, iTriggleNum:%d, iMotionDirection:%d,begin_position:%d \n", iaxisNum, + iTriggleNum, iMotionDirection, begin_position); + //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + + + unsigned char m_cSendData[64] = {0}; + m_cSendData[0] = 0x01; + m_cSendData[1] = 0x02; + m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2); + Sleep(2); + g_pLogger->SendAndFlushWithTime(L"[DCCScanStart] Out\n"); + m_IsUsePPS = false; + } + ReleaseMutex(g_WR_ToMove_Mutex); + return rStatus; +} + //=========================================================================== -HSI_STATUS HSI_Motion::DCCScanStop() +HSI_STATUS HSI_Motion::DCCScanStopOld() { WaitForSingleObject(g_WR_ToMove_Mutex, INFINITE); auto rStatus = HSI_STATUS_NORMAL; @@ -5770,6 +6305,23 @@ HSI_STATUS HSI_Motion::DCCScanStop() return rStatus; } +HSI_STATUS HSI_Motion::DCCScanStop() +{ + WaitForSingleObject(g_WR_ToMove_Mutex, INFINITE); + auto rStatus = HSI_STATUS_NORMAL; + if (g_pHSI_Motion) + { + g_pLogger->SendAndFlushWithTime(L"[DCCScanStop] In\n"); + unsigned char m_SendDCCData[64] = {0}; + m_SendDCCData[0] = 0x01; + m_SendDCCData[1] = 0x03; + m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, 2); + g_pLogger->SendAndFlushWithTime(L"[DCCScanStop] Out\n"); + } + ReleaseMutex(g_WR_ToMove_Mutex); + return rStatus; +} + //=========================================================================== HSI_STATUS HSI_Motion::DCCForLightPlate() { @@ -6876,7 +7428,9 @@ int HSI_Motion::SpeedPercent(int AxisNum, double& Speed, int& DirveSpeed, int& S DecLine = m_JogDecLine[AxisNum][0]; AccCurve = m_JogAccCurve[AxisNum][0]; DecCurve = m_JogDecCurve[AxisNum][0]; - g_pLogger->SendAndFlushWithTime(L"[SpeedPercent] 0.81 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); + g_pLogger->SendAndFlushWithTime( + L"[SpeedPercent] 0.81 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", + DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); } else if (fabs(Speed) > 0.61) { @@ -6886,7 +7440,9 @@ int HSI_Motion::SpeedPercent(int AxisNum, double& Speed, int& DirveSpeed, int& S DecLine = m_JogDecLine[AxisNum][1]; AccCurve = m_JogAccCurve[AxisNum][1]; DecCurve = m_JogDecCurve[AxisNum][1]; - g_pLogger->SendAndFlushWithTime(L"[SpeedPercent] 0.61 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); + g_pLogger->SendAndFlushWithTime( + L"[SpeedPercent] 0.61 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", + DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); } else if (fabs(Speed) > 0.41) { @@ -6896,7 +7452,9 @@ int HSI_Motion::SpeedPercent(int AxisNum, double& Speed, int& DirveSpeed, int& S DecLine = m_JogDecLine[AxisNum][2]; AccCurve = m_JogAccCurve[AxisNum][2]; DecCurve = m_JogDecCurve[AxisNum][2]; - g_pLogger->SendAndFlushWithTime(L"[SpeedPercent] 0.41 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); + g_pLogger->SendAndFlushWithTime( + L"[SpeedPercent] 0.41 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", + DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); } else if (fabs(Speed) > 0.21) { @@ -6906,7 +7464,9 @@ int HSI_Motion::SpeedPercent(int AxisNum, double& Speed, int& DirveSpeed, int& S DecLine = m_JogDecLine[AxisNum][3]; AccCurve = m_JogAccCurve[AxisNum][3]; DecCurve = m_JogDecCurve[AxisNum][3]; - g_pLogger->SendAndFlushWithTime(L"[SpeedPercent] 0.21 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); + g_pLogger->SendAndFlushWithTime( + L"[SpeedPercent] 0.21 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", + DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); } else if (fabs(Speed) > 0.01) { @@ -6916,7 +7476,9 @@ int HSI_Motion::SpeedPercent(int AxisNum, double& Speed, int& DirveSpeed, int& S DecLine = m_JogDecLine[AxisNum][4]; AccCurve = m_JogAccCurve[AxisNum][4]; DecCurve = m_JogDecCurve[AxisNum][4]; - g_pLogger->SendAndFlushWithTime(L"[SpeedPercent] 0.01 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); + g_pLogger->SendAndFlushWithTime( + L"[SpeedPercent] 0.01 DriveSpeed: [%d], StartSpeed: [%d], AccLine: [%d], DecLine: [%d], AccCurve: [%d], DecCurve: [%d]\n", + DirveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve); } else { @@ -7033,6 +7595,7 @@ HSI_STATUS HSI_Motion::GetSpeedXyz(int AxisNum, double& Speed) g_pLogger->SendAndFlushWithTime(L"[GetSpeedXyz] Out\n"); return rStatus; } + //=========================================================================== HSI_STATUS HSI_Motion::SetSpeedXyz(double Speed) { @@ -7557,6 +8120,7 @@ HSI_STATUS HSI_Motion::SetSpeedEx(UINT AxisTypes, double Speed) g_pLogger->SendAndFlushWithTime(L"[SetSpeedEx] Out\n"); return rStatus; } + //=========================================================================== HSI_STATUS HSI_Motion::GetAccelerationEx(UINT AxisTypes, double& Accel) { @@ -7922,7 +8486,7 @@ unsigned __stdcall HSI_Motion::m_ThreadData(LPVOID pThis) case HSI_THREAD_RUNNING: { TRACE("HSI_THREAD_RUNNING.\r\n"); - _This->UpdateMotionStateData();//ȡ˶״̬ + _This->UpdateMotionStateData(); //ȡ˶״̬ break; } case HSI_THREAD_PAUSED: @@ -8198,7 +8762,22 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng WaitForSingleObject(g_RW_Data_Mutex, INFINITE); if (m_bConnected && (m_IsUseEF3 == 1) && (com == 0)) { + g_pLogger->SendAndFlushWithTime(L"[Send_Command] lenth:%d, %s\n", SendDataLength,m_SO7_Serial.ToHexStr(_SendData, SendDataLength)); int iWriteByte = m_SO7_Serial.Send(_SendData, SendDataLength); + if (iWriteByte != SendDataLength)// дֽڷֽ + { + rStatus = FALSE; + g_pLogger->SendAndFlushWithTime(L"[Send_Command] WriteByte:%d,!= SendDataLength:%d\n", iWriteByte, SendDataLength); + } + + ////ԭӣhttps://blog.csdn.net/qq_31073871/article/details/85696092 + //printf("Send_Command: "); + //for (int i = 0; i < SendDataLength; i++) + //{ + // printf("%02X ", ((uint8_t*)_SendData)[i]); + //} + //printf("\r\n"); + if (iWriteByte == 0) { int iError = GetLastError(); @@ -8221,8 +8800,10 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng g_pLogger->SendAndFlushWithTime(L"[Send_Command] m_SO7_Serial[%d].Send failed\n", com); rStatus = FALSE; } - // Sleep(5); - // m_SO7_Serial.OnReceive(); + + //ӡڷֵ + Sleep(10); + m_SO7_Serial.OnReceive(); } ReleaseMutex(g_RW_Data_Mutex); return rStatus; diff --git a/HSI_HexagonMI_EF3/HSI_Motion.h b/HSI_HexagonMI_EF3/HSI_Motion.h index 94e7f58..9919211 100644 --- a/HSI_HexagonMI_EF3/HSI_Motion.h +++ b/HSI_HexagonMI_EF3/HSI_Motion.h @@ -312,14 +312,34 @@ public: HSI_STATUS SetTriggerLight(int triggleNum, int delayLighting, int delayLightBefor, int triggleMode, double* Intensities); HSI_STATUS DCCPPStartPoint(double* startPoint); + /** + * \brief · + * \param AxisTypes + * \param eType ȼߵʱ + * \param lTrigNumber + * \param dTrigDis + * \return + */ HSI_STATUS DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis); + HSI_STATUS DCCScanSetDataOld(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis); + /** + * \brief ʼɨ + * \return + */ HSI_STATUS DCCScanStart(); + HSI_STATUS DCCScanStartOld(); + /** + * \brief ֹͣɨ + * \return + */ HSI_STATUS DCCScanStop(); + HSI_STATUS DCCScanStopOld(); HSI_STATUS DCCForLightPlate(); HSI_STATUS IOStep(bool RunSts); + HSI_STATUS IOprogram(byte* SendData, int length); HSI_STATUS FindOriginTest(bool state); - + HSI_STATUS StartPlcJob(int* CamerasDis, int* BinsDis, int SubArea, int filterTime1, int filterTime2, int pluseSumDis); HSI_STATUS SendBinResult(int* BinResult); diff --git a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP index 57d8111..83aaa33 100644 --- a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP +++ b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP @@ -4,6 +4,9 @@ #include "CMMIO_SERIAL.H " +#include + +using namespace std; ////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// #define LONG_TIMEOUT 5000 @@ -564,9 +567,11 @@ void CPSerial::OnReceive() char s[MAX_RECIEVE_BUFFER_SIZE] = {0}; s[1] = '\0'; CurrentPointer = 0; + printf("MAX_RECIEVE_BUFFER_SIZE: %d m_HandShake:%d\n", MAX_RECIEVE_BUFFER_SIZE, m_HandShake); if (m_HandShake == CS_HANDSHAKE_FOR_TRESASTR_E) { int num = ReadPort(s, MAX_RECIEVE_BUFFER_SIZE); + if ((num > 0) && (num < MAX_RECIEVE_BUFFER_SIZE)) { if (m_IsWrtingData) @@ -589,12 +594,17 @@ void CPSerial::OnReceive() else { int num = ReadPort(s, m_iRecvCount); + printf("----RECV: %d----\r\n", num); if ((num > 0) && (num < MAX_RECIEVE_BUFFER_SIZE)) { // memset(m_RecvData,0,m_iRecvBytes); memcpy(m_RecvData, s, num); m_iRecvBytes = num; m_iRecvState = TRUE; + for (int i = 0; i < num; i++) + { + printf(" %02X ", m_RecvData[i]); + } } } //LineReceive(s, num); @@ -1266,6 +1276,30 @@ int CPSerial::HexToInt(char* Data, int Bytes) return (Value); } +//ֽתΪ16ַ +CString CPSerial::ToHexStr(const char* pData, int nLen) +{ + CString str; + CString strTemp; + for (int i = 0; i < nLen; i++) + { + strTemp.Format(_T(" %02X "), pData[i]); + str += strTemp; + } + return str; +} + + +//unsigned char CPSerial::HexCharToByte(char ch) +//{ +// if ((ch >= '0') && (ch <= '9')) +// return ch - '0'; +// if ((ch >= 'A') && (ch <= 'F')) +// return ch - 'A' + 10; +// if ((ch >= 'a') && (ch <= 'f')) +// return ch - 'a' + 10; +// return 0; +//} ///////////////////////////////////////////////////////////////////////////// // Private functions diff --git a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H index 63d1eda..3cee589 100644 --- a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H +++ b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H @@ -128,6 +128,10 @@ public: // Convert ascii hex into an int int HexToInt(char* Data, int Bytes); + //ֽתΪ16ַ + CString ToHexStr(const char* pData, int nLen); + + DWORD Send(LPCSTR buffer, int l, BOOL needsResponse = FALSE) override; //virtual DWORD Send(CString what); diff --git a/HSI_HexagonMI_EF3/version.h b/HSI_HexagonMI_EF3/version.h index 9598caf..3bb6a68 100644 --- a/HSI_HexagonMI_EF3/version.h +++ b/HSI_HexagonMI_EF3/version.h @@ -12,5 +12,5 @@ #define HSI_VERSION_REVNUM #define HSI_VERSION_BUILD_DATE _T(__DATE__ ) #define HSI_VERSION_BUILD_TIME _T(__TIME__ ) -#define HSI_FILE_DESCRIPTION "2022.11.07 / 17:44 " -#define HSI_FILE_CSDESCRIPTION _T("2022.11.07 / 17:44 ") +#define HSI_FILE_DESCRIPTION "2022.11.22 / 15:35 " +#define HSI_FILE_CSDESCRIPTION _T("2022.11.22 / 15:35 ") diff --git a/HSI_SEVENOCEAN_EF1_CsTest/bin/Debug/Config/EF3_Config.ini b/HSI_SEVENOCEAN_EF1_CsTest/bin/Debug/Config/EF3_Config.ini deleted file mode 100644 index ad11e48..0000000 Binary files a/HSI_SEVENOCEAN_EF1_CsTest/bin/Debug/Config/EF3_Config.ini and /dev/null differ diff --git a/SerialAssistant/WPFSerialAssistant.zip b/SerialAssistant/WPFSerialAssistant.zip new file mode 100644 index 0000000..e7831f8 Binary files /dev/null and b/SerialAssistant/WPFSerialAssistant.zip differ