Tratamento de exceções no módulo GNSS

This commit is contained in:
Diego Freitas 2026-03-04 08:51:49 -03:00
parent ea78440695
commit 8ea61c158e
1 changed files with 30 additions and 9 deletions

View File

@ -138,9 +138,16 @@ namespace AgroBase.Services
await Task.Delay(2000);
foreach (string comando in comandos)
{
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
}
}
@ -182,9 +189,16 @@ namespace AgroBase.Services
await Task.Delay(2000);
foreach (string cmd in comandos)
{
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
{
@ -900,6 +914,8 @@ namespace AgroBase.Services
byte[] buffer = new byte[4096];
int bytesRead;
while (CorrecaoRTK_Ntrip && (bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
try
{
if (PortaGPS?.IsOpen ?? false)
{
@ -908,6 +924,11 @@ namespace AgroBase.Services
UltimoEnvioCorrecaoRTK = DateTime.Now;
}
}
catch (Exception ex)
{
Console.WriteLine($"Erro ao enviar correção RTCM para o módulo GNSS: {ex.Message}");
}
}
}
else
{