From 8ea61c158ed9600acbe32b9c33c8cb4f4f767000 Mon Sep 17 00:00:00 2001 From: Diego Freitas Date: Wed, 4 Mar 2026 08:51:49 -0300 Subject: [PATCH] =?UTF-8?q?Tratamento=20de=20exce=C3=A7=C3=B5es=20no=20m?= =?UTF-8?q?=C3=B3dulo=20GNSS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AgroBase/AgroBase/Services/GPSService.cs | 39 ++++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) 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}"); } } }