此帖出自嵌入式系统论坛
最新回复
UINT PortReadThread(LPVOID lpvoid)
{
DWORD dwCommModemStatus;
// Specify a set of events to be monitored for the port.
SetCommMask (m_hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);
//=============================
int ReadFalge=0,ReadCount=0;
while (m_hPort != INVALID_HANDLE_VALUE)
{
// Wait for an event to occur for the port.
WaitCommEvent (m_hPort, &dwCommModemStatus, 0);
// Re-specify the set of events to be monitored for the port.
SetCommMask (m_hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
if (dwCommModemStatus & EV_RXCHAR)
{
// Loop for waiting for the data.
int K;
BYTE bText[MAXLENGTH];
K = 0;
for(;;)
{
DWORD nLength;
COMSTAT ComStat;
DWORD dwErrorFlags;
BYTE bBuffer[MAXLENGTH];
ClearCommError(m_hPort,&dwErrorFlags,&ComStat);
nLength = 1; //每次只读一个字节
ReadFile(m_hPort,bBuffer,nLength,&nLength,NULL);
if(bBuffer[0] == '\n')
{
bText[K] = 0;
if ((bText[0] == '$') & (bText[1] == 'G') & (bText[2] == 'P') &
(bText[3] == 'G') & (bText[4] == 'G') & (bText[5] == 'A') )
{
WriteGGAToFile(bText);
}
else if ((bText[0] == '$') & (bText[1] == 'G') & (bText[2] == 'P') &
(bText[3] == 'G') & (bText[4] == 'S') & (bText[5] == 'V') )
{
WriteGSVToFile(bText);
}
else if ((bText[0] == '$') & (bText[1] == 'G') & (bText[2] == 'P') &
(bText[3] == 'R') & (bText[4] == 'M') & (bText[5] == 'C') )
{
WriteRMCToFile(bText);
}
K = 0;
}
else if(bBuffer[0] == '$')
{
K = 0;
bText[K] = bBuffer[0];
K++;
}
else
{
bText[K] = bBuffer[0];
K++;
}
Sleep(1);
}
}
// Retrieve modem control-register values.s
// GetCommModemStatus (m_hPort, &dwCommModemStatus);
}
return true;
}
详情
回复
发表于 2008-9-16 08:51
| ||
|
||
| |
|
|
此帖出自嵌入式系统论坛
| ||
|
||
EEWorld Datasheet 技术支持