函数主体
DWORD CPSerialPort::ReadPort(char *data,int length)
{
BOOL fReadState;
DWORD dwLength,dwBytesRead;
int TimeOutCount;
dwBytesRead=0;
TimeOutCount=0;
while(m_hComm!=INVALID_HANDLE_VALUE)
{
char* buf=new char[length];
fReadState=ReadFile(m_hComm,data,length,&dwLength,NULL);
if(!fReadState)
{
break;
}
else
{
dwBytesRead+=dwLength;
data+=dwLength;
}
if(dwBytesRead==length)
{
break;
}
if(dwLength!=0)
{
TimeOutCount=0;
}
else
{
TimeOutCount++;
Sleep(5);
}
if(TimeOutCount==5)
{
break;
}
}
return dwBytesRead;
}
调用函数
CPSerialPort ck;
bool hcom =ck.OpenPort(_T("COM2:"),9600,8,0,0);
if(hcom)
{
ck.ReadPort(这里不知道填写什么);
}
调用函数,不知道参数如何填写
DWORD CPSerialPort::ReadPort(char *data,int length)
{
BOOL fReadState;
DWORD dwLength,dwBytesRead;
int TimeOutCount;
dwBytesRead=0;
TimeOutCount=0;
while(m_hComm!=INVALID_HANDLE_VALUE)
{
char* buf=new char[length];
fReadState=ReadFile(m_hComm,data,length,&dwLength,NULL);
if(!fReadState)
{
break;
}
else
{
dwBytesRead+=dwLength;
data+=dwLength;
}
if(dwBytesRead==length)
{
break;
}
if(dwLength!=0)
{
TimeOutCount=0;
}
else
{
TimeOutCount++;
Sleep(5);
}
if(TimeOutCount==5)
{
break;
}
}
return dwBytesRead;
}
调用函数
CPSerialPort ck;
bool hcom =ck.OpenPort(_T("COM2:"),9600,8,0,0);
if(hcom)
{
ck.ReadPort(这里不知道填写什么);
}
调用函数,不知道参数如何填写