1603 lines
66 KiB
C#
1603 lines
66 KiB
C#
using AForge.Video;
|
|
using AForge.Video.DirectShow;
|
|
using AgroBase.Comum;
|
|
using AgroBase.Models;
|
|
using AgroBase.Models.Modules;
|
|
using AgroBase.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static AgroBase.Models.Enums;
|
|
|
|
namespace AgroBase.Forms.IHM
|
|
{
|
|
public partial class frmDiagnosticos : Form
|
|
{
|
|
static string[] ComplementosPadrao = { "Falha", "Sucesso" };
|
|
|
|
static List<DiagnosticoModel> Diagnosticos = new List<DiagnosticoModel>();
|
|
|
|
public static bool Diagnosticando
|
|
{
|
|
get
|
|
{
|
|
return Diagnosticos.Any(x => x.EmAndamento);
|
|
}
|
|
}
|
|
|
|
public frmDiagnosticos()
|
|
{
|
|
InitializeComponent();
|
|
|
|
FuncoesGlobais.DefinirEventosPicBtn(picVoltar, "", async () =>
|
|
{
|
|
if (Diagnosticando)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.Close();
|
|
});
|
|
FuncoesGlobais.DefinirEventosPicBtn(picDiagnosticarTudo, "Erro ao realizar diagnóstico geral!", async () =>
|
|
{
|
|
if (Diagnosticando)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (MessageBox.Show("Iniciar o diagnóstico completo do equipamento?", "Iniciar Diagnóstico", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
picLoading.Image = Properties.Resources.loading;
|
|
|
|
tabControl1.SelectedIndex = 0;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 1;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 2;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 3;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 4;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 5;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 6;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
tabControl1.SelectedIndex = 8;
|
|
await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
FinalizarDiagnostico();
|
|
|
|
picLoading.Image = null;
|
|
|
|
MessageBox.Show($"Diagnóstico completo do equipamento concluído com sucesso!", "Diagnóstico Concluído", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
});
|
|
FuncoesGlobais.DefinirEventosPicBtn(picIniciarDiagnostico, "Erro ao realizar diagnóstico do módulo " + tabControl1.SelectedTab.Text, async () =>
|
|
{
|
|
if (Diagnosticando)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string ModuloSelecionado = tabControl1.SelectedTab.Text;
|
|
if (MessageBox.Show("Iniciar o diagnóstico do módulo " + ModuloSelecionado + "?", "Iniciar Diagnóstico", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
picLoading.Image = Properties.Resources.loading;
|
|
|
|
bool Sucesso = await IniciarDiagnostico(tabControl1.SelectedIndex);
|
|
FinalizarDiagnostico();
|
|
|
|
picLoading.Image = null;
|
|
|
|
if (Sucesso)
|
|
{
|
|
MessageBox.Show($"Diagnóstico do módulo {ModuloSelecionado} concluído com sucesso!", "Diagnóstico Concluído", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show($"Diagnóstico do módulo {ModuloSelecionado} concluído com erro!", "Diagnóstico Concluído", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void frmDiagnosticos_Load(object sender, EventArgs e)
|
|
{
|
|
PreencherDadosDiagnosticos();
|
|
}
|
|
|
|
private void PreencherDadosDiagnosticos()
|
|
{
|
|
Diagnosticos = new List<DiagnosticoModel>()
|
|
{
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Atu,
|
|
Descricao = "Pulverizador",
|
|
ResultadoMinimo = 90,
|
|
grid = dgPulverizador,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Mov,
|
|
Descricao = "Movimentação",
|
|
ResultadoMinimo = 75,
|
|
grid = dgMovimentacao,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Dir,
|
|
Descricao = "Direcional",
|
|
ResultadoMinimo = 75,
|
|
grid = dgDirecional,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Pzm,
|
|
Descricao = "Sensoriamento",
|
|
ResultadoMinimo = 100,
|
|
grid = dgSensoriamento,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Lra,
|
|
Descricao = "Comunicação",
|
|
ResultadoMinimo = 60,
|
|
grid = dgComunicacao,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Cam,
|
|
Descricao = "Cameras",
|
|
ResultadoMinimo = 100,
|
|
grid = dgCameras,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
new DiagnosticoModel()
|
|
{
|
|
Modulo = T_Code.Sen,
|
|
Descricao = "Sinaleiros",
|
|
ResultadoMinimo = 90,
|
|
grid = dgSinaleiros,
|
|
Testes = new List<ColunasDiagnosticoModel>()
|
|
},
|
|
};
|
|
|
|
PreencherDadosDiagnosticoPulverizador(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Atu));
|
|
PreencherDadosDiagnosticoMovimentacao(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Mov));
|
|
PreencherDadosDiagnosticoDirecional(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Dir));
|
|
PreencherDadosDiagnosticoSensoriamento(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Pzm));
|
|
PreencherDadosDiagnosticoComunicacao(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Lra));
|
|
PreencherDadosDiagnosticoCameras(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Cam));
|
|
PreencherDadosDiagnosticoSinaleiros(Diagnosticos.FirstOrDefault(x => x.Modulo == T_Code.Sen));
|
|
PreencherDadosTabelaResultado(dgResultados);
|
|
OperacaoModel.PopularTreeView(tvwFalhas, Variaveis.OperacaoEmAndamento.RetornaCodigoFalha());
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnostico(int idx)
|
|
{
|
|
bool Sucesso = false;
|
|
|
|
if (idx == 8)
|
|
{
|
|
OperacaoModel.PopularTreeView(tvwFalhas, Variaveis.OperacaoEmAndamento.RetornaCodigoFalha());
|
|
|
|
return true;
|
|
}
|
|
|
|
var Diagnostico = Diagnosticos[idx];
|
|
Diagnostico.Testes.ForEach(x =>
|
|
{
|
|
x.Resultado = "Pendente";
|
|
x.ValorAferido = 0;
|
|
});
|
|
Diagnostico.Concluido = false;
|
|
Diagnostico.EmAndamento = true;
|
|
|
|
if (idx == 0)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoPulverizador(Diagnostico);
|
|
}
|
|
else if (idx == 1)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoMovimentacao(Diagnostico);
|
|
}
|
|
else if (idx == 2)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoDirecional(Diagnostico);
|
|
}
|
|
else if (idx == 3)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoSensoriamento(Diagnostico);
|
|
}
|
|
else if (idx == 4)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoComunicacao(Diagnostico);
|
|
}
|
|
else if (idx == 5)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoCameras(Diagnostico);
|
|
}
|
|
else if (idx == 6)
|
|
{
|
|
Sucesso = await IniciarDiagnosticoSinaleiros(Diagnostico);
|
|
}
|
|
|
|
Diagnostico.Concluido = true;
|
|
Diagnostico.EmAndamento = false;
|
|
|
|
return Sucesso;
|
|
}
|
|
|
|
private void FinalizarDiagnostico()
|
|
{
|
|
tabControl1.SelectedIndex = 7;
|
|
AualizarDadosTabelaResultado(dgResultados);
|
|
}
|
|
|
|
#region TABELAS
|
|
|
|
private int PreencheDadosLinha(DataGridView grid, List<ColunasDiagnosticoModel> Testes, int idx, double Valor)
|
|
{
|
|
var Teste = Testes[idx];
|
|
|
|
Teste.ValorAferido = Valor;
|
|
|
|
grid.Rows[idx].Cells[3].Value = Teste.ValorAferidoStr;
|
|
|
|
int Sucesso =
|
|
Teste.ComplementoValorPadrao == "<" ? (Teste.ValorAferido < Teste.ValorPadrao ? 1 : 0) :
|
|
Teste.ComplementoValorPadrao == ">" ? (Teste.ValorAferido > Teste.ValorPadrao ? 1 : 0) :
|
|
Teste.ComplementoValorPadrao == "~" ? 1 :
|
|
(Teste.ValorAferido == Teste.ValorPadrao ? 1 : 0);
|
|
|
|
Teste.Resultado = ComplementosPadrao[Sucesso];
|
|
|
|
grid.Rows[idx].Cells[4].Value = Teste.Resultado;
|
|
|
|
idx++;
|
|
|
|
AualizarDadosTabelaResultado(dgResultados);
|
|
|
|
return idx;
|
|
}
|
|
|
|
private void PreencherDadosTabelaResultado(DataGridView grid)
|
|
{
|
|
grid.Columns.Clear();
|
|
grid.Rows.Clear();
|
|
|
|
grid.Columns.Add("clModulo", "Módulo");
|
|
grid.Columns.Add("clTestes", "Testes");
|
|
grid.Columns.Add("clResultadoMinimo", "Resultado mínimo");
|
|
grid.Columns.Add("clSucesso", "Sucesso (%)");
|
|
grid.Columns.Add("clResultado", "Resultado");
|
|
|
|
foreach (var Modulo in Diagnosticos)
|
|
{
|
|
grid.Rows.Add(Modulo.Descricao, Modulo.Testes.Count().ToString(), Modulo.ResultadoMinimo.ToString("0.00") + "%", "", Modulo.Resultado);
|
|
}
|
|
|
|
grid.DefaultCellStyle.Font = new Font(FontFamily.GenericSansSerif, 10);
|
|
grid.ColumnHeadersDefaultCellStyle.Font = new Font(FontFamily.GenericSansSerif, 10);
|
|
grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
|
grid.Columns[grid.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
AualizarDadosTabelaResultado(grid);
|
|
}
|
|
|
|
private void AualizarDadosTabelaResultado(DataGridView grid)
|
|
{
|
|
for (int i = 0; i < Diagnosticos.Count(); i++)
|
|
{
|
|
grid.Rows[i].Cells[3].Value = Diagnosticos[i].PercentualSucesso.ToString("0.00") + "%";
|
|
grid.Rows[i].Cells[4].Value = Diagnosticos[i].Resultado;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS PULVERIZADOR
|
|
|
|
private void PreencherDadosDiagnosticoPulverizador(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel() { Componente = "Módulo", Teste = "Conectado", ValorPadrao = 1, ComplementoValorPadrao = ComplementosPadrao[1] },
|
|
new ColunasDiagnosticoModel() { Componente = "Módulo", Teste = "Inicializado", ValorPadrao = 1, ComplementoValorPadrao = ComplementosPadrao[1] },
|
|
new ColunasDiagnosticoModel() { Componente = "Bomba Hidráulica", Teste = "Inicializado", ValorPadrao = 1, ComplementoValorPadrao = ComplementosPadrao[1] },
|
|
new ColunasDiagnosticoModel() { Componente = "Sensor de Massa", Teste = "Inicializado", ValorPadrao = 1, ComplementoValorPadrao = ComplementosPadrao[1] },
|
|
new ColunasDiagnosticoModel() { Componente = "Sensor de Pressão", Teste = "Inicializado", ValorPadrao = 1, ComplementoValorPadrao = ComplementosPadrao[1] },
|
|
new ColunasDiagnosticoModel() { Componente = "Sensor de Fluxo", Teste = "Inicializado", ValorPadrao = 1, ComplementoValorPadrao = ComplementosPadrao[1] },
|
|
};
|
|
Testes.AddRange(Variaveis.OperacaoEmAndamento.DispAtu.Dados.BicosPulverizadores.SelectMany(x => new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Bico Pulverizador " + x.ID,
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
}
|
|
}));
|
|
Testes.AddRange(new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel() { Componente = "Bomba Hidráulica", Teste = "Atuação", ValorPadrao = 75, ComplementoValorPadrao = ">" },
|
|
new ColunasDiagnosticoModel() { Componente = "Sensor de Massa", Teste = "Leitura", ValorPadrao = 1, ComplementoValorPadrao = ">" },
|
|
new ColunasDiagnosticoModel() { Componente = "Sensor de Pressão", Teste = "Leitura", ValorPadrao = 75, ComplementoValorPadrao = ">" },
|
|
new ColunasDiagnosticoModel() { Componente = "Sensor de Fluxo", Teste = "Leitura", ValorPadrao = 5, ComplementoValorPadrao = ">" },
|
|
});
|
|
Testes.AddRange(Variaveis.OperacaoEmAndamento.DispAtu.Dados.BicosPulverizadores.SelectMany(x => new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Bico Pulverizador " + x.ID,
|
|
Teste = "Ligar",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Bico Pulverizador " + x.ID,
|
|
Teste = "Desligar",
|
|
ValorPadrao = 0,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
}
|
|
}));
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoPulverizador(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Atu);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Conectado ? 1 : 0);
|
|
|
|
DispositivosService<AtuadorModel> Dispositivo = (DispositivosService<AtuadorModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == Enums.T_Code.Atu);
|
|
bool Inicializado = Dispositivo != null && Dispositivo.Dados.Conectado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
|
|
|
|
AtuadorBombaModel Bomba = Dispositivo.Dados.BombaPressurizadora;
|
|
bool BombaInicializado = Bomba.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, BombaInicializado ? 1 : 0);
|
|
|
|
SensorModel sMAS = Dispositivo.Dados.Sensores.FirstOrDefault(x => x.Componente == Enums.S_Code.sMAS);
|
|
bool MassaInicializado = sMAS != null ? sMAS.Inicializado : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, MassaInicializado ? 1 : 0);
|
|
|
|
SensorModel sPRS = Dispositivo.Dados.Sensores.FirstOrDefault(x => x.Componente == Enums.S_Code.sPRS);
|
|
bool PressaoInicializado = sPRS != null ? sPRS.Inicializado : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, PressaoInicializado ? 1 : 0);
|
|
|
|
SensorModel sFLX = Dispositivo.Dados.Sensores.FirstOrDefault(x => x.Componente == Enums.S_Code.sFLX);
|
|
bool FluxoInicializado = sFLX != null ? sFLX.Inicializado : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, FluxoInicializado ? 1 : 0);
|
|
|
|
AtuadorBicoModel B01 = Dispositivo.Dados.BicosPulverizadores[0];
|
|
bool B01Inicializado = B01 != null && B01.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, B01Inicializado ? 1 : 0);
|
|
|
|
AtuadorBicoModel B02 = Dispositivo.Dados.BicosPulverizadores[1];
|
|
bool B02Inicializado = B02 != null && B02.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, B02Inicializado ? 1 : 0);
|
|
|
|
AtuadorBicoModel B03 = Dispositivo.Dados.BicosPulverizadores[2];
|
|
bool B03Inicializado = B03 != null && B03.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, B03Inicializado ? 1 : 0);
|
|
|
|
AtuadorBicoModel B04 = Dispositivo.Dados.BicosPulverizadores[3];
|
|
bool B04Inicializado = B04 != null && B04.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, B04Inicializado ? 1 : 0);
|
|
|
|
|
|
await EnviarComandoBomba(true, 5000);
|
|
|
|
double Pressao = PressaoInicializado ? Dispositivo.Dados.PressaoLinha : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Pressao);
|
|
|
|
double Massa = MassaInicializado ? Dispositivo.Dados.VolumeReservatorio : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Massa);
|
|
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Pressao);
|
|
|
|
await EnviarComandoBico(B01, true, 1000);
|
|
|
|
double Fluxo = FluxoInicializado ? Dispositivo.Dados.VazaoFluxoMLpS : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Fluxo);
|
|
|
|
bool statusB01_1 = B01 != null && B01.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, statusB01_1 ? 1 : 0);
|
|
|
|
await EnviarComandoBico(B01, false, 1000);
|
|
|
|
bool statusB01_0 = B01 != null && B01.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, !statusB01_0 ? 0 : 1);
|
|
|
|
await EnviarComandoBico(B02, true, 1000);
|
|
|
|
bool statusB02_1 = B02 != null && B02.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, statusB02_1 ? 1 : 0);
|
|
|
|
await EnviarComandoBico(B02, false, 1000);
|
|
|
|
bool statusB02_0 = B02 != null && B02.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, !statusB02_0 ? 0 : 1);
|
|
|
|
await EnviarComandoBico(B03, true, 1000);
|
|
|
|
bool statusB03_1 = B03 != null && B03.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, statusB03_1 ? 1 : 0);
|
|
|
|
await EnviarComandoBico(B03, false, 1000);
|
|
|
|
bool statusB03_0 = B03 != null && B03.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, !statusB03_0 ? 0 : 1);
|
|
|
|
await EnviarComandoBico(B04, true, 1000);
|
|
|
|
bool statusB04_1 = B04 != null && B04.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, statusB04_1 ? 1 : 0);
|
|
|
|
await EnviarComandoBico(B04, false, 1000);
|
|
|
|
bool statusB04_0 = B04 != null && B04.LeituraStatusBico;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, !statusB04_0 ? 0 : 1);
|
|
|
|
|
|
await EnviarComandoBomba(false, 500);
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
private async Task EnviarComandoBomba(bool Ligar, int Delay)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.PressaoLinha = 85;
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, Ligar);
|
|
await Task.Delay(Delay);
|
|
}
|
|
|
|
private async Task EnviarComandoBico(AtuadorBicoModel Bico, bool Ligar, int Delay)
|
|
{
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBIC, Ligar, Bico.ID);
|
|
await Task.Delay(Delay);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS MOVIMENTACAO
|
|
|
|
private void PreencherDadosDiagnosticoMovimentacao(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>();
|
|
Testes.AddRange(new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo SEN",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo SEN",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
});
|
|
Testes.AddRange(Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.SelectMany(x => new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "S_TMP_" + x.Modulo_ID,
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Temperatura",
|
|
ValorPadrao = 10,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Tensão",
|
|
ValorPadrao = 36,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Temperatura Driver",
|
|
ValorPadrao = 65,
|
|
ComplementoValorPadrao = "<"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Código Erro",
|
|
ValorPadrao = 0
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Para Frente",
|
|
ValorPadrao = 2,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Parado",
|
|
ValorPadrao = 0
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Para Trás",
|
|
ValorPadrao = 2,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Parado",
|
|
ValorPadrao = 0
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID + " Servo Freio",
|
|
Teste = "Ativar",
|
|
ValorPadrao = VariaveisEquipamento.AnguloFreio[AcaoFreio.Ativar]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID + " Servo Freio",
|
|
Teste = "Desativar",
|
|
ValorPadrao = VariaveisEquipamento.AnguloFreio[AcaoFreio.Desativar]
|
|
},
|
|
}));
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoMovimentacao(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
TipoMovimentoDirecional _oldTipoMovimento = Variaveis.OperacaoEmAndamento.Controle.TipoMovimento;
|
|
double _oldPercentualVelocidade = Variaveis.OperacaoEmAndamento.Controle.PercentualVelocidadeSP;
|
|
|
|
Variaveis.OperacaoEmAndamento.Controle.TipoMovimento = TipoMovimentoDirecional.Diagnostico;
|
|
Variaveis.OperacaoEmAndamento.Controle.PercentualVelocidadeSP = 20;
|
|
|
|
DispositivosService<MovimentacaoUnificadaModel> Dispositivo = (DispositivosService<MovimentacaoUnificadaModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == Enums.T_Code.Mvd);
|
|
|
|
if (Dispositivo == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
bool SenConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, SenConectado ? 1 : 0);
|
|
|
|
var Modulo_Sen = Variaveis.OperacaoEmAndamento.DispSen.Dados;
|
|
|
|
bool SenIniciado = Modulo_Sen.Conectado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, SenIniciado ? 1 : 0);
|
|
|
|
foreach (var Modulo in Dispositivo.Dados.Modulos)
|
|
{
|
|
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Bld && x.Mod_ID == Modulo.Modulo_ID);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Conectado ? 1 : 0);
|
|
|
|
bool Inicializado = Modulo.MovMotor.BLD_Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
|
|
|
|
var SensorTmp = Modulo_Sen.Sensores.FirstOrDefault(x => x.Componente == S_Code.sTMP && x.ID.Contains(Modulo.Modulo_ID));
|
|
|
|
bool TempIniciado = SensorTmp != null && SensorTmp.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, TempIniciado ? 1 : 0);
|
|
|
|
double Temperatura = TempIniciado ? Modulo.MovMotor.Temperatura : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Temperatura);
|
|
|
|
double Tensao = Inicializado ? Modulo.MovMotor.Tensao : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Tensao);
|
|
|
|
double TemperaturaDriver = Inicializado ? Modulo.MovMotor.TemperaturaDriver : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, TemperaturaDriver);
|
|
|
|
double CodigoErro = Inicializado ? Modulo.MovMotor.CodigoAlarme : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, CodigoErro);
|
|
|
|
bool ParaFrente = Inicializado ? await EnviarComandoMov(Modulo, Enums.Direcao.Frente, Testes[idx], 5000) : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
|
|
|
|
bool Parado = Inicializado ? await EnviarComandoMov(Modulo, Enums.Direcao.Parado, Testes[idx], 5000) : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
|
|
|
|
bool ParaTras = Inicializado ? await EnviarComandoMov(Modulo, Enums.Direcao.Tras, Testes[idx], 5000) : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
|
|
|
|
Parado = Inicializado ? await EnviarComandoMov(Modulo, Enums.Direcao.Parado, Testes[idx], 5000) : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
|
|
|
|
var ServoFreio = Modulo_Sen.Servos.FirstOrDefault(x => x.ID.Contains(Modulo.Modulo_ID) && x.Inicializado);
|
|
(bool atuar, int angAtivar) = Modulo.MovMotor.ConfigFreio.AtualizarDadosFreio(true, 0, 15);
|
|
bool AtivarFreio = SenIniciado && ServoFreio != null ? await EnviarComandoMovFreio(Variaveis.OperacaoEmAndamento.DispSen, ServoFreio, angAtivar, Testes[idx], 2000) : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, ServoFreio != null ? Testes[idx].ValorAferido : -1);
|
|
|
|
(bool desatuar, int angDesativar) = Modulo.MovMotor.ConfigFreio.AtualizarDadosFreio(false);
|
|
bool DesativarFreio = SenIniciado && ServoFreio != null ? await EnviarComandoMovFreio(Variaveis.OperacaoEmAndamento.DispSen, ServoFreio, angDesativar, Testes[idx], 2000) : false;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, ServoFreio != null ? Testes[idx].ValorAferido : -1);
|
|
|
|
}
|
|
|
|
Variaveis.OperacaoEmAndamento.Controle.TipoMovimento = _oldTipoMovimento;
|
|
Variaveis.OperacaoEmAndamento.Controle.PercentualVelocidadeSP = _oldPercentualVelocidade;
|
|
|
|
return true;
|
|
}
|
|
|
|
private async Task<bool> EnviarComandoMov(ModuloMvdModel Modulo, Direcao Sentido, ColunasDiagnosticoModel Teste, int Timeout)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x => x.MovMotor.Comandar = false);
|
|
Modulo.MovMotor.Comandar = true;
|
|
|
|
GeneralJoystick.EnviaComandoMotor(Sentido == Direcao.Frente ? Keys.Up : Sentido == Direcao.Tras ? Keys.Down : Keys.Escape, T_Code.Mov);
|
|
|
|
DateTime Inicio = DateTime.Now;
|
|
bool Sucesso = false;
|
|
while (!Sucesso && Inicio.AddMilliseconds(Timeout) > DateTime.Now)
|
|
{
|
|
await Task.Delay(500);
|
|
|
|
bool sentidoCorreto = Sentido == Direcao.Parado ? true :
|
|
Modulo.MovMotor.Sentido ==
|
|
(Sentido == Enums.Direcao.Frente ? Modulo.MovMotor.ConfigSentidos[Variaveis.OperacaoEmAndamento.Controle.TipoMovimento].Frente :
|
|
Sentido == Enums.Direcao.Tras ? Modulo.MovMotor.ConfigSentidos[Variaveis.OperacaoEmAndamento.Controle.TipoMovimento].Tras :
|
|
Enums.Sentido.Parado);
|
|
|
|
bool rpmCorreto =
|
|
Teste.ComplementoValorPadrao == "<" ? Modulo.MovMotor.RPM_Roda < Teste.ValorPadrao :
|
|
Teste.ComplementoValorPadrao == ">" ? Modulo.MovMotor.RPM_Roda > Teste.ValorPadrao :
|
|
Modulo.MovMotor.RPM_Roda == Teste.ValorPadrao;
|
|
|
|
Sucesso = sentidoCorreto && rpmCorreto;
|
|
}
|
|
|
|
Teste.ValorAferido = Modulo.MovMotor.RPM_Roda;
|
|
|
|
return Sucesso;
|
|
}
|
|
|
|
private async Task<bool> EnviarComandoMovFreio(DispositivosService<SensoriamentoModel> Dispositivo, SensorServoModel ServoFreio, int Angulo, ColunasDiagnosticoModel Teste, int Timeout)
|
|
{
|
|
Dispositivo.Dados.Servos.ForEach(x => x.Controlar = false);
|
|
ServoFreio.Controlar = true;
|
|
|
|
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, ServoFreio.ID, Angulo);
|
|
//Dispositivo.AdicionarMensagemFila(Dispositivo.Dados.Modulo_ID, ServoFreio.ProtocoloComando(), true, false);
|
|
|
|
DateTime Inicio = DateTime.Now;
|
|
bool Sucesso = false;
|
|
while (!Sucesso && Inicio.AddMilliseconds(Timeout) > DateTime.Now)
|
|
{
|
|
Dispositivo.Dados.RequisitarDadosModulo();
|
|
await Task.Delay(1000);
|
|
|
|
Sucesso =
|
|
Teste.ComplementoValorPadrao == "<" ? (((FirmwareServoFreio)ServoFreio.Leitura)?.Angulo ?? 0) < Teste.ValorPadrao :
|
|
Teste.ComplementoValorPadrao == ">" ? (((FirmwareServoFreio)ServoFreio.Leitura)?.Angulo ?? 0) > Teste.ValorPadrao :
|
|
(((FirmwareServoFreio)ServoFreio.Leitura)?.Angulo ?? 0) == Teste.ValorPadrao;
|
|
}
|
|
|
|
Teste.ValorAferido = (((FirmwareServoFreio)ServoFreio.Leitura)?.Angulo ?? 0);
|
|
|
|
return Sucesso;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS DIRECIONAL
|
|
|
|
private void PreencherDadosDiagnosticoDirecional(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>();
|
|
Testes.AddRange(Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.SelectMany(x => new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Código Erro",
|
|
ValorPadrao = 0
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Para Esquerda",
|
|
ValorPadrao = 20,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Para Direita",
|
|
ValorPadrao = -20,
|
|
ComplementoValorPadrao = "<"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.Modulo_ID,
|
|
Teste = "Para Zero",
|
|
ValorPadrao = 0
|
|
},
|
|
}));
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoDirecional(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
TipoMovimentoDirecional _oldTipoMovimento = Variaveis.OperacaoEmAndamento.Controle.TipoMovimento;
|
|
double _oldAngulo = Variaveis.OperacaoEmAndamento.Controle.Angulo;
|
|
|
|
Variaveis.OperacaoEmAndamento.Controle.TipoMovimento = TipoMovimentoDirecional.Diagnostico;
|
|
Variaveis.OperacaoEmAndamento.Controle.Angulo = 25;
|
|
|
|
DispositivosService<MovimentacaoUnificadaModel> Dispositivo = (DispositivosService<MovimentacaoUnificadaModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == Enums.T_Code.Mvd);
|
|
|
|
if (Dispositivo == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
foreach (var Modulo in Dispositivo.Dados.Modulos)
|
|
{
|
|
var Leitura = MKS057DService.DadosLeitura.FirstOrDefault(x => x.Endereco == Convert.ToByte(Modulo.DirMotor.Endereco, 16));
|
|
|
|
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Mks && x.Mod_ID == Modulo.Modulo_ID);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Conectado ? 1 : 0);
|
|
|
|
bool Inicializado = Modulo.DirMotor.MKS_Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
|
|
|
|
int.TryParse(Leitura?.Mensagem ?? "", out int CodigoErro);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? CodigoErro : -1);
|
|
|
|
//MKS057DService.AddrRef = Convert.ToByte(Modulo.DirMotor.Endereco, 16);
|
|
|
|
if (Inicializado)
|
|
{
|
|
await EnviarComandoDir(Modulo, Enums.Direcao.Esquerda, Testes[idx], 5000);
|
|
}
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Testes[idx].ValorAferido);
|
|
|
|
if (Inicializado)
|
|
{
|
|
await EnviarComandoDir(Modulo, Enums.Direcao.Direita, Testes[idx], 5000);
|
|
}
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Testes[idx].ValorAferido);
|
|
|
|
if (Inicializado)
|
|
{
|
|
await EnviarComandoDir(Modulo, Enums.Direcao.Parado, Testes[idx], 5000);
|
|
}
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Testes[idx].ValorAferido);
|
|
|
|
//MKS057DService.AddrRef = 0x00;
|
|
|
|
}
|
|
|
|
Variaveis.OperacaoEmAndamento.Controle.TipoMovimento = _oldTipoMovimento;
|
|
Variaveis.OperacaoEmAndamento.Controle.Angulo = _oldAngulo;
|
|
|
|
return true;
|
|
}
|
|
|
|
private async Task EnviarComandoDir(ModuloMvdModel Modulo, Enums.Direcao Sentido, ColunasDiagnosticoModel Teste, int Timeout)
|
|
{
|
|
await Modulo.DirMotor.EnviarComandoControle(Sentido);
|
|
|
|
DateTime Inicio = DateTime.Now;
|
|
bool Sucesso = false;
|
|
while (!Sucesso && Inicio.AddMilliseconds(Timeout) > DateTime.Now)
|
|
{
|
|
await Task.Delay(200);
|
|
|
|
/*bool sentidoCorreto = Modulo.DirMotor.Sentido ==
|
|
(Sentido == Enums.Direcao.Esquerda ? Modulo.DirMotor.ConfigSentidos[Variaveis.OperacaoEmAndamento.Controle.TipoMovimento].Esquerda :
|
|
Sentido == Enums.Direcao.Direita ? Modulo.DirMotor.ConfigSentidos[Variaveis.OperacaoEmAndamento.Controle.TipoMovimento].Direita :
|
|
Enums.Sentido.Parado);*/
|
|
|
|
bool anguloCorreto =
|
|
Teste.ComplementoValorPadrao == "<" ? Modulo.DirMotor.Angulo < Teste.ValorPadrao :
|
|
Teste.ComplementoValorPadrao == ">" ? Modulo.DirMotor.Angulo > Teste.ValorPadrao :
|
|
Modulo.DirMotor.Angulo == Teste.ValorPadrao;
|
|
|
|
Sucesso = anguloCorreto;
|
|
}
|
|
|
|
Teste.ValorAferido = Modulo.DirMotor.Angulo;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS SENSORIAMENTO
|
|
|
|
private void PreencherDadosDiagnosticoSensoriamento(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>();
|
|
Testes.AddRange(new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "PZEM",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "PZEM",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "PZEM",
|
|
Teste = "Tensão Bateria",
|
|
ValorPadrao = 36,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "PZEM",
|
|
Teste = "Corrente Bateria",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Tensão Barramento 5V",
|
|
ValorPadrao = 4.95,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Corrente Barramento 5V",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Tensão Barramento 12V",
|
|
ValorPadrao = 11.5,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Corrente Barramento 12V",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "WIT MOTION",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "WIT MOTION",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "WIT MOTION",
|
|
Teste = "Orientação Magnética",
|
|
ValorPadrao = 0,
|
|
ComplementoValorPadrao = "~"
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "GPS",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "GPS",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "GPS",
|
|
Teste = "Precisão",
|
|
ValorPadrao = 85,
|
|
ComplementoValorPadrao = ">"
|
|
},
|
|
});
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoSensoriamento(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
bool PzmConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Pzm);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, PzmConectado ? 1 : 0);
|
|
|
|
bool PzmInicializado = PZEMService.Iniciado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, PzmInicializado ? 1 : 0);
|
|
|
|
double Tensao = PzmInicializado ? PZEMService.UltimaLeitura.Tensao : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Tensao);
|
|
|
|
double Corrente = PzmInicializado ? PZEMService.UltimaLeitura.Corrente : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Corrente);
|
|
|
|
bool SenConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, SenConectado ? 1 : 0);
|
|
|
|
var Modulo_Sen = Variaveis.OperacaoEmAndamento.DispSen.Dados;
|
|
|
|
bool SenIniciado = Modulo_Sen.Conectado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, SenIniciado ? 1 : 0);
|
|
|
|
var S5V = Modulo_Sen.DadosLeitura.SensoresCorrente.FirstOrDefault(x => x.ID == "AB5V");
|
|
double Tensao5V = S5V != null ? (double)S5V.Current : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Tensao5V);
|
|
|
|
double Corrente5V = S5V != null ? (double)S5V.Current : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Corrente5V);
|
|
|
|
var S12V = Modulo_Sen.DadosLeitura.SensoresCorrente.FirstOrDefault(x => x.ID == "AB12V");
|
|
double Tensao12V = S12V != null ? (double)S12V.Current : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Tensao12V);
|
|
|
|
double Corrente12V = S12V != null ? (double)S12V.Current : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Corrente12V);
|
|
|
|
bool WitConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Wit);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, WitConectado ? 1 : 0);
|
|
|
|
bool WitInicializado = WT901CService.Iniciado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, WitInicializado ? 1 : 0);
|
|
|
|
double Orientacao = WitInicializado ? WT901CService.DadosLeitura.AngleZ : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Orientacao);
|
|
|
|
bool GpsConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Gps);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, GpsConectado ? 1 : 0);
|
|
|
|
bool GpsInicializado = GPSService.Iniciado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, GpsInicializado ? 1 : 0);
|
|
|
|
double Precisao = GpsInicializado ? GPSService.UltimaLeitura.PrecisaoHorizontal : -1;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Precisao);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS COMUNICACAO
|
|
|
|
private void PreencherDadosDiagnosticoComunicacao(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>();
|
|
Testes.AddRange(new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo Sen",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "RLLRA",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "RLLRA",
|
|
Teste = "Ligar",
|
|
ValorPadrao = 1,
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "RLLRA",
|
|
Teste = "Desligar",
|
|
ValorPadrao = 0,
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo LoRa",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo LoRa",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo LoRa",
|
|
Teste = "Parametrizado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo LoRa",
|
|
Teste = "Envio",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo LoRa",
|
|
Teste = "Recebimento",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
});
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoComunicacao(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
bool SenConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, SenConectado ? 1 : 0);
|
|
|
|
DispositivosService<SensoriamentoModel> Dispositivo = (DispositivosService<SensoriamentoModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == T_Code.Sen);
|
|
bool SenInicializado = Dispositivo != null && Dispositivo.Dados.Conectado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, SenInicializado ? 1 : 0);
|
|
|
|
SensorReleModel ReleLra = Dispositivo.Dados.Reles.FirstOrDefault(x => x.ID == "RLLRA");
|
|
|
|
bool RlInicializado = SenInicializado && ReleLra != null && ReleLra.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, RlInicializado ? 1 : 0);
|
|
|
|
await EnviarComandoRele(Dispositivo, ReleLra, true, 1000);
|
|
|
|
bool RlStatus = RlInicializado && (((FirmwareRele)ReleLra.Leitura)?.Leitura ?? Estado.Desligado) == Estado.Ligado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, RlStatus ? 1 : 0);
|
|
|
|
await EnviarComandoRele(Dispositivo, ReleLra, false, 1000);
|
|
|
|
RlStatus = RlInicializado && (((FirmwareRele)ReleLra.Leitura)?.Leitura ?? Estado.Desligado) == Estado.Ligado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, !RlStatus ? 0 : 1);
|
|
|
|
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Lra);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Conectado ? 1 : 0);
|
|
|
|
bool Inicializado = LoRaService.Iniciado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
|
|
|
|
(bool sucesso, LoRaParametrosModel parametros) = await Variaveis.ConexaoLoRa.RequisitarParametrosModuloAsync();
|
|
|
|
bool Parametrizado = Inicializado && sucesso && Variaveis.ConexaoLoRa.parametros != null;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Parametrizado ? 1 : 0);
|
|
|
|
int msgEnviadasAnterior = LoRaService.MensagensEnviadas;
|
|
LoRaService.EnviarDadosParaBase();
|
|
await Task.Delay(2000);
|
|
bool MensagemEnviada = LoRaService.MensagensEnviadas > msgEnviadasAnterior;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, MensagemEnviada ? 1 : 0);
|
|
|
|
await Task.Delay(VariaveisEquipamento.TempoEntrePingsConexao);
|
|
bool MensagemRecebida = VariaveisOperacao.PosicaoBase != null;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, MensagemRecebida ? 1 : 0);
|
|
|
|
return true;
|
|
}
|
|
|
|
private async Task EnviarComandoRele(DispositivosService<SensoriamentoModel> Dispositivo, SensorReleModel Rele, bool Ligar, int Delay)
|
|
{
|
|
var novoEstado = Ligar ? Estado.Ligado : Estado.Desligado;
|
|
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sRLE, Rele.ID, novoEstado);
|
|
await Task.Delay(Delay);
|
|
Dispositivo.Dados.RequisitarDadosModulo();
|
|
await Task.Delay(Delay);
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS CAMERAS
|
|
|
|
Bitmap bitmapCamera = null;
|
|
|
|
private void PreencherDadosDiagnosticoCameras(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>();
|
|
Testes.AddRange(new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Caminho Frontal",
|
|
Teste = "Configurado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Caminho Frontal",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Caminho Frontal",
|
|
Teste = "Vídeo",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Pulverizador Esquerdo",
|
|
Teste = "Configurado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Pulverizador Esquerdo",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Pulverizador Esquerdo",
|
|
Teste = "Vídeo",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Pulverizador Direito",
|
|
Teste = "Configurado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Pulverizador Direito",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Pulverizador Direito",
|
|
Teste = "Vídeo",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
});
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoCameras(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
|
|
List<string> CamerasIDs = new List<string>();
|
|
foreach (FilterInfo info in videoDevices)
|
|
{
|
|
CamerasIDs.Add(info.MonikerString.ToLower());
|
|
}
|
|
|
|
string IDcamRua = (Variaveis.OperacaoEmAndamento.DispSen.Dados.CameraID_Caminho ?? "").Replace("\\", "#").ToLower();
|
|
|
|
bool RuaConfigurado = !string.IsNullOrEmpty(IDcamRua) && IDcamRua != "Sem video";
|
|
idx = PreencheDadosLinha(grid, Testes, idx, RuaConfigurado ? 1 : 0);
|
|
|
|
bool RuaConectado = RuaConfigurado && CamerasIDs.Any(x => x.Contains(IDcamRua));
|
|
idx = PreencheDadosLinha(grid, Testes, idx, RuaConectado ? 1 : 0);
|
|
|
|
bool RuaVideo = await VerificaImagemCamera(CamerasIDs, IDcamRua, RuaConectado);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, RuaVideo ? 1 : 0);
|
|
|
|
string IDcamEsq = (Variaveis.OperacaoEmAndamento.DispSen.Dados.CameraID_Solo[0] ?? "").Replace("\\", "#").ToLower();
|
|
|
|
bool EsqConfigurado = !string.IsNullOrEmpty(IDcamEsq) && IDcamEsq != "Sem video";
|
|
idx = PreencheDadosLinha(grid, Testes, idx, EsqConfigurado ? 1 : 0);
|
|
|
|
bool EsqConectado = EsqConfigurado && CamerasIDs.Any(x => x.Contains(IDcamEsq));
|
|
idx = PreencheDadosLinha(grid, Testes, idx, EsqConectado ? 1 : 0);
|
|
|
|
bool EsqVideo = await VerificaImagemCamera(CamerasIDs, IDcamEsq, EsqConectado);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, EsqVideo ? 1 : 0);
|
|
|
|
string IDcamDir = (Variaveis.OperacaoEmAndamento.DispSen.Dados.CameraID_Solo[1] ?? "").Replace("\\", "#").ToLower();
|
|
|
|
bool DirConfigurado = !string.IsNullOrEmpty(IDcamDir) && IDcamDir != "Sem video";
|
|
idx = PreencheDadosLinha(grid, Testes, idx, DirConfigurado ? 1 : 0);
|
|
|
|
bool DirConectado = DirConfigurado && CamerasIDs.Any(x => x.Contains(IDcamDir));
|
|
idx = PreencheDadosLinha(grid, Testes, idx, DirConectado ? 1 : 0);
|
|
|
|
bool DirVideo = await VerificaImagemCamera(CamerasIDs, IDcamDir, DirConectado);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, DirVideo ? 1 : 0);
|
|
|
|
return true;
|
|
}
|
|
|
|
private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
|
|
{
|
|
bitmapCamera = (Bitmap)eventArgs.Frame.Clone();
|
|
picCamera.Image = bitmapCamera;
|
|
}
|
|
|
|
private async Task<bool> VerificaImagemCamera(List<string> CamerasIDs, string ID, bool Conecatdo)
|
|
{
|
|
if (!Conecatdo)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
VideoCaptureDevice videoSource;
|
|
videoSource = new VideoCaptureDevice(CamerasIDs.First(x => x.Contains(ID)));
|
|
videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
|
|
videoSource.Start();
|
|
|
|
DateTime Inicio = DateTime.Now;
|
|
while (bitmapCamera == null && Inicio.AddMilliseconds(5000) > DateTime.Now)
|
|
{
|
|
await Task.Delay(200);
|
|
}
|
|
|
|
bool VideoSucesso = bitmapCamera != null && !IsBlackFrame(bitmapCamera);
|
|
bitmapCamera = null;
|
|
videoSource.Stop();
|
|
|
|
return VideoSucesso;
|
|
}
|
|
|
|
private bool IsBlackFrame(Bitmap bitmap)
|
|
{
|
|
float brightnessThreshold = 0.1f; // Ajuste conforme necessário
|
|
float totalBrightness = 0;
|
|
int pixelCount = bitmap.Width * bitmap.Height;
|
|
|
|
for (int y = 0; y < bitmap.Height; y++)
|
|
{
|
|
for (int x = 0; x < bitmap.Width; x++)
|
|
{
|
|
Color pixelColor = bitmap.GetPixel(x, y);
|
|
totalBrightness += pixelColor.GetBrightness();
|
|
}
|
|
}
|
|
|
|
float averageBrightness = totalBrightness / pixelCount;
|
|
return averageBrightness < brightnessThreshold;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DIAGNOSTICOS SINALEIROS
|
|
|
|
private void PreencherDadosDiagnosticoSinaleiros(DiagnosticoModel Diagnostico)
|
|
{
|
|
var Testes = new List<ColunasDiagnosticoModel>();
|
|
Testes.AddRange(new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo",
|
|
Teste = "Conectado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = "Módulo",
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
});
|
|
Testes.AddRange(Variaveis.OperacaoEmAndamento.DispSen.Dados.Sinaleiros.SelectMany(x => new List<ColunasDiagnosticoModel>()
|
|
{
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.ID,
|
|
Teste = "Inicializado",
|
|
ValorPadrao = 1,
|
|
ComplementoValorPadrao = ComplementosPadrao[1]
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.ID,
|
|
Teste = "Ligar",
|
|
ValorPadrao = 1,
|
|
},
|
|
new ColunasDiagnosticoModel()
|
|
{
|
|
Componente = x.ID,
|
|
Teste = "Desligar",
|
|
ValorPadrao = 0,
|
|
},
|
|
}));
|
|
|
|
Diagnostico.Testes = Testes;
|
|
Diagnostico.PreencherDadosTabela();
|
|
}
|
|
|
|
private async Task<bool> IniciarDiagnosticoSinaleiros(DiagnosticoModel Diagnostico)
|
|
{
|
|
int idx = 0;
|
|
|
|
var grid = Diagnostico.grid;
|
|
var Testes = Diagnostico.Testes;
|
|
|
|
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enums.T_Code.Sen);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Conectado ? 1 : 0);
|
|
|
|
DispositivosService<SensoriamentoModel> Dispositivo = (DispositivosService<SensoriamentoModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == Enums.T_Code.Sen);
|
|
bool Inicializado = Dispositivo != null && Dispositivo.Dados.Conectado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
|
|
|
|
foreach (var Sinaleiro in Dispositivo.Dados.Sinaleiros)
|
|
{
|
|
bool Iniciado = Sinaleiro.Inicializado;
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
|
|
|
|
if (Iniciado)
|
|
{
|
|
await EnviarComandoSinaleiro(Dispositivo, Sinaleiro, true, 1000);
|
|
}
|
|
|
|
StatusLED Status = (((FirmwareSinaleiro)Sinaleiro.Leitura)?.Leitura ?? StatusLED.Apagado);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Iniciado && Status == StatusLED.Aceso ? 1 : 0);
|
|
|
|
if (Iniciado)
|
|
{
|
|
await EnviarComandoSinaleiro(Dispositivo, Sinaleiro, false, 1000);
|
|
}
|
|
|
|
Status = (((FirmwareSinaleiro)Sinaleiro.Leitura)?.Leitura ?? StatusLED.Apagado);
|
|
idx = PreencheDadosLinha(grid, Testes, idx, Iniciado && Status == StatusLED.Apagado ? 0 : 1);
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
private async Task EnviarComandoSinaleiro(DispositivosService<SensoriamentoModel> Dispositivo, SensorSinaleiroModel Sinaleiro, bool Ligar, int Delay)
|
|
{
|
|
var Comportamento = VariaveisEquipamento.ComportamentoPorStatus(StatusOperacao.NaoIniciado);
|
|
Comportamento.statusLED = Ligar ? StatusLED.Aceso : StatusLED.Apagado;
|
|
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sLED, Sinaleiro.ID, Comportamento);
|
|
await Task.Delay(Delay);
|
|
Dispositivo.Dados.RequisitarDadosModulo();
|
|
await Task.Delay(Delay);
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
class DiagnosticoModel
|
|
{
|
|
public T_Code Modulo { get; set; }
|
|
public string Descricao { get; set; }
|
|
public double ResultadoMinimo { get; set; }
|
|
public bool EmAndamento { get; set; }
|
|
public bool Concluido { get; set; }
|
|
public double PercentualSucesso
|
|
{
|
|
get
|
|
{
|
|
double sucesso = Testes.Count(x => x.Resultado == ComplementosPadrao[1]);
|
|
double resultado = sucesso > 0 ? (sucesso / Testes.Count() * 100) : 0;
|
|
return resultado;
|
|
}
|
|
}
|
|
public string Resultado
|
|
{
|
|
get
|
|
{
|
|
return
|
|
EmAndamento ? "Diagnosticando..." :
|
|
Concluido ? (PercentualSucesso >= ResultadoMinimo) ? "Apto" : "Inapto" :
|
|
"Pendente";
|
|
}
|
|
}
|
|
public DataGridView grid { get; set; }
|
|
public List<ColunasDiagnosticoModel> Testes { get; set; }
|
|
|
|
private void DefinirEstiloTabela()
|
|
{
|
|
grid.DefaultCellStyle.Font = new Font(FontFamily.GenericSansSerif, 10);
|
|
grid.ColumnHeadersDefaultCellStyle.Font = new Font(FontFamily.GenericSansSerif, 10);
|
|
grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
|
grid.Columns[grid.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
}
|
|
|
|
|
|
private void PreencheCabecalho()
|
|
{
|
|
grid.Columns.Clear();
|
|
grid.Rows.Clear();
|
|
|
|
grid.Columns.Add("clComponente", "Componente");
|
|
grid.Columns.Add("clTeste", "Teste");
|
|
grid.Columns.Add("clValorPadrao", "Valor Padrão");
|
|
grid.Columns.Add("clValorAferido", "Valor Aferido");
|
|
grid.Columns.Add("clResultado", "Resultado");
|
|
|
|
DefinirEstiloTabela();
|
|
}
|
|
|
|
|
|
public void PreencherDadosTabela()
|
|
{
|
|
PreencheCabecalho();
|
|
|
|
foreach (var teste in Testes)
|
|
{
|
|
string valorPadrao =
|
|
ComplementosPadrao.Contains(teste.ComplementoValorPadrao) ? teste.ComplementoValorPadrao :
|
|
!string.IsNullOrEmpty(teste.ComplementoValorPadrao) ? teste.ComplementoValorPadrao + " " + teste.ValorPadrao.ToString() :
|
|
teste.ValorPadrao.ToString();
|
|
grid.Rows.Add(teste.Componente, teste.Teste, valorPadrao, teste.ValorAferido, teste.Resultado);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
class ColunasDiagnosticoModel
|
|
{
|
|
public string Componente { get; set; }
|
|
public string Teste { get; set; }
|
|
public double ValorPadrao { get; set; }
|
|
public string ComplementoValorPadrao { get; set; }
|
|
public double ValorAferido { get; set; }
|
|
public string ValorAferidoStr
|
|
{
|
|
get
|
|
{
|
|
return
|
|
ComplementosPadrao.Contains(ComplementoValorPadrao) ? ComplementosPadrao[Convert.ToInt32(ValorAferido)] :
|
|
ValorAferido.ToString("0.00");
|
|
}
|
|
}
|
|
public string Resultado { get; set; } = "Pendente";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|