private void ReadTimerCallback(object state) { if (IsOpen()) { try { GPSDataRequestParameter reqPara = new GPSDataRequestParameter(); reqPara.LastDataID = lastDataID; reqPara.LastDataIDSpecified = true; reqPara.MaxLines = 10; reqPara.MaxLinesSpecified = true; reqPara.LatestDataOnly = !bIsReplay; reqPara.LatestDataOnlySpecified = true; reqPara.PathID = pathInfo.ID; reqPara.PathIDSpecified = true; reqPara.PathPassword = pathInfo.Password; GPSDownloadData[] receivedDatas = serviceClient.GetGPSData(reqPara); if (receivedDatas != null) { foreach (GPSDownloadData dataItem in receivedDatas) { if (dataItem != null) { // Update the id if (lastDataID < dataItem.ID) { lastDataID = dataItem.ID; } if (dataItem.NMEASentence.Length == 0) { continue; } byte[] data = new byte[System.Text.Encoding.Default.GetByteCount(dataItem.NMEASentence)]; data = System.Text.Encoding.Default.GetBytes(dataItem.NMEASentence); // Dispatch the received data. if (data != null) { if (Read != null) { Read(this, data); } } } } } } catch (System.Exception) { // Don't exit if failed. } // ToDO - for the replay model, we should use the time tamp of the gps data. try { // There is exception when close the port during receiving process. if (!disposed) { readTimer.Change(1000, Timeout.Infinite); // Read data every second } } catch (System.Exception) { } } }