From b94d85b393e7559d82948af6e43c8aff71d6eef6 Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Fri, 25 Nov 2022 10:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E9=98=B6=E6=AE=B5=E6=80=A7?= =?UTF-8?q?=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、新增了加速度,减速度,运行速度读配置档位 2、优化了串口通讯,待继续调试 3、测试用例,新增了 DCCScanStart() 和 DCCScanStop()的调试 --- HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj | 1 + HSI_HexagonMI_EF3/HSI_Motion.cpp | 290 ++++++++++-------- HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.CPP | 4 +- HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.H | 2 +- HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP | 280 +++++++++++++---- HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H | 6 +- HSI_HexagonMI_EF3/version.h | 4 +- HSI_SEVENOCEAN_EF1_CsTest/HSI/HSI.cs | 74 ++++- HSI_SEVENOCEAN_EF1_CsTest/Program.cs | 12 +- 9 files changed, 453 insertions(+), 220 deletions(-) diff --git a/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj b/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj index 5cba9b4..ad3dc76 100644 --- a/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj +++ b/HSI_HexagonMI_EF3/HSI_HexagonMI_EF3.vcxproj @@ -108,6 +108,7 @@ copy "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)HSI_SEVENOCEAN_EF1_CsTest\bin\Debug\HSI.dll" copy "$(TargetDir)$(ProjectName).dll" "C:\Hexagon\Metus2020R1\HSI_Sevenocean_EF3.dll" +copy "$(TargetDir)$(ProjectName).dll" "C:\Hexagon\Metus-7.10.1 967\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 b8d184c..782d8bd 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,Code: %d, %S\n", ErrorCode, ErrorStr); } } else @@ -777,18 +777,19 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly) //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] = 0x06; + //m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2); + //Sleep(10); + //Ƶ 1ӣ m_cSendData[0] = 0x01; m_cSendData[1] = 0x01; m_cSendData[2] = 0x02; - m_cSendData[3] = 0x03; + m_cSendData[3] = 0x03; // 10000 0x27 0x10Ӧ1룬3-4ֽڱʾ m_cSendData[4] = 0xE8; m_WriteByte = Send_Command(0, (const char*)m_cSendData, 5); - Sleep(5); + Sleep(10); g_pLogger->SendAndFlushWithTime(L"[Startup] Set EF3 Timing latch Success\n"); } @@ -1935,113 +1936,113 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) 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) - { - if (AxisTypes == AXIS_X /*&& m_motorType & 0x01*/) - { - if (!bJOGDir) // - { - RemainPul = static_cast(now_pos[1] / m_Resolution[1]) - static_cast(m_N_Work_Limit[1] / - m_Resolution[1]); - limitSDPul = (DriveSpeed - StartSpeed) * 13; - if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) - { - float SpeedRatio = limitSDPul * 2 / RemainPul; - DriveSpeed = DriveSpeed / SpeedRatio; - if (DriveSpeed < StartSpeed) - { - DriveSpeed = StartSpeed; - } - } - } - else - { - RemainPul = static_cast(m_P_Work_Limit[1] / m_Resolution[1]) - static_cast(now_pos[1] / - m_Resolution[1]); - limitSDPul = (DriveSpeed - StartSpeed) * 13; - if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) - { - float SpeedRatio = limitSDPul * 2 / RemainPul; - DriveSpeed = DriveSpeed / SpeedRatio; - if (DriveSpeed < StartSpeed) - { - DriveSpeed = StartSpeed; - } - } - } - } - else if (AxisTypes == AXIS_Y /*&& m_motorType & 0x02*/) - { - if (!bJOGDir) // - { - RemainPul = static_cast(now_pos[2] / m_Resolution[2]) - static_cast(m_N_Work_Limit[2] / - m_Resolution[2]); - limitSDPul = (DriveSpeed - StartSpeed) * 13; - if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) - { - float SpeedRatio = 1 + limitSDPul * 2 / RemainPul; - DriveSpeed = DriveSpeed / SpeedRatio; - if (DriveSpeed < StartSpeed) - { - DriveSpeed = StartSpeed; - } - } - } - else - { - RemainPul = static_cast(m_P_Work_Limit[2] / m_Resolution[2]) - static_cast(now_pos[2] / - m_Resolution[2]); - limitSDPul = (DriveSpeed - StartSpeed) * 13; - if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) - { - float SpeedRatio = limitSDPul * 2 / RemainPul; - DriveSpeed = DriveSpeed / SpeedRatio; - if (DriveSpeed < StartSpeed) - { - DriveSpeed = StartSpeed; - } - } - } - } - if (AxisTypes == AXIS_Z /*&& m_motorType & 0x04*/) - { - if (!bJOGDir) // - { - RemainPul = static_cast(now_pos[3] / m_Resolution[3]) - static_cast(m_N_Work_Limit[3] / - m_Resolution[3]); - limitSDPul = (DriveSpeed - StartSpeed) * 13; - if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) - { - float SpeedRatio = limitSDPul * 2 / RemainPul; - DriveSpeed = DriveSpeed / SpeedRatio; - if (DriveSpeed < StartSpeed) - { - DriveSpeed = StartSpeed; - } - } - } - else - { - RemainPul = static_cast(m_P_Work_Limit[3] / m_Resolution[3]) - static_cast(now_pos[3] / - m_Resolution[3]); - limitSDPul = (DriveSpeed - StartSpeed) * 13; - if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) - { - float SpeedRatio = limitSDPul * 2 / RemainPul; - DriveSpeed = DriveSpeed / SpeedRatio; - if (DriveSpeed < StartSpeed) - { - DriveSpeed = StartSpeed; - } - } - } - } - } + //if (m_DeviceType != 3) + //{ + // if (AxisTypes == AXIS_X /*&& m_motorType & 0x01*/) + // { + // if (!bJOGDir) // + // { + // RemainPul = static_cast(now_pos[1] / m_Resolution[1]) - static_cast(m_N_Work_Limit[1] / + // m_Resolution[1]); + // limitSDPul = (DriveSpeed - StartSpeed) * 13; + // if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) + // { + // float SpeedRatio = limitSDPul * 2 / RemainPul; + // DriveSpeed = DriveSpeed / SpeedRatio; + // if (DriveSpeed < StartSpeed) + // { + // DriveSpeed = StartSpeed; + // } + // } + // } + // else + // { + // RemainPul = static_cast(m_P_Work_Limit[1] / m_Resolution[1]) - static_cast(now_pos[1] / + // m_Resolution[1]); + // limitSDPul = (DriveSpeed - StartSpeed) * 13; + // if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) + // { + // float SpeedRatio = limitSDPul * 2 / RemainPul; + // DriveSpeed = DriveSpeed / SpeedRatio; + // if (DriveSpeed < StartSpeed) + // { + // DriveSpeed = StartSpeed; + // } + // } + // } + // } + // else if (AxisTypes == AXIS_Y /*&& m_motorType & 0x02*/) + // { + // if (!bJOGDir) // + // { + // RemainPul = static_cast(now_pos[2] / m_Resolution[2]) - static_cast(m_N_Work_Limit[2] / + // m_Resolution[2]); + // limitSDPul = (DriveSpeed - StartSpeed) * 13; + // if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) + // { + // float SpeedRatio = 1 + limitSDPul * 2 / RemainPul; + // DriveSpeed = DriveSpeed / SpeedRatio; + // if (DriveSpeed < StartSpeed) + // { + // DriveSpeed = StartSpeed; + // } + // } + // } + // else + // { + // RemainPul = static_cast(m_P_Work_Limit[2] / m_Resolution[2]) - static_cast(now_pos[2] / + // m_Resolution[2]); + // limitSDPul = (DriveSpeed - StartSpeed) * 13; + // if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) + // { + // float SpeedRatio = limitSDPul * 2 / RemainPul; + // DriveSpeed = DriveSpeed / SpeedRatio; + // if (DriveSpeed < StartSpeed) + // { + // DriveSpeed = StartSpeed; + // } + // } + // } + // } + // if (AxisTypes == AXIS_Z /*&& m_motorType & 0x04*/) + // { + // if (!bJOGDir) // + // { + // RemainPul = static_cast(now_pos[3] / m_Resolution[3]) - static_cast(m_N_Work_Limit[3] / + // m_Resolution[3]); + // limitSDPul = (DriveSpeed - StartSpeed) * 13; + // if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) + // { + // float SpeedRatio = limitSDPul * 2 / RemainPul; + // DriveSpeed = DriveSpeed / SpeedRatio; + // if (DriveSpeed < StartSpeed) + // { + // DriveSpeed = StartSpeed; + // } + // } + // } + // else + // { + // RemainPul = static_cast(m_P_Work_Limit[3] / m_Resolution[3]) - static_cast(now_pos[3] / + // m_Resolution[3]); + // limitSDPul = (DriveSpeed - StartSpeed) * 13; + // if ((RemainPul < limitSDPul * 2) && (RemainPul > 0)) + // { + // float SpeedRatio = limitSDPul * 2 / RemainPul; + // DriveSpeed = DriveSpeed / SpeedRatio; + // if (DriveSpeed < StartSpeed) + // { + // DriveSpeed = StartSpeed; + // } + // } + // } + // } + //} //ٶ g_pLogger->SendAndFlushWithTime( - L"[Jog] StartSpeed: [%d], DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n", - StartSpeed, DriveSpeed, AccCurve, AccLine, DecCurve, DecLine); + L"[Jog] DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n", + DriveSpeed, AccCurve, AccLine, DecCurve, DecLine); // ͣж if ((StartSpeed < 250) && (DriveSpeed < 6)) @@ -2057,16 +2058,33 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) 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", + L"[Jog] Axis= %d,Current Velocity = %.2f, Acceleration= %.2f, Deceleration= %.2f, KillDeceleration= %.2f, Jerk= %.2f\n", jogAxisNum, motionParam[0], motionParam[1], motionParam[2], motionParam[3], motionParam[4]); //ʼJOG˶ if (!bJOGDir) { - StartSpeed = StartSpeed * (-1); // Negative direction : Using - (minus) velocity + DriveSpeed = DriveSpeed * (-1); // Negative direction : Using - (minus) velocity } //int acsDirection = bJOGDir ? ACSC_POSITIVE_DIRECTION : ACSC_NEGATIVE_DIRECTION; //򣬻 - if (!acsc_Jog(handleACS, 0, jogAxisNum, StartSpeed, nullptr)) + + //üٶ + if(!acsc_SetAccelerationImm(handleACS, jogAxisNum, AccLine, nullptr)) + { + g_pLogger->SendAndFlushWithTime(L"[Jog] ACS SetAccelerationImm failed, Aixs:[%d] AccCurve:[%d]\n", jogAxisNum, + AccLine); + ErrorsHandler(); + } + + //üٶ + if(!acsc_SetDeceleration(handleACS, jogAxisNum, AccLine, nullptr)) + { + g_pLogger->SendAndFlushWithTime(L"[Jog] ACS SetDeceleration failed, Aixs:[%d] DecCurve:[%d]\n", jogAxisNum, + AccLine); + ErrorsHandler(); + } + + if (!acsc_Jog(handleACS, 0, jogAxisNum, DriveSpeed, nullptr)) { printf("[Jog] [%d] [%s] ƶʧ", AxisTypes, bJOGDir ? "" : ""); g_pLogger->SendAndFlushWithTime(L"[Jog] failed, Aixs:[%d] JOGDir:[%S]\n", AxisTypes, @@ -2076,7 +2094,7 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed) jogMoving = true; - g_pLogger->SendAndFlushWithTime(L"[Jog] Out, StartSpeed = %d\n", StartSpeed); + g_pLogger->SendAndFlushWithTime(L"[Jog] Out, DriveSpeed = %d AccCurve:[%d] DecCurve:[%d]\n", DriveSpeed, AccLine, AccLine); } return rStatus; } @@ -3956,9 +3974,10 @@ HSI_STATUS HSI_Motion::Load_EF3_Motion_Inifile(CString GoogolIniFile) temp.GetBufferSetLength(50), 10, csAppPath); 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]); //ӡļ λٶ + //m_JogDriveSpeed[j][i] = speed / (m_Resolution[j] * 50);//ٶתΪ + m_JogDriveSpeed[j][i] = speed; //ֱӶȡٶ + g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_JogDriveSpeed[%d][%d]: %ld %ld\n", i, j, + speed, m_JogDriveSpeed[j][i]); //ӡļ λٶ GetPrivateProfileString(L"JOG_SPEED", L"JOG_STARTSPEED_" + strGear[i] + axisNum[j], L"10", temp.GetBufferSetLength(50), 10, csAppPath); @@ -5057,7 +5076,7 @@ HSI_STATUS HSI_Motion::SetDIO(UINT IOChannel, UINT _Status) m_cSendData[1] = 0x02; m_cSendData[2] = (_Status >> 8) & 0xff; m_cSendData[3] = _Status & 0xff; - m_WriteByte = Send_Command(0, (const char*)m_cSendData, m_SendDataLength); + //m_WriteByte = Send_Command(0, (const char*)m_cSendData, m_SendDataLength); Sleep(5); } g_pLogger->SendAndFlushWithTime(L"[SetDIO] Out\n"); @@ -5170,7 +5189,7 @@ HSI_STATUS HSI_Motion::Shutdown() { memset(m_cSendData, 0x00, 64); m_cSendData[0] = CT_SOFTSTOP; - m_WriteByte = Send_Command(0, (const char*)m_cSendData, m_SendDataLength); + //m_WriteByte = Send_Command(0, (const char*)m_cSendData, m_SendDataLength); Sleep(5); } @@ -5882,7 +5901,7 @@ HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType 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); + //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); Sleep(1); } if ((num > 0) && (lTrigNumber % 14 != 0)) @@ -5900,7 +5919,7 @@ HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType 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); + //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); Sleep(10); } else if (num == 0) @@ -5918,7 +5937,7 @@ HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType 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); + //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); Sleep(10); } break; @@ -6025,7 +6044,7 @@ HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType 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); + //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); Sleep(10); break; } @@ -6137,14 +6156,22 @@ HSI_STATUS HSI_Motion::DCCScanSetData(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType 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); + //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); Sleep(10); break; } default: break; } + + //ʱͬʱɨ ⲿIO + unsigned char m_cSendData[8] = { 0 }; + + //EF3Flash + m_cSendData[0] = 0x01; + m_cSendData[1] = 0x04; + m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2); + Sleep(20); g_pLogger->SendAndFlushWithTime(L"[DCCScanSetData] Out\n"); } ReleaseMutex(g_WR_ToMove_Mutex); @@ -6226,7 +6253,7 @@ HSI_STATUS HSI_Motion::DCCScanStart() m_SetTriggerLightData[0] = CT_LIGHT; m_SetTriggerLightData[1] = 0x03; m_SetTriggerLightData[53] = 0; - m_WriteByte = Send_Command(0, (const char*)m_SetTriggerLightData, m_SendDataLength); + //m_WriteByte = Send_Command(0, (const char*)m_SetTriggerLightData, m_SendDataLength); Sleep(1); } setLightFlag = false; @@ -6268,12 +6295,13 @@ HSI_STATUS HSI_Motion::DCCScanStart() break; } g_pLogger->SendAndFlushWithTime( - L"[DCCScanStart] iaxisNum:%d, iTriggleNum:%d, iMotionDirection:%d,begin_position:%d \n", iaxisNum, - iTriggleNum, iMotionDirection, begin_position); + L"[DCCScanStart] iaxisNum:%d, iTriggleNum:%d, iMotionDirection:%d, begin_position:%d \n", iaxisNum, + iTriggleNum, iMotionDirection, begin_position[1]); //m_WriteByte = Send_Command(0, (const char*)m_SendDCCData, m_SendDataLength); + //ʱͬʱɨ ⲿIO + unsigned char m_cSendData[8] = {0}; - unsigned char m_cSendData[64] = {0}; m_cSendData[0] = 0x01; m_cSendData[1] = 0x02; m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2); @@ -8802,7 +8830,7 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng } //ӡڷֵ - Sleep(10); + Sleep(5); m_SO7_Serial.OnReceive(); } ReleaseMutex(g_RW_Data_Mutex); diff --git a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.CPP b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.CPP index 490ee55..df2adbb 100644 --- a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.CPP +++ b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.CPP @@ -215,14 +215,14 @@ void CMMIO::LineReceive(char* s, int nbCharAvail, BOOL ignoreDelimiter /*= FALSE { if (nbCharAvail != -1) { - //TRACE(_T("LineReceive got %d chars \n"),nbCharAvail); + TRACE(_T("LineReceive got %d chars \n"),nbCharAvail); char c; for (int i = 0; i < nbCharAvail; i++) { c = s[i]; m_InputBuffer[CurrentPointer++] = c; - // only add a packet if we have a delimiter + // only add a packet if we have a delimiter ָ if ((!m_usesTerminator && i == nbCharAvail - 1) || (m_usesTerminator && c == m_terminator) || ignoreDelimiter) { diff --git a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.H b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.H index d91198a..3b77940 100644 --- a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.H +++ b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_BASE.H @@ -6,7 +6,7 @@ #define MAX_OUTPUT_BUFFER_SIZE 2048 -#define MAX_RECIEVE_BUFFER_SIZE 3000 +#define MAX_RECIEVE_BUFFER_SIZE 30000 // TCP, serial style routines struct SerialList diff --git a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP index 83aaa33..4c75201 100644 --- a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP +++ b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.CPP @@ -6,7 +6,7 @@ #include -using namespace std; +using namespace std; ////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// #define LONG_TIMEOUT 5000 @@ -178,7 +178,8 @@ DWORD CPSerial::Open() // Setup the port according to the stored parameters if (ProgramPort(m_Port, m_Baud, m_Parity, m_Bits, m_StopBits, m_HandShake)) { - TRACE(_T("CmmIO> Port OPEN %s\n", m_Port), Ok); + TRACE(_T("CmmIO> Port OPEN %s, m_Baud\n", m_Port, m_Baud), Ok); + printf("m_Baud: %d\n", m_Baud); // Setup the timeouts CommTimeOut.ReadIntervalTimeout = 25; CommTimeOut.ReadTotalTimeoutMultiplier = 1; @@ -486,6 +487,76 @@ int CPSerial::ReadBlock(BYTE* abIn, int MaxLength) // ReceiveTask() : Internal function, this runs as a thread and provides the // OnRecieve and OnTransmit events +//void CPSerial::ReceiveTask(void) +//{ +// //DWORD BytesWritten; +// DWORD Events; +// unsigned long State; +// +// do +// { +// Sleep(2); +// BYTE abIn[MAXBLOCK]; +// int len; +// len = ReadBlock(abIn, MAXBLOCK); +// if ((len > 0) && (len < MAX_RECIEVE_BUFFER_SIZE)) +// { +// //memset(m_RecvData, 0, m_iRecvBytes); +// memcpy(m_RecvData, abIn, len); +// m_iRecvBytes = len; +// m_iRecvState = TRUE; +// } +// // Events=0; +// // +// // // Wait for a comm event +// // State=WaitCommEvent(m_PortHandle,&Events,&m_ReceiveOLap); +// // if(!State) +// // { +// // // Since we are using overlapping IO we may have to wait +// // // for the result +// // if(GetLastError() == ERROR_IO_PENDING) +// // GetOverlappedResult(m_PortHandle,&m_ReceiveOLap,&State,TRUE); +// // } +// ////m_iRecvState=FALSE; +// // // If we have a result then OK otherwise the event was probable +// // // the serial port being closed and we shall exit the loop +// // if( State && IsOpen( ) ) +// // { +// // // Check the events and act accordingly +// // if( Events & EV_RXCHAR ) +// // { +// // OnReceive( ); +// // } +// // //ZH +// // /* +// // if( Events & EV_TXEMPTY ) +// // { +// // if( m_TXHead ) +// // { +// // GetOverlappedResult(m_PortHandle,&m_TransmitOLap,&BytesWritten,TRUE); +// // if( BytesWritten ) +// // AddToDebug( m_TXHead->Buffer, BytesWritten, 2 ); +// // OnTransmit( 0, BytesWritten ); +// // SendBuffer(TRUE); +// // } +// // } +// // */ +// // if(Events & EV_BREAK) +// // TRACE(_T("Break detected\n")); +// // if(Events & EV_CTS) +// // TRACE(_T("CTS Changed State\n")); +// // if(Events & EV_DSR) +// // TRACE(_T("DSR Changed State\n")); +// // if(Events & EV_ERR) +// // TRACE(_T("Line error\n")); +// // if(Events & EV_RLSD) +// // TRACE(_T("EV_RLSD error\n")); +// // } +// +// // Go round while the port is open +// } +// while (IsOpen()); +//} void CPSerial::ReceiveTask(void) { //DWORD BytesWritten; @@ -494,69 +565,56 @@ void CPSerial::ReceiveTask(void) do { - Sleep(2); - BYTE abIn[MAXBLOCK]; - int len; - len = ReadBlock(abIn, MAXBLOCK); - if ((len > 0) && (len < MAX_RECIEVE_BUFFER_SIZE)) + Events = 0; + + // Wait for a comm event + State = WaitCommEvent(m_PortHandle, &Events, &m_ReceiveOLap); + if (!State) { - //memset(m_RecvData, 0, m_iRecvBytes); - memcpy(m_RecvData, abIn, len); - m_iRecvBytes = len; - m_iRecvState = TRUE; + // Since we are using overlapping IO we may have to wait + // for the result + if (GetLastError() == ERROR_IO_PENDING) + GetOverlappedResult(m_PortHandle, &m_ReceiveOLap, &State, TRUE); + } + //m_iRecvState=FALSE; + // If we have a result then OK otherwise the event was probable + // the serial port being closed and we shall exit the loop + if (State && IsOpen()) + { + // Check the events and act accordingly + if (Events & EV_RXCHAR) + { + OnReceive(); + } + //ZH + /* + if( Events & EV_TXEMPTY ) + { + if( m_TXHead ) + { + GetOverlappedResult(m_PortHandle,&m_TransmitOLap,&BytesWritten,TRUE); + if( BytesWritten ) + AddToDebug( m_TXHead->Buffer, BytesWritten, 2 ); + OnTransmit( 0, BytesWritten ); + SendBuffer(TRUE); + } + } + */ + if (Events & EV_BREAK) + TRACE(_T("Break detected\n")); + if (Events & EV_CTS) + TRACE(_T("CTS Changed State\n")); + if (Events & EV_DSR) + TRACE(_T("DSR Changed State\n")); + if (Events & EV_ERR) + TRACE(_T("Line error\n")); + if (Events & EV_RLSD) + TRACE(_T("EV_RLSD error\n")); } - // Events=0; - // - // // Wait for a comm event - // State=WaitCommEvent(m_PortHandle,&Events,&m_ReceiveOLap); - // if(!State) - // { - // // Since we are using overlapping IO we may have to wait - // // for the result - // if(GetLastError() == ERROR_IO_PENDING) - // GetOverlappedResult(m_PortHandle,&m_ReceiveOLap,&State,TRUE); - // } - ////m_iRecvState=FALSE; - // // If we have a result then OK otherwise the event was probable - // // the serial port being closed and we shall exit the loop - // if( State && IsOpen( ) ) - // { - // // Check the events and act accordingly - // if( Events & EV_RXCHAR ) - // { - // OnReceive( ); - // } - // //ZH - // /* - // if( Events & EV_TXEMPTY ) - // { - // if( m_TXHead ) - // { - // GetOverlappedResult(m_PortHandle,&m_TransmitOLap,&BytesWritten,TRUE); - // if( BytesWritten ) - // AddToDebug( m_TXHead->Buffer, BytesWritten, 2 ); - // OnTransmit( 0, BytesWritten ); - // SendBuffer(TRUE); - // } - // } - // */ - // if(Events & EV_BREAK) - // TRACE(_T("Break detected\n")); - // if(Events & EV_CTS) - // TRACE(_T("CTS Changed State\n")); - // if(Events & EV_DSR) - // TRACE(_T("DSR Changed State\n")); - // if(Events & EV_ERR) - // TRACE(_T("Line error\n")); - // if(Events & EV_RLSD) - // TRACE(_T("EV_RLSD error\n")); - // } // Go round while the port is open - } - while (IsOpen()); + } while (IsOpen()); } - ///////////////////////////////////////////////////////////////////////////// // OnReceive() : Default OnReceive() // V114 @@ -567,7 +625,12 @@ 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); + int num = 0; + printf(" m_HandShake:%d\n", m_HandShake); //ӡ + + Sleep(100); //ʱ100ms ȴ + + if (m_HandShake == CS_HANDSHAKE_FOR_TRESASTR_E) { int num = ReadPort(s, MAX_RECIEVE_BUFFER_SIZE); @@ -593,8 +656,8 @@ void CPSerial::OnReceive() } else { - int num = ReadPort(s, m_iRecvCount); - printf("----RECV: %d----\r\n", num); + num = ReadPort(s, m_iRecvCount); + printf("----Data received:: %d----\r\n", num); if ((num > 0) && (num < MAX_RECIEVE_BUFFER_SIZE)) { // memset(m_RecvData,0,m_iRecvBytes); @@ -614,6 +677,92 @@ void CPSerial::OnReceive() ///////////////////////////////////////////////////////////////////////////// // ReadPort() : Read the specifed number of bytes. // +#if 0 +DWORD CPSerial::ReadPort(char* Buffer, DWORD Bytes) +{ + DWORD recieved, Error; + BOOL ReadState; + + long len = 0; + int read_loop = 1; + // Check the port is open + if (IsOpen()) + { + // Enter a critical section incase this is been used from multiple threads + // EnterCriticalSection(&m_ReadLock); + // Start the read + while (read_loop != 0) + { + //BOOL ReadFile( + // HANDLE hFile, //ļľ + // LPVOID lpBuffer, //ڱݵһ + // DWORD nNumberOfBytesToRead, //Ҫֽ + // LPDWORD lpNumberOfBytesRead, //ָʵʶȡָֽ + // LPOVERLAPPED lpOverlapped + // //ļʱָFILE_FLAG_OVERLAPPEDô룬һĽṹ + // //ýṹһ첽ȡӦΪNULL + //); + ReadState = ReadFile(m_PortHandle, Buffer, 1, &recieved, &m_ReadOLap); + printf("Bytes: %d\r\n", Bytes); + if (!ReadState) + { + Sleep(3); + // the specifed number of bytes were not available so + // the read will continue in the background aslong as + // GetLastError() returns ERROR_IO_PENDING + if (GetLastError() == ERROR_IO_PENDING) + { + // Wait for the read to complete + WaitForSingleObject(m_ReadOLap.hEvent, LONG_TIMEOUT); // GER + + // get the result of the read + if (GetOverlappedResult(m_PortHandle, &m_ReadOLap, &recieved, FALSE) == 0) + Error = GetLastError(); + } + else + { + // Gone wrong so clear any erros + ClearCommError(m_PortHandle, &Error, nullptr); + recieved = 0; + } + } + + len++; + printf("BytesRead:%d %s\r\n", len, std::to_string(recieved)); + // recieved prompt, so end read loop + if ((len == 2) && (Buffer[0] == '6F') && (Buffer[1] == '6B')) + { + printf("1111"); + read_loop = 0; + } + + // recieve nothing so quit + if (len <= 0) { read_loop = 0; } + + if (Buffer[len - 1] != '\r') + { + printf("%C", Buffer[len - 1]); + } + else + { + len = 0; + printf("\n"); + } + + //ZH + /* + // Read some bytes so add then to the debug list + if( BytesRead ) + AddToDebug( Buffer, BytesRead, 1 ); + */ + // LeaveCriticalSection( &m_ReadLock ); + } + } + + return (len); +} +#endif + DWORD CPSerial::ReadPort(char* Buffer, DWORD Bytes) { @@ -630,7 +779,7 @@ DWORD CPSerial::ReadPort(char* Buffer, DWORD Bytes) ReadState = ReadFile(m_PortHandle, Buffer, Bytes, &BytesRead, &m_ReadOLap); if (!ReadState) { - Sleep(3); + Sleep(5); // the specifed number of bytes were not available so // the read will continue in the background aslong as // GetLastError() returns ERROR_IO_PENDING @@ -658,12 +807,11 @@ DWORD CPSerial::ReadPort(char* Buffer, DWORD Bytes) AddToDebug( Buffer, BytesRead, 1 ); */ // LeaveCriticalSection( &m_ReadLock ); - } +} return (BytesRead); } - ///////////////////////////////////////////////////////////////////////////// // ReadPort() : Read the specifed number of bytes into a CString class. // diff --git a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H index 3cee589..8c7bdf3 100644 --- a/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H +++ b/HSI_HexagonMI_EF3/SevenOcean/CMMIO_SERIAL.H @@ -191,9 +191,9 @@ public: // BV Nov 2001: Made public // CRITICAL_SECTION m_QueueLock; - BOOL m_iRecvState; - INT m_iRecvBytes; - INT m_iRecvCount; + BOOL m_iRecvState; //״̬ + INT m_iRecvBytes; //ֽ + INT m_iRecvCount; //ռ unsigned char m_RecvData[MAX_RECIEVE_BUFFER_SIZE]; }; diff --git a/HSI_HexagonMI_EF3/version.h b/HSI_HexagonMI_EF3/version.h index 3bb6a68..783771d 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.22 / 15:35 " -#define HSI_FILE_CSDESCRIPTION _T("2022.11.22 / 15:35 ") +#define HSI_FILE_DESCRIPTION "2022.11.24 / 16:22 " +#define HSI_FILE_CSDESCRIPTION _T("2022.11.24 / 16:22 ") diff --git a/HSI_SEVENOCEAN_EF1_CsTest/HSI/HSI.cs b/HSI_SEVENOCEAN_EF1_CsTest/HSI/HSI.cs index 8106e27..461c852 100644 --- a/HSI_SEVENOCEAN_EF1_CsTest/HSI/HSI.cs +++ b/HSI_SEVENOCEAN_EF1_CsTest/HSI/HSI.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Windows.Forms; +using static HSI_SEVENOCEAN_EF1_CsTest.HSI.Def; namespace HSI_SEVENOCEAN_EF1_CsTest.HSI { @@ -25,7 +26,7 @@ namespace HSI_SEVENOCEAN_EF1_CsTest.HSI //1ֵΪvoidҪʹrefؼ(ref readonlyʾֻ)η //2ÿһreturnҪһref [DllImport("HSI.dll", EntryPoint = "HSI_MOTION_GET_FIREWAREVERION", CharSet = CharSet.Unicode)] - public static extern Def.HSI_STATUS MotionGetFirewareVerion( IntPtr firewareVerion); + public static extern Def.HSI_STATUS MotionGetFirewareVerion(IntPtr firewareVerion); [DllImport("HSI.dll", EntryPoint = "HSI_STARTUP", CharSet = CharSet.Unicode)] public static extern Def.HSI_STATUS Startup(IntPtr hWnd, bool bOfflineOnly); @@ -68,7 +69,7 @@ namespace HSI_SEVENOCEAN_EF1_CsTest.HSI var eventFunctionId = (Def.HSI_EVENT_FUNCTION_ID)eventId; switch (eventFunctionId) { - case Def.HSI_EVENT_FUNCTION_ID.HSI_EVENT_MOTION_DCC_HOME://׼ؼ + case Def.HSI_EVENT_FUNCTION_ID.HSI_EVENT_MOTION_DCC_HOME: //׼ؼ { MessageBox.Show(Resources.Interface_Tips_Home_Machine, Resources.Interface_Tips, msgBtn, MessageBoxIcon.Information); @@ -132,6 +133,16 @@ namespace HSI_SEVENOCEAN_EF1_CsTest.HSI [DllImport("HSI.dll", EntryPoint = "HSI_MOTION_SET_SPEED_XYZ", CharSet = CharSet.Unicode)] public static extern Def.HSI_STATUS SetSpeedXyz(double speed); + + [DllImport("HSI.dll", EntryPoint = "HSI_MOTION_DCC_SCAN_SET_DATA", CharSet = CharSet.Unicode)] + public static extern Def.HSI_STATUS DCCScanSetData(uint axisTypes, Def.HSI_SCAN_MOTION_TYPE eType, uint lTrigNumber, double[] dTrigDis); + + [DllImport("HSI.dll", EntryPoint = "HSI_MOTION_DCC_SCAN_START", CharSet = CharSet.Unicode)] + public static extern Def.HSI_STATUS DCCScanStart(); + + [DllImport("HSI.dll", EntryPoint = "HSI_MOTION_DCC_SCAN_STOP", CharSet = CharSet.Unicode)] + public static extern Def.HSI_STATUS DCCScanStop(); + //[DllImport("HSI.dll", EntryPoint = "HSI_MOTION_GET_SPEED_R", CharSet = CharSet.Unicode)] //public static extern Def.HSI_STATUS GetSpeedR(ref double speed); @@ -367,6 +378,17 @@ namespace HSI_SEVENOCEAN_EF1_CsTest.HSI HSI_ILLUMINATION_BULB_GRID = 4 } + public enum HSI_SCAN_MOTION_TYPE + { + HSI_SCAN_MOTION_LINEAR = 1, + HSI_SCAN_MOTION_CIRCULAR, + HSI_SCAN_MOTION_SPEC_LOCA = 100,//EF1 + HSI_SCAN_MOTION_EQ_DIS, + HSI_SCAN_MOTION_EQ_DIS_II, + HSI_SCAN_MOTION_LINEAR_TEST,//ʹ + HSI_SCAN_MOTION_EQ_TEST,//ʹ + HSI_SCAN_MOTION_MANUAL_TEST //ʹ + }; /////////////////////////////////////////////////////////////////////////////// //Illumination API @@ -437,18 +459,42 @@ namespace HSI_SEVENOCEAN_EF1_CsTest.HSI HSI_MOTION_AXIS_Y = 0x0002, // This is the default "Sensor level" Y Axis - use on single Y axis machines HSI_MOTION_AXIS_Z = 0x0004, // This is the default "Sensor level" Z Axis - use on single Z axis machines HSI_MOTION_AXIS_R = 0x0008, // This is the default "Sensor level" R Axis - use on single R axis machines - HSI_MOTION_AXIS_X1 = 0x0010, // This is the 1st X Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_Y1 = 0x0020, // This is the 1st Y Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_Z1 = 0x0040, // This is the 1st Z Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_R1 = 0x0080, // This is the 1st R Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_X2 = 0x0100, // This is the 2nd X Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_Y2 = 0x0200, // This is the 2nd Y Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_Z2 = 0x0400, // This is the 2nd Z Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_R2 = 0x0800, // This is the 2nd R Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_X3 = 0x1000, // This is the 3rd X Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_Y3 = 0x2000, // This is the 3rd Y Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_Z3 = 0x4000, // This is the 3rd Z Axis - use on multiple axis machines when specific axis needed - HSI_MOTION_AXIS_R3 = 0x8000 // This is the 3rd R Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_X1 = + 0x0010, // This is the 1st X Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_Y1 = + 0x0020, // This is the 1st Y Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_Z1 = + 0x0040, // This is the 1st Z Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_R1 = + 0x0080, // This is the 1st R Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_X2 = + 0x0100, // This is the 2nd X Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_Y2 = + 0x0200, // This is the 2nd Y Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_Z2 = + 0x0400, // This is the 2nd Z Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_R2 = + 0x0800, // This is the 2nd R Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_X3 = + 0x1000, // This is the 3rd X Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_Y3 = + 0x2000, // This is the 3rd Y Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_Z3 = + 0x4000, // This is the 3rd Z Axis - use on multiple axis machines when specific axis needed + + HSI_MOTION_AXIS_R3 = + 0x8000 // This is the 3rd R Axis - use on multiple axis machines when specific axis needed } public enum HSI_MOTION_IO_TYPE diff --git a/HSI_SEVENOCEAN_EF1_CsTest/Program.cs b/HSI_SEVENOCEAN_EF1_CsTest/Program.cs index 68d8322..6f08cb9 100644 --- a/HSI_SEVENOCEAN_EF1_CsTest/Program.cs +++ b/HSI_SEVENOCEAN_EF1_CsTest/Program.cs @@ -136,10 +136,20 @@ namespace HSI_SEVENOCEAN_EF1_CsTest { SpeedGear = 0.1; } - Console.WriteLine("Motion.SpeedGera:{0}", SpeedGear); break; + case ConsoleKey.NumPad5: + Motion.DCCScanStart(); + break; + case ConsoleKey.NumPad7: + Motion.DCCScanStop(); + break; + case ConsoleKey.NumPad9: + var dPos1 = new double[3]; + dPos1[0] = 100; + Motion.DCCScanSetData(1, Def.HSI_SCAN_MOTION_TYPE.HSI_SCAN_MOTION_EQ_DIS,7, dPos1); + break; //case ConsoleKey.LeftArrow: // break; //case ConsoleKey.RightArrow: