1、对串口获取返回值

2、新增获取批量点
3、新增测试用例
4、对对端设备进行调试
This commit is contained in:
zhengxuan.zhang
2022-11-25 17:53:16 +08:00
parent d73ac43da5
commit 4e11acde01
11 changed files with 816 additions and 486 deletions
+142 -15
View File
@@ -786,8 +786,12 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly)
m_cSendData[0] = 0x01;
m_cSendData[1] = 0x01;
m_cSendData[2] = 0x02;
m_cSendData[3] = 0x03; // 10000 0x27 0x10)对应1秒,3-4字节表示锁存周期
m_cSendData[4] = 0xE8;
//m_cSendData[3] = 0x03; // 10000 0x27 0x10)对应1秒,3-4字节表示锁存周期
//m_cSendData[4] = 0xE8;
// 10000 0x27 0x10)对应1秒,3-4字节表示锁存周期
m_cSendData[3] = (m_axisLatchFrequency >> 8) & 0xFF;
m_cSendData[4] = m_axisLatchFrequency & 0xFF;
m_WriteByte = Send_Command(0, (const char*)m_cSendData, 5);
Sleep(10);
@@ -1125,6 +1129,21 @@ HSI_STATUS HSI_Motion::HomeMachine(bool bHomed)
}
while (!home);
//回家后,将锁存板的位置设置为0
unsigned char m_cSendData[8] = { 0 };
m_cSendData[0] = 0x01;
m_cSendData[1] = 0x06;
m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2);
Sleep(5);
//清除锁存板Flash区
m_cSendData[0] = 0x01;
m_cSendData[1] = 0x04;
m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2);
Sleep(5);
g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Go Home success\n");
g_pLogger->SendAndFlushWithTime(L"[HomeMachine] Out\n");
}
@@ -3720,9 +3739,76 @@ HSI_STATUS HSI_Motion::SetPositionXyzCache(UINT AxisTypes, HSI_MOTION_MOVE_TYPE
auto rStatus = HSI_STATUS_NORMAL;
if (g_pHSI_Motion)
{
g_pLogger->SendAndFlushWithTime(L"SetPositionXyzCache : start\n");
g_pLogger->SendAndFlushWithTime(L"[SetPositionXyzCache] start\n");
g_pLogger->SendAndFlushWithTime(L"SetPositionXyzCache : end\n");
g_pLogger->SendAndFlushWithTime(L"[SetPositionXyzCache] end\n");
}
return rStatus;
}
//===========================================================================
/**
* \brief
* \param CacheData
* \param DataCount
* \return
*/
HSI_STATUS HSI_Motion::GetPositionXyzCache(unsigned char * CacheData, int DataCount)
{
auto rStatus = HSI_STATUS_NORMAL;
if (g_pHSI_Motion)
{
g_pLogger->SendAndFlushWithTime(L"[GetPositionXyzCache] start\n");
if(m_SO7_Serial.IsOpen())
{
//发送获取点数量命令 0x01 0x05
unsigned char m_cSendData[8] = { 0 };
m_cSendData[0] = 0x01;
m_cSendData[1] = 0x05;
m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2);
Sleep(2);
//解析缓存点数量
if(m_SO7_Serial.m_iRecvState)
{
//特殊帧头, 表示该内容为回复点数
if ((m_SO7_Serial.m_RecvData[0] == 0x01) && (m_SO7_Serial.m_RecvData[0] == 0x1B))
{
DataCount = (m_SO7_Serial.m_RecvData[4] << 24 | m_SO7_Serial.m_RecvData[5] << 16 | m_SO7_Serial.m_RecvData[6] << 8 | m_SO7_Serial.m_RecvData[7]);
//详细 https://blog.csdn.net/hebbely/article/details/79577880
g_pLogger->SendAndFlushWithTime(L"[GetPositionXyzCache] DataCount%d, %s\n",DataCount, m_SO7_Serial.ToHexStr((const char *)m_SO7_Serial.m_RecvData,8));
}
}
//读取锁存点
m_cSendData[0] = 0x01;
m_cSendData[1] = 0x09;
m_WriteByte = Send_Command(0, (const char*)m_cSendData, 2); //此处应该返回 "ok"
Sleep(2);
//读取点的字节数,每个点占用12个字节
if (m_SO7_Serial.m_iRecvBytes != DataCount*12)
{
g_pLogger->SendAndFlushWithTime(L"[GetPositionXyzCache] m_iRecvBytes: %d != Points: %d\n", m_SO7_Serial.m_iRecvBytes, DataCount * 12);
rStatus = HSI_STATUS_FAILED;
}
else
{
memcpy(CacheData, m_SO7_Serial.m_RecvData, m_SO7_Serial.m_iRecvBytes);
m_SO7_Serial.m_iRecvState = FALSE;
rStatus = HSI_STATUS_FAILED;
}
}
else
{
g_pLogger->SendAndFlushWithTime(L"[GetPositionXyzCache] Serial Port is unavailable! \n");
rStatus = HSI_STATUS_FAILED;
}
g_pLogger->SendAndFlushWithTime(L"[GetPositionXyzCache] end\n");
}
return rStatus;
}
@@ -3971,7 +4057,7 @@ HSI_STATUS HSI_Motion::Load_EF3_Motion_Inifile(CString GoogolIniFile)
/*m_JogDriveSpeed[j][i] = GetPrivateProfileInt(L"JOG_SPEED", L"JOG_DRIVESPEED_" , 10, csAppPath);*/
//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,
g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_JogDriveSpeed[%d][%d]: %d %ld\n", i, j,
speed, m_JogDriveSpeed[j][i]); //打印配置文件 档位速度
GetPrivateProfileString(L"JOG_SPEED", L"JOG_STARTSPEED_" + strGear[i] + axisNum[j], L"10",
@@ -4097,6 +4183,25 @@ HSI_STATUS HSI_Motion::Load_EF3_Config_Inifile(CString GoogolIniFile)
m_IsHavePattern = GetPrivateProfileInt(L"ASIX", L"ISHAVE_AXISPATTERN", 15, csAppPath);
m_AxisHomeDirection = GetPrivateProfileInt(L"ASIX", L"AXIS_HOMEDIRECTION", 15, csAppPath);
m_IsUseManualRunin = GetPrivateProfileInt(L"ASIX", L"IS_USEMANUALRUNIN", 0, csAppPath);
m_axisLatchFrequency = GetPrivateProfileInt(L"ASIX", L"AXIS_LATCHFREQUENCY", 1, csAppPath);
switch (m_axisLatchFrequency)
{
case 1:
m_axisLatchFrequency = 1000;
break;
case 2:
m_axisLatchFrequency = 2000;
break;
case 3:
m_axisLatchFrequency = 4000;
break;
case 4:
m_axisLatchFrequency = 8000;
break;
case 5:
m_axisLatchFrequency = 16000;
break;
} //锁存频率处理
m_IsUseExternalTrigger = GetPrivateProfileInt(L"FUNCTION", L"IS_USEEXTERNALTRIGGER", 1, csAppPath);
m_IsUseSixRingEightArea = GetPrivateProfileInt(L"FUNCTION", L"IS_USESIXRINGEIGHTAREA", 0, csAppPath);
@@ -6296,11 +6401,11 @@ HSI_STATUS HSI_Motion::DCCScanStart()
//启动定时锁存的同时,启动扫描 外部IO
unsigned char m_cSendData[8] = {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;
}
@@ -8785,14 +8890,7 @@ 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++)
@@ -8801,6 +8899,11 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng
}
printf("\r\n");*/
//------------------------------调试区-----------------------------------//
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 == 0)
{
int iError = GetLastError();
@@ -8824,7 +8927,31 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng
rStatus = FALSE;
}
//打印串口返回值
if (iWriteByte != SendDataLength)// 写入字节数不等于发送字节数
{
rStatus = FALSE;
g_pLogger->SendAndFlushWithTime(L"[Send_Command] WriteByte:%d,!= SendDataLength:%d\n", iWriteByte, SendDataLength);
}
//判断回复值,是否为ok 6F 6B
int iRetrys = 0;
while (!m_SO7_Serial.m_iRecvState && iRetrys < 20)
{
iRetrys++;
Sleep(100);
}
//发送完当前指令后,第一次结束完成标志
if (m_SO7_Serial.m_iRecvState)
{
if ((m_SO7_Serial.m_RecvData[0] == 0x6F) && (m_SO7_Serial.m_RecvData[0] == 0x6B))
{
g_pLogger->SendAndFlushWithTime(L"[Send_Command] m_SO7_Serial[%d]. EF3 Reply not ok.\n", com);
rStatus = FALSE;
}
}
//打印串口返回值,该方式废弃
//Sleep(5);
//m_SO7_Serial.OnReceive();
}