pGPSInfo));
LocalFree(npGPSInfo);
return (TRUE);
}
BOOL NEAR OpenConnection()
{
char szPort[15];
BOOL fRetVal;
HCURSOR hOldCursor,hWaitCursor;
HANDLE hCommWatchThread;
DWORD dwThreadID;
COMMTIMEOUTS CommTimeOuts;
if (!npGPSInfo) return (FALSE);
hWaitCursor=LoadCursor(NULL,IDC_WAIT) ;
hOldCursor=SetCursor(hWaitCursor) ;
wsprintf(szPort,"COM%d",PORT(npGPSInfo));
if
((COMDEV(npGPSInfo)=CreateFile(szPort,GENERIC_READ|GENERIC_WRITE,
0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
NULL))==(HANDLE)-1)
return ( FALSE ) ;
else
{ SetCommMask(COMDEV(npGPSInfo),EV_RXCHAR);
SetupComm(COMDEV(npGPSInfo),4096,4096);
PurgeComm(COMDEV(npGPSInfo),PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|
PURGE_R
XCLEAR);
CommTimeOuts.ReadIntervalTimeout=0xFFFFFFFF;
CommTimeOuts.ReadTotalTimeoutMultiplier=0;
CommTimeOuts.ReadTotalTimeoutConstant=1000;
CommTimeOuts.WriteTotalTimeoutMultiplier=0;
CommTimeOuts.WriteTotalTimeoutConstant=1000;
SetCommTimeouts(COMDEV(npGPSInfo),&CommTimeOuts);
}
fRetVal=SetupConnection();
if (fRetVal)
{ CONNECTED(npGPSInfo)=TRUE;
if
(NULL==(hCommWatchThread=CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,(LPTHREAD_START_ROUTINE)CommWatchProc,
(LPVOID)NULL,0,&dwThreadID)))
{ CONNECTED(npGPSInfo)=FALSE;
CloseHandle(COMDEV(npGPSInfo));
fRetVal=FALSE;
}
else
{ THREADID(npGPSInfo)=dwThreadID;
HTHREAD(npGPSInfo)=hCommWatchThread;
EscapeCommFunction(COMDEV(npGPSInfo),SETDTR);
}
}
else
{ CONNECTED(npGPSInfo)=FALSE;
CloseHandle(COMDEV(npGPSInfo));
}
SetCursor(hOldCursor);
return (fRetVal);
}
BOOL NEAR SetupConnection()
{ BOOL fRetVal;
DCB dcb;
if (!npGPSInfo) return(FALSE);
dcb.DCBlength=sizeof(DCB);
GetCommState(COMDEV(npGPSInfo),&dcb);
dcb.BaudRate=BAUDRATE(npGPSInfo);
dcb.ByteSize=BYTESIZE(npGPSInfo);
dcb.Parity=PARITY(npGPSInfo);
dcb.StopBits=STOPBITS(npGPSInfo);
dcb.fOutxDsrFlow=FALSE;
dcb.fDtrControl=DTR_CONTROL_ENABLE;
dcb.fOutxCtsFlow=FALSE;
dcb.fRtsControl=RTS_CONTROL_ENABLE;
dcb.fInX=dcb.fOutX=FALSE;
dcb.fBinary=TRUE;
dcb.fParity=TRUE;
fRetVal=SetCommState(COMDEV(npGPSInfo),&dcb);
return (fRetVal);
}
BOOL NEAR CloseConnection()
{
if (!npGPSInfo) return(FALSE);
CONNECTED(npGPSInfo)=FALSE;
SetCommMask(COMDEV(npGPSInfo),0);
while(THREADID(npGPSInfo)!=0);
EscapeCommFunction(COMDEV(npGPSInfo),CLRDTR);
PurgeComm(COMDEV(npGPSInfo),PURGE_TXABORT|PURGE_RXABORT|
PURGE_TXCLEAR|PURGE_RXCLEAR);
CloseHandle(COMDEV(npGPSInfo));
return (TRUE);
}
int NEAR ReadCommBlock(LPSTR lpszBlock,int nMaxLength)
{
BOOL fReadStat ;
COMSTAT ComStat ;
DWORD dwErrorFlags;
DWORD dwLength;
DWORD dwError;
if (!npGPSInfo) return(FALSE);
ClearCommError(COMDEV(npGPSInfo),&dwErrorFlags,&ComStat);
dwLength=min((DWORD)nMaxLength,ComStat.cbInQue);
if (dwLength>0)
{ fReadStat=ReadFile(COMDEV(npGPSInfo),lpszBlock,
dwLength,&dwLength,&READ_OS(npGPSInfo));
if (!fReadStat)
{ if (GetLastError()==ERROR_IO_PENDING)
{ OutputDebugString("\n\rIO Pending");
while(!GetOverlappedResult(COMDEV(npGPSInfo),&READ_OS(npGPSInfo),&dwLe
ngth,