格式化,并新增打印串口发送内容
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
|
||||
#include "CMMIO_SERIAL.H "
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user