public SerialPortControl(GPSDev parent) { try { m_Parent = parent; singleton = new object(); port = new SerialPort(); } catch { m_Parent.ConnectionError(); } }
void Poller() { GPSDev.GPSInfo gpsInfo = null; while (!m_Stop) { Thread.Sleep(m_PollLoopSleepTime); // do we have a comm port? if (m_FixedCommPort == null) { m_FixedCommPort = FindDevicePort.GetGPSCommPort(); // may still be null if there is no device } if (m_ResetGPSDriver) { // lost the device connection, start over if (m_GPSDevice != null) { m_GPSDevice.Close(); } m_FixedCommPort = null; // start over, perhaps the user moved the receiver to another port m_GPSDevice = null; m_ResetGPSDriver = false; m_Log.Log("lost GPS Device connection", ErrorLog.LOG_TYPE.FATAL); m_GPSUseModes = GPS_USE_MODES.USE_FIXED; LoadGPSConfiguration();// re-load the static configuration if one is there } if (m_FixedCommPort != null) { // we have found a comm, port, try it.... // do we have a device opened ? if (m_GPSDevice == null && !m_Stop) { m_GPSDevice = new GPSDev(m_FixedCommPort, HandleLostGPSDeviceConnection, m_AppData); } if (m_GPSDevice == null && m_Stop) { break; } if (!m_GPSDevice.OpenSucess) { m_GPSDevice.Close(); m_GPSDevice = null; continue;// try again next time around } else { if (m_ReceiverDetected == false) { m_Log.Log("connected to GPS Device", ErrorLog.LOG_TYPE.FATAL); } m_ReceiverDetected = true; m_GPSUseModes = GPS_USE_MODES.USE_RECEIVER; // everything is working fine, get the latest available sat data m_GPSDevice.GetLocation(out gpsInfo); lock (m_CurrentLocationInfo) { m_CurrentLocationInfo = gpsInfo.Clone(); } BuildURL(gpsInfo.Latitude, gpsInfo.Longitude, m_googleString); } } if (m_GPSUseModes == GPS_USE_MODES.USE_RECEIVER) { m_putNewGPSData(gpsInfo.CleanPositionString, gpsInfo.DetectedReceiver, gpsInfo.HaveSatData); } else if (m_GPSUseModes == GPS_USE_MODES.USE_FIXED) { m_putNewGPSData(m_FixedSiteCoordiates.CleanPositionString, m_FixedSiteCoordiates.DetectedReceiver, m_FixedSiteCoordiates.HaveSatData); } else if (m_GPSUseModes == GPS_USE_MODES.USE_NONE) { m_putNewGPSData("no position avaialbe", false, false); } }// end while (! stop) if (m_GPSDevice != null) { m_GPSDevice.Close(); m_GPSDevice = null; } }