diff --git a/AgroBase/AgroBase/Services/GPSService.cs b/AgroBase/AgroBase/Services/GPSService.cs index 11ec7244a..717094c7e 100644 --- a/AgroBase/AgroBase/Services/GPSService.cs +++ b/AgroBase/AgroBase/Services/GPSService.cs @@ -139,8 +139,15 @@ namespace AgroBase.Services foreach (string comando in comandos) { - byte[] bytesComando = Encoding.ASCII.GetBytes(comando); - PortaGPS?.Write(bytesComando, 0, bytesComando.Length); + try + { + byte[] bytesComando = Encoding.ASCII.GetBytes(comando); + PortaGPS?.Write(bytesComando, 0, bytesComando.Length); + } + catch (Exception ex) + { + Console.WriteLine($"Erro ao enviar comando de configuração GNSS: {ex.Message}"); + } await Task.Delay(1000); // Pequeno delay para evitar sobrecarga na comunicação } } @@ -183,8 +190,15 @@ namespace AgroBase.Services foreach (string cmd in comandos) { - byte[] bytes = Encoding.ASCII.GetBytes(cmd); - PortaGPS.Write(bytes, 0, bytes.Length); + try + { + byte[] bytes = Encoding.ASCII.GetBytes(cmd); + PortaGPS.Write(bytes, 0, bytes.Length); + } + catch (Exception ex) + { + Console.WriteLine($"Erro ao enviar comando de configuração GNSS: {ex.Message}"); + } await Task.Delay(500); } } @@ -861,7 +875,7 @@ namespace AgroBase.Services int port = 2101; string mountpoint = "EESC0"; string username = "Zendion"; // Geralmente vazio para RTK2Go - string password = "vyNEF$5*"; // Geralmente vazio para RTK2Go + string password = "QD&m1p60"; // Geralmente vazio para RTK2Go while (CorrecaoRTK_Ntrip && APIService.HasInternet) // Loop para reconectar em caso de falha { @@ -901,11 +915,18 @@ namespace AgroBase.Services int bytesRead; while (CorrecaoRTK_Ntrip && (bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0) { - if (PortaGPS?.IsOpen ?? false) + try { - PortaGPS.Write(buffer, 0, bytesRead); // Envia os dados RTCM para o GPS - //Console.WriteLine($"Enviando {bytesRead} bytes de correção RTCM para o GPS"); - UltimoEnvioCorrecaoRTK = DateTime.Now; + if (PortaGPS?.IsOpen ?? false) + { + PortaGPS.Write(buffer, 0, bytesRead); // Envia os dados RTCM para o GPS + //Console.WriteLine($"Enviando {bytesRead} bytes de correção RTCM para o GPS"); + UltimoEnvioCorrecaoRTK = DateTime.Now; + } + } + catch (Exception ex) + { + Console.WriteLine($"Erro ao enviar correção RTCM para o módulo GNSS: {ex.Message}"); } } }