bool GpsIdPort::Initialize() { _hLoc = ::CreateEvent(NULL, FALSE, FALSE, NULL); _hState = ::CreateEvent(NULL, FALSE, FALSE, NULL); _hGPS = ::GPSOpenDevice(_hLoc, _hState, NULL, 0); if (0 == _hGPS) { StartupStore(_T("Unable to Open GPS Intermediate driver %s"), NEWLINE); return false; } SetPortStatus(CPS_OPENOK); GPS_DEVICE dev = {0}; GPSResetData(dev); GPSGetDeviceState(&dev); StartupStore(_T("GPSID : DeviceState: %lX, ServiceState: %lX%s"), dev.dwDeviceState, dev.dwServiceState, NEWLINE); // StartupStore(_T("GPSID : LastDataTime: %s%s"), dev.ftLastDataReceived, NEWLINE); StartupStore(_T("GPSID : DrvPrefix; %s%s"), dev.szGPSDriverPrefix, NEWLINE); StartupStore(_T("GPSID : MxPrefix %s%s"), dev.szGPSMultiplexPrefix, NEWLINE); StartupStore(_T("GPSID : Name:%s%s"), dev.szGPSFriendlyName, NEWLINE); if (!StartRxThread()) { StartupStore(_T(". ComPort %u <%s> Failed to start Rx Thread%s"), GetPortIndex() + 1, GetPortName(), NEWLINE); return false; } return true; }
void SerialPort::UpdateStatus() { DWORD dwErrors = 0; COMSTAT comStat = {0}; if(hPort != INVALID_HANDLE_VALUE) { ClearCommError(hPort, &dwErrors, &comStat); if (dwErrors & CE_FRAME) { //StartupStore(_T("... Com port %d, dwErrors=%ld FRAME (old status=%d)\n"), // GetPortIndex(),dwErrors,ComPortStatus[GetPortIndex()]); SetPortStatus(CPS_EFRAME); AddStatErrRx(1); valid_frames = 0; } else { if (++valid_frames > 10) { valid_frames = 20; SetPortStatus(CPS_OPENOK); } } } }