叠加读取串口
This commit is contained in:
@@ -356,7 +356,6 @@ const int HSI_MAX_POSITIONS_STORED = 500;
|
||||
// 第一阶段需要重写的API 函数
|
||||
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_STARTUP(bool bHome);
|
||||
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_GET_FIREWAREVERION(byte* verion);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_SHUTDOWN();
|
||||
HSI_API HSI_STATUS WINAPI HSI_EF3MOTION_GET_SPEED_XYZ(int axis, double& Speed);
|
||||
@@ -371,6 +370,12 @@ HSI_API HSI_STATUS WINAPI HSI_MOTION_ABORT_MOTION();
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_IS_HOMED(bool& bHomed);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_GET_DIO(UINT IOChannel, UINT& _Status);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_SET_DIO(UINT IOChannel, UINT _Status);
|
||||
|
||||
//扫描相关函数
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_DCC_SCAN_SET_DATA(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis);//扫描配置
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_DCC_SCAN_START();//开始扫描
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_DCC_SCAN_STOP();//停止扫描
|
||||
|
||||
// 第一阶段结束
|
||||
|
||||
|
||||
@@ -394,9 +399,7 @@ HSI_API HSI_STATUS WINAPI HSI_MOTION_SET_POSITION_XYZ_CACHE(UINT AxisTypes, HSI_
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_GET_POSITION_R(UINT AxisTypes, double &PositionR, double &Time);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_SET_POSITION_R(UINT AxisTypes, double PositionR, HSI_MOTION_AXIS_R_MOVE_TYPE DirectionType, bool bWait);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_SET_PLAN_SCAN(double *pdStartPosX, double *pdStartPosY, double *pdStartPosZ, double *pdEndPosX, double *pdEndPosY, double *pdEndPosZ, double *pdStepDis, bool *pbTrig, int iCount);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_DCC_SCAN_SET_DATA(UINT AxisTypes, HSI_SCAN_MOTION_TYPE eType, UINT lTrigNumber, double* dTrigDis);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_DCC_SCAN_START();
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_DCC_SCAN_STOP();
|
||||
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_IS_SUPPORTED_EX(UINT AxisTypes, UINT &Types);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_STARTUP_EX(UINT AxisTypes, bool bHome);
|
||||
HSI_API HSI_STATUS WINAPI HSI_MOTION_GET_SCALE_RESOLUTION_EX(UINT AxisTypes, double &Scale);
|
||||
|
||||
@@ -963,14 +963,10 @@ HSI_STATUS HSI_Motion::HomeMachineOld(bool bHomed)
|
||||
int SavePos[5] = {0};
|
||||
if (m_SO7_Serial.m_RecvData[0] == 2)
|
||||
{
|
||||
SavePos[1] = (m_SO7_Serial.m_RecvData[41] << 24 | m_SO7_Serial.m_RecvData[42] << 16 | m_SO7_Serial.
|
||||
m_RecvData[43] << 8 | m_SO7_Serial.m_RecvData[44]);
|
||||
SavePos[2] = (m_SO7_Serial.m_RecvData[45] << 24 | m_SO7_Serial.m_RecvData[46] << 16 | m_SO7_Serial.
|
||||
m_RecvData[47] << 8 | m_SO7_Serial.m_RecvData[48]);
|
||||
SavePos[3] = (m_SO7_Serial.m_RecvData[49] << 24 | m_SO7_Serial.m_RecvData[50] << 16 | m_SO7_Serial.
|
||||
m_RecvData[51] << 8 | m_SO7_Serial.m_RecvData[52]);
|
||||
SavePos[4] = (m_SO7_Serial.m_RecvData[53] << 24 | m_SO7_Serial.m_RecvData[54] << 16 | m_SO7_Serial.
|
||||
m_RecvData[55] << 8 | m_SO7_Serial.m_RecvData[56]);
|
||||
SavePos[1] = (m_SO7_Serial.m_RecvData[41] << 24 | m_SO7_Serial.m_RecvData[42] << 16 | m_SO7_Serial.m_RecvData[43] << 8 | m_SO7_Serial.m_RecvData[44]);
|
||||
SavePos[2] = (m_SO7_Serial.m_RecvData[45] << 24 | m_SO7_Serial.m_RecvData[46] << 16 | m_SO7_Serial.m_RecvData[47] << 8 | m_SO7_Serial.m_RecvData[48]);
|
||||
SavePos[3] = (m_SO7_Serial.m_RecvData[49] << 24 | m_SO7_Serial.m_RecvData[50] << 16 | m_SO7_Serial.m_RecvData[51] << 8 | m_SO7_Serial.m_RecvData[52]);
|
||||
SavePos[4] = (m_SO7_Serial.m_RecvData[53] << 24 | m_SO7_Serial.m_RecvData[54] << 16 | m_SO7_Serial.m_RecvData[55] << 8 | m_SO7_Serial.m_RecvData[56]);
|
||||
}
|
||||
double PrinfPos[5] = {0};
|
||||
PrinfPos[1] = SavePos[1] * m_Resolution[1];
|
||||
@@ -3635,13 +3631,6 @@ int HSI_Motion::CaculateStepMotorACC(int pos, int maxacc, int minacc)
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
/**
|
||||
* \brief 求各轴运动配置参数
|
||||
* \param AXIS
|
||||
* \param motionParam
|
||||
* \return
|
||||
*/
|
||||
|
||||
//&符号用来处理一个变量,但不是通常的 - 访问这个变量的内容,而是取出这个变量的地址
|
||||
//
|
||||
//int* b;此时b是一个指向int空间的指针,也就是说它是一个未分配的地址
|
||||
@@ -3650,7 +3639,6 @@ int HSI_Motion::CaculateStepMotorACC(int pos, int maxacc, int minacc)
|
||||
//而 & 是对一个已存在的变量取地址,取完地址之后同样可以通过地址操作
|
||||
//
|
||||
//* x是找到x地址的变量,取它的值,所以 * 和 & 是反操作, & x得到x的地址 * , * x得到x的值x
|
||||
|
||||
//————————————————
|
||||
//版权声明:本文为CSDN博主「nick__huang」的原创文章,遵循CC 4.0 BY - SA版权协议,转载请附上原文出处链接及本声明。
|
||||
//原文链接:https ://blog.csdn.net/u012610237/article/details/58599083
|
||||
@@ -3658,7 +3646,14 @@ int HSI_Motion::CaculateStepMotorACC(int pos, int maxacc, int minacc)
|
||||
//void func3(void); //利用全局变量返回数组
|
||||
//void func2(uchar* s); //利用指针返回数组
|
||||
//uchar* func1(); //利用指针函数返回数组
|
||||
//void func0(uchar*& r); //利用引用返回数组
|
||||
//void func0(uchar*& r); //利用引用返回数组
|
||||
|
||||
/**
|
||||
* \brief 求各轴运动配置参数
|
||||
* \param AXIS
|
||||
* \param motionParam
|
||||
* \return
|
||||
*/
|
||||
HSI_STATUS HSI_Motion::GetMotorParam(int AXIS, double motionParam[5])
|
||||
{
|
||||
auto rStatus = HSI_STATUS_NORMAL;
|
||||
@@ -8798,13 +8793,13 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng
|
||||
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");
|
||||
//原文链接: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)
|
||||
{
|
||||
@@ -8830,8 +8825,8 @@ BOOL HSI_Motion::Send_Command(int com, const char* _SendData, DWORD SendDataLeng
|
||||
}
|
||||
|
||||
//打印串口返回值
|
||||
Sleep(5);
|
||||
m_SO7_Serial.OnReceive();
|
||||
//Sleep(5);
|
||||
//m_SO7_Serial.OnReceive();
|
||||
}
|
||||
ReleaseMutex(g_RW_Data_Mutex);
|
||||
return rStatus;
|
||||
|
||||
@@ -152,7 +152,7 @@ int CMMIO::AddReceived(const char* Buffer, DWORD Bytes)
|
||||
// We are messing with pointers so use the CriticalSection
|
||||
if (bArmed)
|
||||
{
|
||||
// EnterCriticalSection(&m_QueueLock);
|
||||
// EnterCriticalSection(&m_QueueLock);
|
||||
//Allocate a new list and add it in
|
||||
count = pBuffer2 - (&Buffer2[0]);
|
||||
if (m_pReceiveNotify)
|
||||
@@ -215,7 +215,7 @@ 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++)
|
||||
{
|
||||
|
||||
@@ -71,26 +71,26 @@ CPSerial::CPSerial()
|
||||
memset(&m_ReadOLap, 0, sizeof(OVERLAPPED));
|
||||
memset(&m_WriteOLap, 0, sizeof(OVERLAPPED));
|
||||
|
||||
//事件最常用在多线程同步互斥机制。
|
||||
//1、HANDLE CreateEvent(
|
||||
//
|
||||
// LPSECURITY_ATTRIBUTES lpEventAttributes, // SECURITY_ATTRIBUTES结构指针,可为NULL
|
||||
// BOOL bManualReset, // 手动/自动
|
||||
// // TRUE:表示手动,在WaitForSingleObject后必须手动调用ResetEvent清除信号
|
||||
// // FALSE:表示自动,在WaitForSingleObject后,系统自动清除事件信号
|
||||
// BOOL bInitialState, //初始状态,FALSE为无信号,TRUE为有信号
|
||||
// LPCTSTR lpName //事件的名称
|
||||
//1、CreateEvent 创建事件。
|
||||
|
||||
//函数原型如下所示,一共四个参数:
|
||||
//HANDLE CreateEvent(
|
||||
|
||||
// LPSECURITY_ATTRIBUTES lpEventAttributes, // SECURITY_ATTRIBUTES结构指针,可为NULL
|
||||
// BOOL bManualReset, // 手动/自动
|
||||
// // TRUE:表示手动,在WaitForSingleObject后必须手动调用ResetEvent清除信号
|
||||
// // FALSE:表示自动,在WaitForSingleObject后,系统自动清除事件信号
|
||||
// BOOL bInitialState, //初始状态,FALSE为无信号,TRUE为有信号
|
||||
// LPCTSTR lpName //事件的名称
|
||||
//);
|
||||
//
|
||||
//2、SetEvent:设置为激活触发状态。
|
||||
//
|
||||
//3、ResetEvent:设置为未激活触发状态。
|
||||
//
|
||||
//4、WaitForSingleObject:检测信号,如果未激活,代码就会处于挂起状态,不再往下执行。
|
||||
//
|
||||
//————————————————
|
||||
//版权声明:本文为CSDN博主「AI浩」的原创文章,遵循CC 4.0 BY - SA版权协议,转载请附上原文出处链接及本声明。
|
||||
//原文链接:https ://blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/108380956
|
||||
|
||||
//2、SetEvent:设置为激活触发状态。
|
||||
//3、ResetEvent:设置为未激活触发状态。
|
||||
//4、WaitForSingleObject:检测信号,如果未激活,代码就会处于挂起状态,不再往下执行。
|
||||
//————————————————
|
||||
//版权声明:本文为CSDN博主「AI浩」的原创文章,遵循CC 4.0 BY - SA版权协议,转载请附上原文出处链接及本声明。
|
||||
//原文链接:https ://blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/108380956
|
||||
|
||||
|
||||
m_hWaitCMMResponse = CreateEvent(nullptr, TRUE, FALSE, nullptr);
|
||||
m_hNewRx = CreateEvent(nullptr, TRUE, FALSE, nullptr); // to trigger OnRx
|
||||
@@ -462,19 +462,19 @@ int CPSerial::ReadBlock(BYTE* abIn, int MaxLength)
|
||||
}
|
||||
dwLength = (static_cast<DWORD>(MaxLength) < ComStat.cbInQue ? MaxLength : ComStat.cbInQue);
|
||||
memset(abIn, 0, MaxLength);
|
||||
//如果有字符即读入
|
||||
//如果有字符即读入
|
||||
if (dwLength)
|
||||
{
|
||||
JudgeRead = ReadFile(m_PortHandle, abIn, dwLength, &dwLength, &m_ReceiveOLap); //读出字符至abIn处
|
||||
JudgeRead = ReadFile(m_PortHandle, abIn, dwLength, &dwLength, &m_ReceiveOLap); //读出字符至abIn处
|
||||
if (!JudgeRead)
|
||||
{
|
||||
//如果重叠操作未完成,等待直到操作完成
|
||||
//如果重叠操作未完成,等待直到操作完成
|
||||
if (GetLastError() == ERROR_IO_PENDING)
|
||||
{
|
||||
// WaitForSingleObject(m_osRead.hEvent,INFINITE);
|
||||
// WaitForSingleObject(m_osRead.hEvent,INFINITE);
|
||||
GetOverlappedResult(m_PortHandle, &m_ReceiveOLap, &dwLength, TRUE);
|
||||
m_ReceiveOLap.Offset = 0;
|
||||
// m_osRead.Offset=(m_osRead.Offset+dwLength)%MAXBLOCK;
|
||||
// m_osRead.Offset=(m_osRead.Offset+dwLength)%MAXBLOCK;
|
||||
}
|
||||
else
|
||||
dwLength = 0;
|
||||
@@ -487,82 +487,82 @@ 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;
|
||||
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());
|
||||
}
|
||||
#if 0
|
||||
void CPSerial::ReceiveTask(void)
|
||||
{
|
||||
//DWORD BytesWritten;
|
||||
DWORD Events;
|
||||
unsigned long State;
|
||||
do
|
||||
{
|
||||
Events = 0;
|
||||
@@ -613,28 +613,23 @@ void CPSerial::ReceiveTask(void)
|
||||
}
|
||||
|
||||
// Go round while the port is open
|
||||
} while (IsOpen());
|
||||
}
|
||||
while (IsOpen());
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// OnReceive() : Default OnReceive()
|
||||
// V114
|
||||
|
||||
void CPSerial::OnReceive()
|
||||
{
|
||||
// Dummy OnReceieve if not used
|
||||
char s[MAX_RECIEVE_BUFFER_SIZE] = {0};
|
||||
s[1] = '\0';
|
||||
CurrentPointer = 0;
|
||||
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);
|
||||
|
||||
if ((num > 0) && (num < MAX_RECIEVE_BUFFER_SIZE))
|
||||
{
|
||||
if (m_IsWrtingData)
|
||||
@@ -656,7 +651,7 @@ void CPSerial::OnReceive()
|
||||
}
|
||||
else
|
||||
{
|
||||
num = ReadPort(s, m_iRecvCount);
|
||||
int num = ReadPort(s, m_iRecvCount);
|
||||
printf("----Data received:: %d----\r\n", num);
|
||||
if ((num > 0) && (num < MAX_RECIEVE_BUFFER_SIZE))
|
||||
{
|
||||
@@ -677,93 +672,6 @@ 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)
|
||||
{
|
||||
DWORD BytesRead, Error;
|
||||
@@ -774,7 +682,7 @@ DWORD CPSerial::ReadPort(char* Buffer, DWORD Bytes)
|
||||
if (IsOpen())
|
||||
{
|
||||
// Enter a critical section incase this is been used from multiple threads
|
||||
// EnterCriticalSection(&m_ReadLock);
|
||||
// EnterCriticalSection(&m_ReadLock);
|
||||
// Start the read
|
||||
ReadState = ReadFile(m_PortHandle, Buffer, Bytes, &BytesRead, &m_ReadOLap);
|
||||
if (!ReadState)
|
||||
@@ -806,8 +714,8 @@ DWORD CPSerial::ReadPort(char* Buffer, DWORD Bytes)
|
||||
if( BytesRead )
|
||||
AddToDebug( Buffer, BytesRead, 1 );
|
||||
*/
|
||||
// LeaveCriticalSection( &m_ReadLock );
|
||||
}
|
||||
//LeaveCriticalSection( &m_ReadLock );
|
||||
}
|
||||
|
||||
return (BytesRead);
|
||||
}
|
||||
@@ -1424,7 +1332,7 @@ int CPSerial::HexToInt(char* Data, int Bytes)
|
||||
return (Value);
|
||||
}
|
||||
|
||||
//字节数组转换为16进制字符
|
||||
//�ֽ�����ת��Ϊ16�����ַ�
|
||||
CString CPSerial::ToHexStr(const char* pData, int nLen)
|
||||
{
|
||||
CString str;
|
||||
|
||||
@@ -131,7 +131,6 @@ public:
|
||||
//字节数据转换为16进制字符串
|
||||
CString ToHexStr(const char* pData, int nLen);
|
||||
|
||||
|
||||
DWORD Send(LPCSTR buffer, int l, BOOL needsResponse = FALSE) override;
|
||||
//virtual DWORD Send(CString what);
|
||||
|
||||
@@ -192,8 +191,8 @@ public:
|
||||
// BV Nov 2001: Made public
|
||||
// CRITICAL_SECTION m_QueueLock;
|
||||
BOOL m_iRecvState; //接收状态
|
||||
INT m_iRecvBytes; //接收字节数
|
||||
INT m_iRecvCount; //接收计数
|
||||
INT m_iRecvBytes; //接收字节数
|
||||
INT m_iRecvCount; //接收计数
|
||||
unsigned char m_RecvData[MAX_RECIEVE_BUFFER_SIZE];
|
||||
};
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ void CLogger::SendAndFlush(LPCTSTR format, ...)
|
||||
LeaveCriticalSection(&m_lockLogger);
|
||||
}
|
||||
|
||||
//https://www.educative.io/answers/what-is-vswprintfs-in-c
|
||||
//vswprintf_s()参考连接:https://www.educative.io/answers/what-is-vswprintfs-in-c
|
||||
void CLogger::SendAndFlushWithTime(LPCTSTR format, ...)
|
||||
{
|
||||
EnterCriticalSection(&m_lockLogger);
|
||||
@@ -133,7 +133,6 @@ void CLogger::SendAndFlushPerMode(LPCTSTR format, ...)
|
||||
LeaveCriticalSection(&m_lockLogger);
|
||||
}
|
||||
|
||||
|
||||
string ConvertCharToString(char* a, int size)
|
||||
{
|
||||
int i;
|
||||
@@ -145,7 +144,6 @@ string ConvertCharToString(char* a, int size)
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//删除指定目录以及目录下的所有文件
|
||||
#include <iostream>
|
||||
#include <io.h>
|
||||
@@ -153,7 +151,6 @@ string ConvertCharToString(char* a, int size)
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
void DelFiles(string path)
|
||||
{
|
||||
//在目录后面加上"\\*.*"进行第一次搜索
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#TargetFrameworkVersion=:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native64Bit:WindowsTargetPlatformVersion=10.0.19041.0
|
||||
Debug|x64|E:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\|
|
||||
@@ -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.24 / 16:22 "
|
||||
#define HSI_FILE_CSDESCRIPTION _T("2022.11.24 / 16:22 ")
|
||||
#define HSI_FILE_DESCRIPTION "2022.11.25 / 15:12 "
|
||||
#define HSI_FILE_CSDESCRIPTION _T("2022.11.25 / 15:12 ")
|
||||
|
||||
Reference in New Issue
Block a user