alterado timers para AsyncTaskTimer

This commit is contained in:
Diego Freitas 2024-11-25 09:14:59 -03:00
parent 37b3d52927
commit 80dcf09073
72 changed files with 5032 additions and 1232 deletions

Binary file not shown.

View File

@ -416,6 +416,7 @@
<DependentUpon>frmSonar.cs</DependentUpon>
</Compile>
<Compile Include="Models\AlarmeModel.cs" />
<Compile Include="Models\AsyncTaskTimerModel.cs" />
<Compile Include="Models\BLD300RModel.cs" />
<Compile Include="Models\CameraCaminhoModel.cs" />
<Compile Include="Models\CameraModel.cs" />

View File

@ -1,6 +1,7 @@
using AgroBase.Comum;
using AgroBase.Models;
using AgroBase.Models.Modules;
using CefSharp.DevTools.Page;
using Microsoft.DirectX.PrivateImplementationDetails;
using System;
using System.Collections.Generic;
@ -9,6 +10,7 @@ using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using static AgroBase.Models.Enums;
@ -17,7 +19,7 @@ namespace AgroBase.Forms.Atuador
{
public partial class frmAtuCalibragem : Form
{
Timer tmrLeitura = new Timer() { Interval = 1000 };
AsyncTaskTimerModel tmrLeitura;
DispositivosService<AtuadorModel> DispAtu = (DispositivosService<AtuadorModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == T_Code.Atu);
CalibragemVazao _CalibragemVazao = new CalibragemVazao();
@ -55,7 +57,7 @@ namespace AgroBase.Forms.Atuador
grdSensoriamento.Rows.Add(new object[] { "Percentual", "0" });
tmrLeitura.Tick += TmrLeitura_Tick;
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 1000, this);
tmrLeitura.Start();
}
@ -121,7 +123,7 @@ namespace AgroBase.Forms.Atuador
}
private void TmrLeitura_Tick(object sender, EventArgs e)
private async Task tmrLeitura_Tick()
{
DispAtu = (DispositivosService<AtuadorModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == T_Code.Atu);

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using AgroBase.Models;
using AgroBase.Services;
@ -13,7 +14,7 @@ namespace AgroBase.Forms
public partial class frmAtuCamera : Form
{
private CameraSoloModel cameraSolo = new CameraSoloModel();
private Timer tmrLeitura;
private AsyncTaskTimerModel tmrLeitura;
public frmAtuCamera()
{
@ -53,7 +54,7 @@ namespace AgroBase.Forms
}
}
private void TmrLeitura_Tick(object sender, EventArgs e)
private async Task tmrLeitura_Tick()
{
ListarObjetosDetectados();
}
@ -102,8 +103,7 @@ namespace AgroBase.Forms
cameraSolo.tmrProcesso
);
tmrLeitura = new Timer() { Interval = 200 };
tmrLeitura.Tick += TmrLeitura_Tick;
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 200);
tmrLeitura.Start();
}

View File

@ -30,6 +30,8 @@ namespace AgroBase.Forms.Direcional
private void InitializeComponent()
{
this.gpbSentido = new System.Windows.Forms.GroupBox();
this.lblIP = new System.Windows.Forms.Label();
this.txtIP = new System.Windows.Forms.TextBox();
this.cmbTipoMovimento = new System.Windows.Forms.ComboBox();
this.lblTipoMovimento = new System.Windows.Forms.Label();
this.btnSalvarSentido = new System.Windows.Forms.Button();
@ -69,8 +71,6 @@ namespace AgroBase.Forms.Direcional
this.cmbETEsquerda = new System.Windows.Forms.ComboBox();
this.lblETEsquerda = new System.Windows.Forms.Label();
this.lblETDireita = new System.Windows.Forms.Label();
this.lblIP = new System.Windows.Forms.Label();
this.txtIP = new System.Windows.Forms.TextBox();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDFOffset)).BeginInit();
@ -102,6 +102,25 @@ namespace AgroBase.Forms.Direcional
this.gpbSentido.TabStop = false;
this.gpbSentido.Text = "Sentido de giro";
//
// lblIP
//
this.lblIP.AutoSize = true;
this.lblIP.Location = new System.Drawing.Point(10, 326);
this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblIP.Name = "lblIP";
this.lblIP.Size = new System.Drawing.Size(17, 13);
this.lblIP.TabIndex = 143;
this.lblIP.Text = "IP";
//
// txtIP
//
this.txtIP.Location = new System.Drawing.Point(13, 343);
this.txtIP.Margin = new System.Windows.Forms.Padding(2);
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(85, 20);
this.txtIP.TabIndex = 142;
this.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// cmbTipoMovimento
//
this.cmbTipoMovimento.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@ -201,6 +220,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbDFDireita
//
this.cmbDFDireita.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDFDireita.FormattingEnabled = true;
this.cmbDFDireita.Location = new System.Drawing.Point(66, 25);
this.cmbDFDireita.Margin = new System.Windows.Forms.Padding(2);
@ -210,6 +230,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbDFEsquerda
//
this.cmbDFEsquerda.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDFEsquerda.FormattingEnabled = true;
this.cmbDFEsquerda.Location = new System.Drawing.Point(66, 50);
this.cmbDFEsquerda.Margin = new System.Windows.Forms.Padding(2);
@ -306,6 +327,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbEFDireita
//
this.cmbEFDireita.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbEFDireita.FormattingEnabled = true;
this.cmbEFDireita.Location = new System.Drawing.Point(66, 25);
this.cmbEFDireita.Margin = new System.Windows.Forms.Padding(2);
@ -315,6 +337,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbEFEsquerda
//
this.cmbEFEsquerda.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbEFEsquerda.FormattingEnabled = true;
this.cmbEFEsquerda.Location = new System.Drawing.Point(66, 50);
this.cmbEFEsquerda.Margin = new System.Windows.Forms.Padding(2);
@ -411,6 +434,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbDTDireita
//
this.cmbDTDireita.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDTDireita.FormattingEnabled = true;
this.cmbDTDireita.Location = new System.Drawing.Point(66, 25);
this.cmbDTDireita.Margin = new System.Windows.Forms.Padding(2);
@ -420,6 +444,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbDTEsquerda
//
this.cmbDTEsquerda.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDTEsquerda.FormattingEnabled = true;
this.cmbDTEsquerda.Location = new System.Drawing.Point(66, 50);
this.cmbDTEsquerda.Margin = new System.Windows.Forms.Padding(2);
@ -516,6 +541,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbETDireita
//
this.cmbETDireita.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbETDireita.FormattingEnabled = true;
this.cmbETDireita.Location = new System.Drawing.Point(66, 25);
this.cmbETDireita.Margin = new System.Windows.Forms.Padding(2);
@ -525,6 +551,7 @@ namespace AgroBase.Forms.Direcional
//
// cmbETEsquerda
//
this.cmbETEsquerda.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbETEsquerda.FormattingEnabled = true;
this.cmbETEsquerda.Location = new System.Drawing.Point(66, 50);
this.cmbETEsquerda.Margin = new System.Windows.Forms.Padding(2);
@ -552,25 +579,6 @@ namespace AgroBase.Forms.Direcional
this.lblETDireita.TabIndex = 2;
this.lblETDireita.Text = "Direita";
//
// lblIP
//
this.lblIP.AutoSize = true;
this.lblIP.Location = new System.Drawing.Point(10, 326);
this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblIP.Name = "lblIP";
this.lblIP.Size = new System.Drawing.Size(17, 13);
this.lblIP.TabIndex = 143;
this.lblIP.Text = "IP";
//
// txtIP
//
this.txtIP.Location = new System.Drawing.Point(13, 343);
this.txtIP.Margin = new System.Windows.Forms.Padding(2);
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(85, 20);
this.txtIP.TabIndex = 142;
this.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// frmDirConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -189,7 +189,7 @@ namespace AgroBase.Forms.IHM
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSourceEsquerda;
private VideoCaptureDevice videoSourceDireita;
private Timer tmrKinect;
private AsyncTaskTimerModel tmrKinect;
private void AtualizarCameras()
{
@ -286,7 +286,7 @@ namespace AgroBase.Forms.IHM
}
}
private void TmrKinect_Tick(object sender, EventArgs e)
private async Task tmrKinect_Tick()
{
Bitmap bitmap = (Bitmap)(chbKinect.Checked ? KinectService.bitmapMap : KinectService.bitmapRGB).Clone();
picCentro.Image = bitmap;
@ -315,10 +315,7 @@ namespace AgroBase.Forms.IHM
{
if (tmrKinect == null)
{
tmrKinect = new Timer();
tmrKinect.Interval = 100;
tmrKinect.Tick -= TmrKinect_Tick;
tmrKinect.Tick += TmrKinect_Tick;
tmrKinect = new AsyncTaskTimerModel(tmrKinect_Tick, 100, this);
tmrKinect.Start();
}
}

View File

@ -662,10 +662,12 @@ namespace AgroBase.Forms.IHM
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 AtivarFreio = SenIniciado && ServoFreio != null ? await EnviarComandoMovFreio(Variaveis.OperacaoEmAndamento.DispSen, ServoFreio, AcaoFreio.Ativar, Testes[idx], 2000) : false;
(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 DesativarFreio = SenIniciado && ServoFreio != null ? await EnviarComandoMovFreio(Variaveis.OperacaoEmAndamento.DispSen, ServoFreio, AcaoFreio.Desativar, Testes[idx], 2000) : false;
(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);
}
@ -708,12 +710,12 @@ namespace AgroBase.Forms.IHM
return Sucesso;
}
private async Task<bool> EnviarComandoMovFreio(DispositivosService<SensoriamentoModel> Dispositivo, SensorServoModel ServoFreio, AcaoFreio Acao, ColunasDiagnosticoModel Teste, int Timeout)
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, Acao);
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, ServoFreio.ID, Angulo);
//Dispositivo.AdicionarMensagemFila(Dispositivo.Dados.Modulo_ID, ServoFreio.ProtocoloComando(), true, false);
DateTime Inicio = DateTime.Now;

View File

@ -7,7 +7,7 @@ using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Timers;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
@ -15,8 +15,8 @@ namespace AgroBase.Forms.IHM
{
public partial class frmIHM : Form
{
System.Timers.Timer tmrDispositivos = new System.Timers.Timer() { Interval = 1000, Enabled = false };
System.Timers.Timer tmrAtualizacaoArquivos = new System.Timers.Timer() { Interval = 300, Enabled = false };
AsyncTaskTimerModel tmrDispositivos;
AsyncTaskTimerModel tmrAtualizacaoArquivos;
public ulong CodFalha = 0;
public frmIHM()
@ -97,30 +97,80 @@ namespace AgroBase.Forms.IHM
private void frmIHM_Load(object sender, EventArgs e)
{
lblVersao.Text = "v " + Variaveis.Versao;
tmrDispositivos.Elapsed += TmrDispositivos_Elapsed;
tmrDispositivos = new AsyncTaskTimerModel(tmrDispositivos_Tick, 5000, this);
tmrDispositivos.Start();
tmrAtualizacaoArquivos.Elapsed += TmrAtualizacaoArquivos_Elapsed;
tmrAtualizacaoArquivos = new AsyncTaskTimerModel(tmrAtualizacaoArquivos_Tick, 300, this);
tmrAtualizacaoArquivos.Start();
lblCodigoFalha.Click += LblCodigoFalha_Click;
}
private void TmrAtualizacaoArquivos_Elapsed(object sender, ElapsedEventArgs e)
private async Task tmrAtualizacaoArquivos_Tick()
{
tmrAtualizacaoArquivos.Stop();
lblProgressoAtualizacao.Text = VersionamentoService.AtualizandoArquivos ? $"({VersionamentoService.ProgressoAtualizacao.ToString("0.00")}%) Atualizando arquivos..." : VersionamentoService.ResultadoAtualizacao;
pgbAtualizacaoArquivos.Value = (int)VersionamentoService.ProgressoAtualizacao;
Func<bool> func = new Func<bool>(() =>
tmrAtualizacaoArquivos.SetInterval(VersionamentoService.AtualizandoArquivos ? 300 : 5000);
}
private async Task tmrDispositivos_Tick()
{
CodFalha = Variaveis.OperacaoEmAndamento.RetornaCodigoFalha();
var Labels = this.Controls.OfType<Label>().Where(y => y.Name.Contains("lblD_")).ToList();
Labels.ForEach(lbl =>
{
//pgbAtualizacaoArquivos.Visible = VersionamentoService.AtualizandoArquivos;
//lblProgressoAtualizacao.Visible = VersionamentoService.AtualizandoArquivos;
lblProgressoAtualizacao.Text = VersionamentoService.AtualizandoArquivos ? $"({VersionamentoService.ProgressoAtualizacao.ToString("0.00")}%) Atualizando arquivos..." : VersionamentoService.ResultadoAtualizacao;
pgbAtualizacaoArquivos.Value = (int)VersionamentoService.ProgressoAtualizacao;
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(pgbAtualizacaoArquivos, func);
T_Code Dispositivo = (T_Code)Enum.Parse(typeof(T_Code), lbl.Name.Split('_')[1]);
string Mod_ID = lbl.Name.Split('_').Length == 3 ? lbl.Name.Split('_')[2] : lbl.Name.Split('_')[1];
tmrAtualizacaoArquivos.Start();
if (Dispositivo == T_Code.Cam)
{
var listaCameras = CameraService.AtualizaListaCameras();
var CameraCaminho = Variaveis.OperacaoEmAndamento.CameraCaminhoKinect;
if (CameraCaminho != null && Mod_ID == CameraCaminho.ID)
{
lbl.ForeColor = !listaCameras.Any(x => x.Value == CameraCaminho.CameraSelecionada) ? Color.DarkRed : CameraCaminho.camera.selectedCamera == 0 ? Color.Gold : Color.DarkGreen;
}
else
{
var CameraSolo = Variaveis.OperacaoEmAndamento.CamerasSolo.FirstOrDefault(x => x.ID == Mod_ID);
if (CameraSolo != null)
{
lbl.ForeColor = !listaCameras.Any(x => x.Value == CameraSolo.CameraSelecionada) ? Color.DarkRed : CameraSolo.camera.selectedCamera == 0 ? Color.Gold : Color.DarkGreen;
}
}
}
else
{
var Modulo = SerialService.DispositivosMapeados.FirstOrDefault(x => x.Dispositivo == Dispositivo && (x.Mod_ID == Mod_ID || x.Mod_ID == null));
if (Modulo != null)
{
lbl.ForeColor = Modulo.Erro ? Color.Gold : Modulo.Conectado ? Color.DarkGreen : Color.DarkRed;
}
else
{
lbl.ForeColor = Color.Black;
}
}
});
if (SerialService.DispositivosMapeados.Count == 0)
{
Variaveis.DispositivosConectados.Where(x => x.Dados.GetStatusConexao()).ToList().ForEach(x => x.AcaoDesconectar());
}
bool mqttConectado = Variaveis.MqttService.StatusConexao();
lblMqtt.Text = "MQTT: " + (mqttConectado ? "Conectado" : "Desconectado");
lblMqtt.ForeColor = mqttConectado ? Color.Green : Color.Red;
bool opLiberada = Variaveis.OperacaoEmAndamento.OperacaoLiberada;
lblOperacaoLiberada.Text = "Operação Liberada: " + (opLiberada ? "Sim" : "Não");
lblOperacaoLiberada.ForeColor = opLiberada ? Color.Green : Color.Red;
lblCodigoFalha.Text = $"Código de Falha: {CodFalha}";
picWifi.Image = APIService.HasInternet ? Resources.wifi_on : Resources.wifi_off;
await FuncoesGlobais.SafeExecuteAsync(() => SerialService.RealizarVarreduraPortasUSB());
}
private void LblCodigoFalha_Click(object sender, EventArgs e)
@ -129,76 +179,6 @@ namespace AgroBase.Forms.IHM
MessageBox.Show($"{DescricaoFalha}", "Código de Falha", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private async void TmrDispositivos_Elapsed(object sender, ElapsedEventArgs e)
{
((System.Timers.Timer)sender).Stop();
CodFalha = Variaveis.OperacaoEmAndamento.RetornaCodigoFalha();
Func<bool> funcao = new Func<bool>(() =>
{
var Labels = this.Controls.OfType<Label>().Where(y => y.Name.Contains("lblD_")).ToList();
Labels.ForEach(lbl =>
{
T_Code Dispositivo = (T_Code)Enum.Parse(typeof(T_Code), lbl.Name.Split('_')[1]);
string Mod_ID = lbl.Name.Split('_').Length == 3 ? lbl.Name.Split('_')[2] : lbl.Name.Split('_')[1];
if (Dispositivo == T_Code.Cam)
{
var listaCameras = CameraService.AtualizaListaCameras();
var CameraCaminho = Variaveis.OperacaoEmAndamento.CameraCaminhoKinect;
if (CameraCaminho != null && Mod_ID == CameraCaminho.ID)
{
lbl.ForeColor = !listaCameras.Any(x => x.Value == CameraCaminho.CameraSelecionada) ? Color.DarkRed : CameraCaminho.camera.selectedCamera == 0 ? Color.Gold : Color.DarkGreen;
}
else
{
var CameraSolo = Variaveis.OperacaoEmAndamento.CamerasSolo.FirstOrDefault(x => x.ID == Mod_ID);
if (CameraSolo != null)
{
lbl.ForeColor = !listaCameras.Any(x => x.Value == CameraSolo.CameraSelecionada) ? Color.DarkRed : CameraSolo.camera.selectedCamera == 0 ? Color.Gold : Color.DarkGreen;
}
}
}
else
{
var Modulo = SerialService.DispositivosMapeados.FirstOrDefault(x => x.Dispositivo == Dispositivo && (x.Mod_ID == Mod_ID || x.Mod_ID == null));
if (Modulo != null)
{
lbl.ForeColor = Modulo.Erro ? Color.Gold : Modulo.Conectado ? Color.DarkGreen : Color.DarkRed;
}
else
{
lbl.ForeColor = Color.Black;
}
}
});
if (SerialService.DispositivosMapeados.Count == 0)
{
Variaveis.DispositivosConectados.Where(x => x.Dados.GetStatusConexao()).ToList().ForEach(x => x.AcaoDesconectar());
}
bool mqttConectado = Variaveis.MqttService.StatusConexao();
lblMqtt.Text = "MQTT: " + (mqttConectado ? "Conectado" : "Desconectado");
lblMqtt.ForeColor = mqttConectado ? Color.Green : Color.Red;
bool opLiberada = Variaveis.OperacaoEmAndamento.OperacaoLiberada;
lblOperacaoLiberada.Text = "Operação Liberada: " + (opLiberada ? "Sim" : "Não");
lblOperacaoLiberada.ForeColor = opLiberada ? Color.Green : Color.Red;
lblCodigoFalha.Text = $"Código de Falha: {CodFalha}";
picWifi.Image = APIService.HasInternet ? Resources.wifi_on : Resources.wifi_off;
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(this, funcao);
await SerialService.RealizarVarreduraPortasUSB(tmrDispositivos);
((System.Timers.Timer)sender).Start();
}
private void lblModulo_Click(object sender, EventArgs e)
{
Label lbl = (Label)sender;

View File

@ -33,6 +33,10 @@ namespace AgroBase.Forms.Movimentacao
this.cmbTipoMovimento = new System.Windows.Forms.ComboBox();
this.lblTipoMovimento = new System.Windows.Forms.Label();
this.gpbDF = new System.Windows.Forms.GroupBox();
this.gpbDF_Freio = new System.Windows.Forms.GroupBox();
this.nudDF_Angulo = new System.Windows.Forms.NumericUpDown();
this.rdbDF_Dec = new System.Windows.Forms.RadioButton();
this.rdbDF_Inc = new System.Windows.Forms.RadioButton();
this.lblDFEndereco = new System.Windows.Forms.Label();
this.txtDFEndereco = new System.Windows.Forms.TextBox();
this.cmbDFFrente = new System.Windows.Forms.ComboBox();
@ -40,6 +44,10 @@ namespace AgroBase.Forms.Movimentacao
this.lblDFTras = new System.Windows.Forms.Label();
this.lblDFFrente = new System.Windows.Forms.Label();
this.gpbEF = new System.Windows.Forms.GroupBox();
this.gpbEF_Freio = new System.Windows.Forms.GroupBox();
this.nudEF_Angulo = new System.Windows.Forms.NumericUpDown();
this.rdbEF_Dec = new System.Windows.Forms.RadioButton();
this.rdbEF_Inc = new System.Windows.Forms.RadioButton();
this.lblEFEndereco = new System.Windows.Forms.Label();
this.txtEFEndereco = new System.Windows.Forms.TextBox();
this.cmbEFFrente = new System.Windows.Forms.ComboBox();
@ -47,6 +55,10 @@ namespace AgroBase.Forms.Movimentacao
this.lblEFTras = new System.Windows.Forms.Label();
this.lblEFFrente = new System.Windows.Forms.Label();
this.gpbDT = new System.Windows.Forms.GroupBox();
this.gpbDT_Freio = new System.Windows.Forms.GroupBox();
this.nudDT_Angulo = new System.Windows.Forms.NumericUpDown();
this.rdbDT_Dec = new System.Windows.Forms.RadioButton();
this.rdbDT_Inc = new System.Windows.Forms.RadioButton();
this.lblDTEndereco = new System.Windows.Forms.Label();
this.txtDTEndereco = new System.Windows.Forms.TextBox();
this.cmbDTFrente = new System.Windows.Forms.ComboBox();
@ -54,13 +66,19 @@ namespace AgroBase.Forms.Movimentacao
this.lblDTTras = new System.Windows.Forms.Label();
this.lblDTFrente = new System.Windows.Forms.Label();
this.gpbET = new System.Windows.Forms.GroupBox();
this.gpbET_Freio = new System.Windows.Forms.GroupBox();
this.nudET_Angulo = new System.Windows.Forms.NumericUpDown();
this.rdbET_Dec = new System.Windows.Forms.RadioButton();
this.rdbET_Inc = new System.Windows.Forms.RadioButton();
this.lblETEndereco = new System.Windows.Forms.Label();
this.txtETEndereco = new System.Windows.Forms.TextBox();
this.cmbETFrente = new System.Windows.Forms.ComboBox();
this.cmbETTras = new System.Windows.Forms.ComboBox();
this.lblETTras = new System.Windows.Forms.Label();
this.lblETFrente = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.gpbAjustes = new System.Windows.Forms.GroupBox();
this.lblIP = new System.Windows.Forms.Label();
this.txtIP = new System.Windows.Forms.TextBox();
this.txtOffsetLeitura = new System.Windows.Forms.TextBox();
this.lblOffsetLeitura = new System.Windows.Forms.Label();
this.lblReducao = new System.Windows.Forms.Label();
@ -74,14 +92,20 @@ namespace AgroBase.Forms.Movimentacao
this.nudNumPolos = new System.Windows.Forms.NumericUpDown();
this.lblRampa = new System.Windows.Forms.Label();
this.nudRampa = new System.Windows.Forms.NumericUpDown();
this.txtIP = new System.Windows.Forms.TextBox();
this.lblIP = new System.Windows.Forms.Label();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
this.gpbDF_Freio.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDF_Angulo)).BeginInit();
this.gpbEF.SuspendLayout();
this.gpbEF_Freio.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudEF_Angulo)).BeginInit();
this.gpbDT.SuspendLayout();
this.gpbDT_Freio.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDT_Angulo)).BeginInit();
this.gpbET.SuspendLayout();
this.groupBox1.SuspendLayout();
this.gpbET_Freio.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudET_Angulo)).BeginInit();
this.gpbAjustes.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudReducao)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudDiametroRoda)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudRPMMax)).BeginInit();
@ -101,7 +125,7 @@ namespace AgroBase.Forms.Movimentacao
this.gpbSentido.Margin = new System.Windows.Forms.Padding(2);
this.gpbSentido.Name = "gpbSentido";
this.gpbSentido.Padding = new System.Windows.Forms.Padding(2);
this.gpbSentido.Size = new System.Drawing.Size(376, 283);
this.gpbSentido.Size = new System.Drawing.Size(376, 357);
this.gpbSentido.TabIndex = 40;
this.gpbSentido.TabStop = false;
this.gpbSentido.Text = "Sentido de giro";
@ -127,6 +151,7 @@ namespace AgroBase.Forms.Movimentacao
//
// gpbDF
//
this.gpbDF.Controls.Add(this.gpbDF_Freio);
this.gpbDF.Controls.Add(this.lblDFEndereco);
this.gpbDF.Controls.Add(this.txtDFEndereco);
this.gpbDF.Controls.Add(this.cmbDFFrente);
@ -137,11 +162,58 @@ namespace AgroBase.Forms.Movimentacao
this.gpbDF.Margin = new System.Windows.Forms.Padding(2);
this.gpbDF.Name = "gpbDF";
this.gpbDF.Padding = new System.Windows.Forms.Padding(2);
this.gpbDF.Size = new System.Drawing.Size(168, 105);
this.gpbDF.Size = new System.Drawing.Size(168, 143);
this.gpbDF.TabIndex = 9;
this.gpbDF.TabStop = false;
this.gpbDF.Text = "M4 - Direito Frente (DF)";
//
// gpbDF_Freio
//
this.gpbDF_Freio.Controls.Add(this.nudDF_Angulo);
this.gpbDF_Freio.Controls.Add(this.rdbDF_Dec);
this.gpbDF_Freio.Controls.Add(this.rdbDF_Inc);
this.gpbDF_Freio.Location = new System.Drawing.Point(5, 100);
this.gpbDF_Freio.Name = "gpbDF_Freio";
this.gpbDF_Freio.Size = new System.Drawing.Size(158, 38);
this.gpbDF_Freio.TabIndex = 16;
this.gpbDF_Freio.TabStop = false;
this.gpbDF_Freio.Text = "Freio";
//
// nudDF_Angulo
//
this.nudDF_Angulo.Location = new System.Drawing.Point(105, 12);
this.nudDF_Angulo.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.nudDF_Angulo.Name = "nudDF_Angulo";
this.nudDF_Angulo.Size = new System.Drawing.Size(47, 20);
this.nudDF_Angulo.TabIndex = 12;
this.nudDF_Angulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// rdbDF_Dec
//
this.rdbDF_Dec.AutoSize = true;
this.rdbDF_Dec.Location = new System.Drawing.Point(50, 14);
this.rdbDF_Dec.Name = "rdbDF_Dec";
this.rdbDF_Dec.Size = new System.Drawing.Size(45, 17);
this.rdbDF_Dec.TabIndex = 13;
this.rdbDF_Dec.TabStop = true;
this.rdbDF_Dec.Text = "Dec";
this.rdbDF_Dec.UseVisualStyleBackColor = true;
//
// rdbDF_Inc
//
this.rdbDF_Inc.AutoSize = true;
this.rdbDF_Inc.Location = new System.Drawing.Point(8, 14);
this.rdbDF_Inc.Name = "rdbDF_Inc";
this.rdbDF_Inc.Size = new System.Drawing.Size(40, 17);
this.rdbDF_Inc.TabIndex = 12;
this.rdbDF_Inc.TabStop = true;
this.rdbDF_Inc.Text = "Inc";
this.rdbDF_Inc.UseVisualStyleBackColor = true;
//
// lblDFEndereco
//
this.lblDFEndereco.AutoSize = true;
@ -163,6 +235,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbDFFrente
//
this.cmbDFFrente.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDFFrente.FormattingEnabled = true;
this.cmbDFFrente.Location = new System.Drawing.Point(66, 25);
this.cmbDFFrente.Margin = new System.Windows.Forms.Padding(2);
@ -172,6 +245,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbDFTras
//
this.cmbDFTras.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDFTras.FormattingEnabled = true;
this.cmbDFTras.Location = new System.Drawing.Point(66, 50);
this.cmbDFTras.Margin = new System.Windows.Forms.Padding(2);
@ -201,6 +275,7 @@ namespace AgroBase.Forms.Movimentacao
//
// gpbEF
//
this.gpbEF.Controls.Add(this.gpbEF_Freio);
this.gpbEF.Controls.Add(this.lblEFEndereco);
this.gpbEF.Controls.Add(this.txtEFEndereco);
this.gpbEF.Controls.Add(this.cmbEFFrente);
@ -211,11 +286,58 @@ namespace AgroBase.Forms.Movimentacao
this.gpbEF.Margin = new System.Windows.Forms.Padding(2);
this.gpbEF.Name = "gpbEF";
this.gpbEF.Padding = new System.Windows.Forms.Padding(2);
this.gpbEF.Size = new System.Drawing.Size(168, 105);
this.gpbEF.Size = new System.Drawing.Size(168, 143);
this.gpbEF.TabIndex = 9;
this.gpbEF.TabStop = false;
this.gpbEF.Text = "M2 - Esquerdo Frente (EF)";
//
// gpbEF_Freio
//
this.gpbEF_Freio.Controls.Add(this.nudEF_Angulo);
this.gpbEF_Freio.Controls.Add(this.rdbEF_Dec);
this.gpbEF_Freio.Controls.Add(this.rdbEF_Inc);
this.gpbEF_Freio.Location = new System.Drawing.Point(5, 100);
this.gpbEF_Freio.Name = "gpbEF_Freio";
this.gpbEF_Freio.Size = new System.Drawing.Size(158, 38);
this.gpbEF_Freio.TabIndex = 15;
this.gpbEF_Freio.TabStop = false;
this.gpbEF_Freio.Text = "Freio";
//
// nudEF_Angulo
//
this.nudEF_Angulo.Location = new System.Drawing.Point(105, 12);
this.nudEF_Angulo.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.nudEF_Angulo.Name = "nudEF_Angulo";
this.nudEF_Angulo.Size = new System.Drawing.Size(47, 20);
this.nudEF_Angulo.TabIndex = 12;
this.nudEF_Angulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// rdbEF_Dec
//
this.rdbEF_Dec.AutoSize = true;
this.rdbEF_Dec.Location = new System.Drawing.Point(50, 14);
this.rdbEF_Dec.Name = "rdbEF_Dec";
this.rdbEF_Dec.Size = new System.Drawing.Size(45, 17);
this.rdbEF_Dec.TabIndex = 13;
this.rdbEF_Dec.TabStop = true;
this.rdbEF_Dec.Text = "Dec";
this.rdbEF_Dec.UseVisualStyleBackColor = true;
//
// rdbEF_Inc
//
this.rdbEF_Inc.AutoSize = true;
this.rdbEF_Inc.Location = new System.Drawing.Point(8, 14);
this.rdbEF_Inc.Name = "rdbEF_Inc";
this.rdbEF_Inc.Size = new System.Drawing.Size(40, 17);
this.rdbEF_Inc.TabIndex = 12;
this.rdbEF_Inc.TabStop = true;
this.rdbEF_Inc.Text = "Inc";
this.rdbEF_Inc.UseVisualStyleBackColor = true;
//
// lblEFEndereco
//
this.lblEFEndereco.AutoSize = true;
@ -237,6 +359,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbEFFrente
//
this.cmbEFFrente.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbEFFrente.FormattingEnabled = true;
this.cmbEFFrente.Location = new System.Drawing.Point(66, 25);
this.cmbEFFrente.Margin = new System.Windows.Forms.Padding(2);
@ -246,6 +369,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbEFTras
//
this.cmbEFTras.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbEFTras.FormattingEnabled = true;
this.cmbEFTras.Location = new System.Drawing.Point(66, 50);
this.cmbEFTras.Margin = new System.Windows.Forms.Padding(2);
@ -275,21 +399,69 @@ namespace AgroBase.Forms.Movimentacao
//
// gpbDT
//
this.gpbDT.Controls.Add(this.gpbDT_Freio);
this.gpbDT.Controls.Add(this.lblDTEndereco);
this.gpbDT.Controls.Add(this.txtDTEndereco);
this.gpbDT.Controls.Add(this.cmbDTFrente);
this.gpbDT.Controls.Add(this.cmbDTTras);
this.gpbDT.Controls.Add(this.lblDTTras);
this.gpbDT.Controls.Add(this.lblDTFrente);
this.gpbDT.Location = new System.Drawing.Point(195, 169);
this.gpbDT.Location = new System.Drawing.Point(195, 207);
this.gpbDT.Margin = new System.Windows.Forms.Padding(2);
this.gpbDT.Name = "gpbDT";
this.gpbDT.Padding = new System.Windows.Forms.Padding(2);
this.gpbDT.Size = new System.Drawing.Size(168, 105);
this.gpbDT.Size = new System.Drawing.Size(168, 143);
this.gpbDT.TabIndex = 9;
this.gpbDT.TabStop = false;
this.gpbDT.Text = "M3 - Direito Trás (DT)";
//
// gpbDT_Freio
//
this.gpbDT_Freio.Controls.Add(this.nudDT_Angulo);
this.gpbDT_Freio.Controls.Add(this.rdbDT_Dec);
this.gpbDT_Freio.Controls.Add(this.rdbDT_Inc);
this.gpbDT_Freio.Location = new System.Drawing.Point(5, 100);
this.gpbDT_Freio.Name = "gpbDT_Freio";
this.gpbDT_Freio.Size = new System.Drawing.Size(158, 38);
this.gpbDT_Freio.TabIndex = 15;
this.gpbDT_Freio.TabStop = false;
this.gpbDT_Freio.Text = "Freio";
//
// nudDT_Angulo
//
this.nudDT_Angulo.Location = new System.Drawing.Point(105, 12);
this.nudDT_Angulo.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.nudDT_Angulo.Name = "nudDT_Angulo";
this.nudDT_Angulo.Size = new System.Drawing.Size(47, 20);
this.nudDT_Angulo.TabIndex = 12;
this.nudDT_Angulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// rdbDT_Dec
//
this.rdbDT_Dec.AutoSize = true;
this.rdbDT_Dec.Location = new System.Drawing.Point(50, 14);
this.rdbDT_Dec.Name = "rdbDT_Dec";
this.rdbDT_Dec.Size = new System.Drawing.Size(45, 17);
this.rdbDT_Dec.TabIndex = 13;
this.rdbDT_Dec.TabStop = true;
this.rdbDT_Dec.Text = "Dec";
this.rdbDT_Dec.UseVisualStyleBackColor = true;
//
// rdbDT_Inc
//
this.rdbDT_Inc.AutoSize = true;
this.rdbDT_Inc.Location = new System.Drawing.Point(8, 14);
this.rdbDT_Inc.Name = "rdbDT_Inc";
this.rdbDT_Inc.Size = new System.Drawing.Size(40, 17);
this.rdbDT_Inc.TabIndex = 12;
this.rdbDT_Inc.TabStop = true;
this.rdbDT_Inc.Text = "Inc";
this.rdbDT_Inc.UseVisualStyleBackColor = true;
//
// lblDTEndereco
//
this.lblDTEndereco.AutoSize = true;
@ -311,6 +483,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbDTFrente
//
this.cmbDTFrente.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDTFrente.FormattingEnabled = true;
this.cmbDTFrente.Location = new System.Drawing.Point(66, 25);
this.cmbDTFrente.Margin = new System.Windows.Forms.Padding(2);
@ -320,6 +493,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbDTTras
//
this.cmbDTTras.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDTTras.FormattingEnabled = true;
this.cmbDTTras.Location = new System.Drawing.Point(66, 50);
this.cmbDTTras.Margin = new System.Windows.Forms.Padding(2);
@ -349,21 +523,69 @@ namespace AgroBase.Forms.Movimentacao
//
// gpbET
//
this.gpbET.Controls.Add(this.gpbET_Freio);
this.gpbET.Controls.Add(this.lblETEndereco);
this.gpbET.Controls.Add(this.txtETEndereco);
this.gpbET.Controls.Add(this.cmbETFrente);
this.gpbET.Controls.Add(this.cmbETTras);
this.gpbET.Controls.Add(this.lblETTras);
this.gpbET.Controls.Add(this.lblETFrente);
this.gpbET.Location = new System.Drawing.Point(13, 169);
this.gpbET.Location = new System.Drawing.Point(13, 207);
this.gpbET.Margin = new System.Windows.Forms.Padding(2);
this.gpbET.Name = "gpbET";
this.gpbET.Padding = new System.Windows.Forms.Padding(2);
this.gpbET.Size = new System.Drawing.Size(168, 105);
this.gpbET.Size = new System.Drawing.Size(168, 143);
this.gpbET.TabIndex = 0;
this.gpbET.TabStop = false;
this.gpbET.Text = "M1 - Esquerdo Trás (ET)";
//
// gpbET_Freio
//
this.gpbET_Freio.Controls.Add(this.nudET_Angulo);
this.gpbET_Freio.Controls.Add(this.rdbET_Dec);
this.gpbET_Freio.Controls.Add(this.rdbET_Inc);
this.gpbET_Freio.Location = new System.Drawing.Point(5, 100);
this.gpbET_Freio.Name = "gpbET_Freio";
this.gpbET_Freio.Size = new System.Drawing.Size(158, 38);
this.gpbET_Freio.TabIndex = 14;
this.gpbET_Freio.TabStop = false;
this.gpbET_Freio.Text = "Freio";
//
// nudET_Angulo
//
this.nudET_Angulo.Location = new System.Drawing.Point(105, 12);
this.nudET_Angulo.Maximum = new decimal(new int[] {
180,
0,
0,
0});
this.nudET_Angulo.Name = "nudET_Angulo";
this.nudET_Angulo.Size = new System.Drawing.Size(47, 20);
this.nudET_Angulo.TabIndex = 12;
this.nudET_Angulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// rdbET_Dec
//
this.rdbET_Dec.AutoSize = true;
this.rdbET_Dec.Location = new System.Drawing.Point(50, 14);
this.rdbET_Dec.Name = "rdbET_Dec";
this.rdbET_Dec.Size = new System.Drawing.Size(45, 17);
this.rdbET_Dec.TabIndex = 13;
this.rdbET_Dec.TabStop = true;
this.rdbET_Dec.Text = "Dec";
this.rdbET_Dec.UseVisualStyleBackColor = true;
//
// rdbET_Inc
//
this.rdbET_Inc.AutoSize = true;
this.rdbET_Inc.Location = new System.Drawing.Point(8, 14);
this.rdbET_Inc.Name = "rdbET_Inc";
this.rdbET_Inc.Size = new System.Drawing.Size(40, 17);
this.rdbET_Inc.TabIndex = 12;
this.rdbET_Inc.TabStop = true;
this.rdbET_Inc.Text = "Inc";
this.rdbET_Inc.UseVisualStyleBackColor = true;
//
// lblETEndereco
//
this.lblETEndereco.AutoSize = true;
@ -385,6 +607,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbETFrente
//
this.cmbETFrente.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbETFrente.FormattingEnabled = true;
this.cmbETFrente.Location = new System.Drawing.Point(66, 25);
this.cmbETFrente.Margin = new System.Windows.Forms.Padding(2);
@ -394,6 +617,7 @@ namespace AgroBase.Forms.Movimentacao
//
// cmbETTras
//
this.cmbETTras.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbETTras.FormattingEnabled = true;
this.cmbETTras.Location = new System.Drawing.Point(66, 50);
this.cmbETTras.Margin = new System.Windows.Forms.Padding(2);
@ -421,31 +645,50 @@ namespace AgroBase.Forms.Movimentacao
this.lblETFrente.TabIndex = 0;
this.lblETFrente.Text = "Frente";
//
// groupBox1
// gpbAjustes
//
this.groupBox1.Controls.Add(this.lblIP);
this.groupBox1.Controls.Add(this.txtIP);
this.groupBox1.Controls.Add(this.txtOffsetLeitura);
this.groupBox1.Controls.Add(this.lblOffsetLeitura);
this.groupBox1.Controls.Add(this.lblReducao);
this.groupBox1.Controls.Add(this.nudReducao);
this.groupBox1.Controls.Add(this.btnSalvar);
this.groupBox1.Controls.Add(this.lblDiametroRoda);
this.groupBox1.Controls.Add(this.nudDiametroRoda);
this.groupBox1.Controls.Add(this.lblRPMMax);
this.groupBox1.Controls.Add(this.nudRPMMax);
this.groupBox1.Controls.Add(this.lblNumPolos);
this.groupBox1.Controls.Add(this.nudNumPolos);
this.groupBox1.Controls.Add(this.lblRampa);
this.groupBox1.Controls.Add(this.nudRampa);
this.groupBox1.Location = new System.Drawing.Point(11, 298);
this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
this.groupBox1.Size = new System.Drawing.Size(376, 113);
this.groupBox1.TabIndex = 135;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Ajustes";
this.gpbAjustes.Controls.Add(this.lblIP);
this.gpbAjustes.Controls.Add(this.txtIP);
this.gpbAjustes.Controls.Add(this.txtOffsetLeitura);
this.gpbAjustes.Controls.Add(this.lblOffsetLeitura);
this.gpbAjustes.Controls.Add(this.lblReducao);
this.gpbAjustes.Controls.Add(this.nudReducao);
this.gpbAjustes.Controls.Add(this.btnSalvar);
this.gpbAjustes.Controls.Add(this.lblDiametroRoda);
this.gpbAjustes.Controls.Add(this.nudDiametroRoda);
this.gpbAjustes.Controls.Add(this.lblRPMMax);
this.gpbAjustes.Controls.Add(this.nudRPMMax);
this.gpbAjustes.Controls.Add(this.lblNumPolos);
this.gpbAjustes.Controls.Add(this.nudNumPolos);
this.gpbAjustes.Controls.Add(this.lblRampa);
this.gpbAjustes.Controls.Add(this.nudRampa);
this.gpbAjustes.Location = new System.Drawing.Point(11, 372);
this.gpbAjustes.Margin = new System.Windows.Forms.Padding(2);
this.gpbAjustes.Name = "gpbAjustes";
this.gpbAjustes.Padding = new System.Windows.Forms.Padding(2);
this.gpbAjustes.Size = new System.Drawing.Size(376, 113);
this.gpbAjustes.TabIndex = 135;
this.gpbAjustes.TabStop = false;
this.gpbAjustes.Text = "Ajustes";
//
// lblIP
//
this.lblIP.AutoSize = true;
this.lblIP.Location = new System.Drawing.Point(280, 20);
this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblIP.Name = "lblIP";
this.lblIP.Size = new System.Drawing.Size(17, 13);
this.lblIP.TabIndex = 141;
this.lblIP.Text = "IP";
//
// txtIP
//
this.txtIP.Location = new System.Drawing.Point(283, 37);
this.txtIP.Margin = new System.Windows.Forms.Padding(2);
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(85, 20);
this.txtIP.TabIndex = 12;
this.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// txtOffsetLeitura
//
@ -618,32 +861,13 @@ namespace AgroBase.Forms.Movimentacao
this.nudRampa.TabIndex = 31;
this.nudRampa.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// txtIP
//
this.txtIP.Location = new System.Drawing.Point(283, 37);
this.txtIP.Margin = new System.Windows.Forms.Padding(2);
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(85, 20);
this.txtIP.TabIndex = 12;
this.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// lblIP
//
this.lblIP.AutoSize = true;
this.lblIP.Location = new System.Drawing.Point(280, 20);
this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblIP.Name = "lblIP";
this.lblIP.Size = new System.Drawing.Size(17, 13);
this.lblIP.TabIndex = 141;
this.lblIP.Text = "IP";
//
// frmMovConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(398, 424);
this.Controls.Add(this.groupBox1);
this.ClientSize = new System.Drawing.Size(398, 492);
this.Controls.Add(this.gpbAjustes);
this.Controls.Add(this.gpbSentido);
this.Margin = new System.Windows.Forms.Padding(2);
this.MaximizeBox = false;
@ -656,14 +880,26 @@ namespace AgroBase.Forms.Movimentacao
this.gpbSentido.PerformLayout();
this.gpbDF.ResumeLayout(false);
this.gpbDF.PerformLayout();
this.gpbDF_Freio.ResumeLayout(false);
this.gpbDF_Freio.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDF_Angulo)).EndInit();
this.gpbEF.ResumeLayout(false);
this.gpbEF.PerformLayout();
this.gpbEF_Freio.ResumeLayout(false);
this.gpbEF_Freio.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudEF_Angulo)).EndInit();
this.gpbDT.ResumeLayout(false);
this.gpbDT.PerformLayout();
this.gpbDT_Freio.ResumeLayout(false);
this.gpbDT_Freio.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDT_Angulo)).EndInit();
this.gpbET.ResumeLayout(false);
this.gpbET.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.gpbET_Freio.ResumeLayout(false);
this.gpbET_Freio.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudET_Angulo)).EndInit();
this.gpbAjustes.ResumeLayout(false);
this.gpbAjustes.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudReducao)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudDiametroRoda)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudRPMMax)).EndInit();
@ -695,7 +931,7 @@ namespace AgroBase.Forms.Movimentacao
private System.Windows.Forms.ComboBox cmbETTras;
private System.Windows.Forms.Label lblETTras;
private System.Windows.Forms.Label lblETFrente;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox gpbAjustes;
private System.Windows.Forms.Label lblNumPolos;
private System.Windows.Forms.Label lblRampa;
private System.Windows.Forms.NumericUpDown nudRampa;
@ -721,5 +957,21 @@ namespace AgroBase.Forms.Movimentacao
private System.Windows.Forms.Label lblOffsetLeitura;
private System.Windows.Forms.Label lblIP;
private System.Windows.Forms.TextBox txtIP;
private System.Windows.Forms.GroupBox gpbET_Freio;
private System.Windows.Forms.NumericUpDown nudET_Angulo;
private System.Windows.Forms.RadioButton rdbET_Dec;
private System.Windows.Forms.RadioButton rdbET_Inc;
private System.Windows.Forms.GroupBox gpbDT_Freio;
private System.Windows.Forms.NumericUpDown nudDT_Angulo;
private System.Windows.Forms.RadioButton rdbDT_Dec;
private System.Windows.Forms.RadioButton rdbDT_Inc;
private System.Windows.Forms.GroupBox gpbDF_Freio;
private System.Windows.Forms.NumericUpDown nudDF_Angulo;
private System.Windows.Forms.RadioButton rdbDF_Dec;
private System.Windows.Forms.RadioButton rdbDF_Inc;
private System.Windows.Forms.GroupBox gpbEF_Freio;
private System.Windows.Forms.NumericUpDown nudEF_Angulo;
private System.Windows.Forms.RadioButton rdbEF_Dec;
private System.Windows.Forms.RadioButton rdbEF_Inc;
}
}

View File

@ -40,7 +40,9 @@ namespace AgroBase.Forms.Movimentacao
cmb.Items.AddRange(Enum.GetNames(typeof(Sentido)).ToArray());
cmb.SelectedIndex = 0;
var Modulo = Disp.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == cmb.Name.Substring(3, 2));
string Mod_ID = cmb.Name.Substring(3, 2);
var Modulo = Disp.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == Mod_ID);
if (Modulo != null)
{
Sentido sentido = Sentido.Parado;
@ -69,6 +71,18 @@ namespace AgroBase.Forms.Movimentacao
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
txtEndereco.Text = Modulo.MovMotor.Endereco;
GroupBox gpbFreio = FuncoesGlobais.FindControlRecursive<GroupBox>(gpbSentido, "gpb" + Mod_ID + "_Freio");
if (gpbFreio != null)
{
RadioButton rdbInc = gpbFreio.Controls.OfType<RadioButton>().FirstOrDefault(x => x.Name == "rdb" + Mod_ID + "_Inc");
RadioButton rdbDec = gpbFreio.Controls.OfType<RadioButton>().FirstOrDefault(x => x.Name == "rdb" + Mod_ID + "_Dec");
NumericUpDown nudAngulo = gpbFreio.Controls.OfType<NumericUpDown>().FirstOrDefault(x => x.Name == "nud" + Mod_ID + "_Angulo");
rdbInc.Checked = Modulo.MovMotor.ConfigFreio.Incremental;
rdbDec.Checked = !Modulo.MovMotor.ConfigFreio.Incremental;
nudAngulo.Value = Modulo.MovMotor.ConfigFreio.AnguloInicial;
}
}
}
@ -116,6 +130,17 @@ namespace AgroBase.Forms.Movimentacao
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
Modulo.MovMotor.Endereco = txtEndereco.Text;
GroupBox gpbFreio = FuncoesGlobais.FindControlRecursive<GroupBox>(gpbSentido, "gpb" + Modulo.Modulo_ID + "_Freio");
if (gpbFreio != null)
{
RadioButton rdbInc = gpbFreio.Controls.OfType<RadioButton>().FirstOrDefault(x => x.Name == "rdb" + Modulo.Modulo_ID + "_Inc");
RadioButton rdbDec = gpbFreio.Controls.OfType<RadioButton>().FirstOrDefault(x => x.Name == "rdb" + Modulo.Modulo_ID + "_Dec");
NumericUpDown nudAngulo = gpbFreio.Controls.OfType<NumericUpDown>().FirstOrDefault(x => x.Name == "nud" + Modulo.Modulo_ID + "_Angulo");
Modulo.MovMotor.ConfigFreio.Incremental = rdbInc.Checked;
Modulo.MovMotor.ConfigFreio.AnguloInicial = (int)nudAngulo.Value;
}
}
}

View File

@ -7,12 +7,13 @@ using System.Windows.Forms;
using static AgroBase.Models.Enums;
using AgroBase.Services;
using AgroBase.Models.Modules;
using System.Threading.Tasks;
namespace AgroBase.Forms.Operacoes
{
public partial class frmOperacaoManual : Form
{
Timer tmrLeitura;
AsyncTaskTimerModel tmrLeitura;
DateTime UltimoComandoDir = DateTime.Now;
public frmOperacaoManual()
@ -48,15 +49,13 @@ namespace AgroBase.Forms.Operacoes
PopularBicos();
Variaveis.OperacaoEmAndamento.chartGraficos = chartGraficos;
tmrLeitura = new Timer() { Interval = 500 };
tmrLeitura.Tick += tmrLeitura_Tick;
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 500, this);
tmrLeitura.Start();
}
private void frmOperacaoManual_FormClosing(object sender, FormClosingEventArgs e)
{
tmrLeitura.Stop();
tmrLeitura.Dispose();
Variaveis.OperacaoEmAndamento.FinalizarOperacao();
Variaveis.OperacaoEmAndamento.DesligarCameras();
}
@ -118,12 +117,7 @@ namespace AgroBase.Forms.Operacoes
}
private void tmrLeitura_Tick(object sender, EventArgs e)
{
AtualizarDados();
}
public void AtualizarDados()
private async Task tmrLeitura_Tick()
{
this.Text = Variaveis.OperacaoEmAndamento.TextoFormOperacao("Manual");

View File

@ -13,7 +13,7 @@ namespace AgroBase.Forms.Operacoes
{
public partial class frmOperacaoMapaGPS : Form
{
private Timer tmrLeituras = new Timer() { Interval = 200 };
private AsyncTaskTimerModel tmrLeituras;
#region Eventos do formulário
@ -37,7 +37,7 @@ namespace AgroBase.Forms.Operacoes
private void frmOperacaoMapaGPS_Load(object sender, EventArgs e)
{
tmrLeituras.Tick += TmrLeituras_Tick;
tmrLeituras = new AsyncTaskTimerModel(tmrLeituras_Tick, 200, this);
tmrLeituras.Start();
AtualizarDispositivos();
@ -64,7 +64,7 @@ namespace AgroBase.Forms.Operacoes
#region Rotinas e Atualizações de tela
private void TmrLeituras_Tick(object sender, EventArgs e)
private async Task tmrLeituras_Tick()
{
pnlOrientacao.Invalidate();
pnlInclinacao.Invalidate();

View File

@ -10,6 +10,7 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AgroBase.Forms.Operacoes
@ -35,7 +36,7 @@ namespace AgroBase.Forms.Operacoes
string pathImagensSoloE = "";
string pathImagensSoloD = "";
DateTime MomentoAtual = DateTime.Now;
Timer tmrPlay = new Timer() { Interval = 1000 };
AsyncTaskTimerModel tmrPlay;
MapasModel Mapa = new MapasModel();
private Visualizador3DService visualizador3D;
private MapaDinamicoModel MapaDinamico;
@ -85,7 +86,7 @@ namespace AgroBase.Forms.Operacoes
private void frmResultadosOperacao_Load(object sender, EventArgs e)
{
tmrPlay.Tick += TmrPlay_Tick;
tmrPlay = new AsyncTaskTimerModel(tmrPlay_Tick, 1000, this);
picDIR_DF.Image = FuncoesGlobais.EspelharImagemHorizontalmente(Resources.roda_superior);
picDIR_DT.Image = FuncoesGlobais.EspelharImagemHorizontalmente(Resources.roda_superior);
@ -93,7 +94,7 @@ namespace AgroBase.Forms.Operacoes
MapaDinamico = new MapaDinamicoModel(this, pnlZoomMapa);
}
private void TmrPlay_Tick(object sender, EventArgs e)
private async Task tmrPlay_Tick()
{
if (trbMomento.Value < trbMomento.Maximum)
{
@ -113,8 +114,8 @@ namespace AgroBase.Forms.Operacoes
private void btnPlay_Click(object sender, EventArgs e)
{
tmrPlay.Enabled = !tmrPlay.Enabled;
btnPlay.Text = tmrPlay.Enabled ? "Pause" : "Pay";
tmrPlay.Toogle();
btnPlay.Text = tmrPlay.IsRunning ? "Pause" : "Pay";
}
private void btnCarregarOperacao_Click(object sender, EventArgs e)
@ -904,6 +905,12 @@ namespace AgroBase.Forms.Operacoes
private void AtulizarDadosMotorMovimentacao(string ID)
{
var Log = LogsMovimentacao.FirstOrDefault(x => x.Momento == MomentoAtual && x.Modulo_ID == ID);
var Log_Sen = LogsSensoriamento.FirstOrDefault(x => x.Momento == MomentoAtual);
bool freio =
(ID.Contains("ET") && Log_Sen.AnguloFreioET > 0 && Log_Sen.AnguloFreioET < 180) ||
(ID.Contains("DT") && Log_Sen.AnguloFreioDT > 0 && Log_Sen.AnguloFreioDT < 180) ||
(ID.Contains("EF") && Log_Sen.AnguloFreioEF > 0 && Log_Sen.AnguloFreioEF < 180) ||
(ID.Contains("DF") && Log_Sen.AnguloFreioDF > 0 && Log_Sen.AnguloFreioDF < 180);
GroupBox gpbRpm = FuncoesGlobais.FindControlRecursive<GroupBox>(tabMovGreal, "gpbMOV_Geral_" + ID);
gpbRpm.ForeColor = !Log.Inicializado ? Color.Red : Color.Black;
@ -914,9 +921,9 @@ namespace AgroBase.Forms.Operacoes
CheckBox chbBrk = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbRpm, "chbMOV_Brk_" + ID);
chbBrk.Checked = Log.EmFreio;
TextBox txtSentidoSP = FuncoesGlobais.FindControlRecursive<TextBox>(gpbRpm, "txtMOV_SentidoSP_" + ID);
txtSentidoSP.Text = Log.Sentido_SP.ToString();
txtSentidoSP.Text = freio ? Enums.Direcao.EmFreio.ToString() : Log.Sentido_SP.ToString();
TextBox txtSentido = FuncoesGlobais.FindControlRecursive<TextBox>(gpbRpm, "txtMOV_Sentido_" + ID);
txtSentido.Text = Log.Sentido.ToString();
txtSentido.Text = Log.EmFreio ? Enums.Direcao.EmFreio.ToString() : Log.Sentido.ToString();
GroupBox gpbTmp = FuncoesGlobais.FindControlRecursive<GroupBox>(tabMovTemperatura, "gpbMOV_Temperatura_" + ID);
TextBox txtAtual = FuncoesGlobais.FindControlRecursive<TextBox>(gpbTmp, "txtMOV_TemperaturaAt_" + ID);

View File

@ -51,13 +51,16 @@
this.gpbBateria = new System.Windows.Forms.GroupBox();
this.btnBateriaCalibrar = new System.Windows.Forms.Button();
this.gpbCameras = new System.Windows.Forms.GroupBox();
this.btnAtualizarCameras = new System.Windows.Forms.Button();
this.lblSolodir = new System.Windows.Forms.Label();
this.cmbSoloDir = new System.Windows.Forms.ComboBox();
this.lblSoloesq = new System.Windows.Forms.Label();
this.cmbSoloEsq = new System.Windows.Forms.ComboBox();
this.lblCaminho = new System.Windows.Forms.Label();
this.cmbCaminho = new System.Windows.Forms.ComboBox();
this.btnAtualizarCameras = new System.Windows.Forms.Button();
this.btnFreio = new System.Windows.Forms.Button();
this.cmbModFreio = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.gridsTEN)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.gridsCOR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.gridsTMP)).BeginInit();
@ -210,7 +213,7 @@
// btnBateriaVer
//
this.btnBateriaVer.Location = new System.Drawing.Point(8, 54);
this.btnBateriaVer.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.btnBateriaVer.Margin = new System.Windows.Forms.Padding(2);
this.btnBateriaVer.Name = "btnBateriaVer";
this.btnBateriaVer.Size = new System.Drawing.Size(135, 19);
this.btnBateriaVer.TabIndex = 16;
@ -223,7 +226,7 @@
this.cmbBateriaParametro.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbBateriaParametro.FormattingEnabled = true;
this.cmbBateriaParametro.Location = new System.Drawing.Point(7, 30);
this.cmbBateriaParametro.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmbBateriaParametro.Margin = new System.Windows.Forms.Padding(2);
this.cmbBateriaParametro.Name = "cmbBateriaParametro";
this.cmbBateriaParametro.Size = new System.Drawing.Size(137, 21);
this.cmbBateriaParametro.TabIndex = 17;
@ -240,7 +243,7 @@
// nudBateriaValor
//
this.nudBateriaValor.Location = new System.Drawing.Point(8, 79);
this.nudBateriaValor.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.nudBateriaValor.Margin = new System.Windows.Forms.Padding(2);
this.nudBateriaValor.Name = "nudBateriaValor";
this.nudBateriaValor.Size = new System.Drawing.Size(64, 20);
this.nudBateriaValor.TabIndex = 20;
@ -249,7 +252,7 @@
// btnBateriaDefinir
//
this.btnBateriaDefinir.Location = new System.Drawing.Point(76, 78);
this.btnBateriaDefinir.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.btnBateriaDefinir.Margin = new System.Windows.Forms.Padding(2);
this.btnBateriaDefinir.Name = "btnBateriaDefinir";
this.btnBateriaDefinir.Size = new System.Drawing.Size(67, 19);
this.btnBateriaDefinir.TabIndex = 21;
@ -266,9 +269,9 @@
this.gpbBateria.Controls.Add(this.nudBateriaValor);
this.gpbBateria.Controls.Add(this.btnBateriaVer);
this.gpbBateria.Location = new System.Drawing.Point(488, 454);
this.gpbBateria.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.gpbBateria.Margin = new System.Windows.Forms.Padding(2);
this.gpbBateria.Name = "gpbBateria";
this.gpbBateria.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.gpbBateria.Padding = new System.Windows.Forms.Padding(2);
this.gpbBateria.Size = new System.Drawing.Size(154, 121);
this.gpbBateria.TabIndex = 22;
this.gpbBateria.TabStop = false;
@ -277,7 +280,7 @@
// btnBateriaCalibrar
//
this.btnBateriaCalibrar.Location = new System.Drawing.Point(8, 99);
this.btnBateriaCalibrar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.btnBateriaCalibrar.Margin = new System.Windows.Forms.Padding(2);
this.btnBateriaCalibrar.Name = "btnBateriaCalibrar";
this.btnBateriaCalibrar.Size = new System.Drawing.Size(135, 19);
this.btnBateriaCalibrar.TabIndex = 22;
@ -295,14 +298,25 @@
this.gpbCameras.Controls.Add(this.lblCaminho);
this.gpbCameras.Controls.Add(this.cmbCaminho);
this.gpbCameras.Location = new System.Drawing.Point(646, 454);
this.gpbCameras.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.gpbCameras.Margin = new System.Windows.Forms.Padding(2);
this.gpbCameras.Name = "gpbCameras";
this.gpbCameras.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.gpbCameras.Padding = new System.Windows.Forms.Padding(2);
this.gpbCameras.Size = new System.Drawing.Size(197, 121);
this.gpbCameras.TabIndex = 23;
this.gpbCameras.TabStop = false;
this.gpbCameras.Text = "Câmeras";
//
// btnAtualizarCameras
//
this.btnAtualizarCameras.Location = new System.Drawing.Point(64, 99);
this.btnAtualizarCameras.Margin = new System.Windows.Forms.Padding(2);
this.btnAtualizarCameras.Name = "btnAtualizarCameras";
this.btnAtualizarCameras.Size = new System.Drawing.Size(129, 19);
this.btnAtualizarCameras.TabIndex = 26;
this.btnAtualizarCameras.Text = "Atualizar";
this.btnAtualizarCameras.UseVisualStyleBackColor = true;
this.btnAtualizarCameras.Click += new System.EventHandler(this.btnAtualizarCameras_Click);
//
// lblSolodir
//
this.lblSolodir.AutoSize = true;
@ -316,7 +330,7 @@
//
this.cmbSoloDir.FormattingEnabled = true;
this.cmbSoloDir.Location = new System.Drawing.Point(64, 72);
this.cmbSoloDir.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmbSoloDir.Margin = new System.Windows.Forms.Padding(2);
this.cmbSoloDir.Name = "cmbSoloDir";
this.cmbSoloDir.Size = new System.Drawing.Size(129, 21);
this.cmbSoloDir.TabIndex = 24;
@ -334,7 +348,7 @@
//
this.cmbSoloEsq.FormattingEnabled = true;
this.cmbSoloEsq.Location = new System.Drawing.Point(64, 47);
this.cmbSoloEsq.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmbSoloEsq.Margin = new System.Windows.Forms.Padding(2);
this.cmbSoloEsq.Name = "cmbSoloEsq";
this.cmbSoloEsq.Size = new System.Drawing.Size(129, 21);
this.cmbSoloEsq.TabIndex = 22;
@ -352,27 +366,49 @@
//
this.cmbCaminho.FormattingEnabled = true;
this.cmbCaminho.Location = new System.Drawing.Point(64, 23);
this.cmbCaminho.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmbCaminho.Margin = new System.Windows.Forms.Padding(2);
this.cmbCaminho.Name = "cmbCaminho";
this.cmbCaminho.Size = new System.Drawing.Size(129, 21);
this.cmbCaminho.TabIndex = 20;
//
// btnAtualizarCameras
// btnFreio
//
this.btnAtualizarCameras.Location = new System.Drawing.Point(64, 99);
this.btnAtualizarCameras.Margin = new System.Windows.Forms.Padding(2);
this.btnAtualizarCameras.Name = "btnAtualizarCameras";
this.btnAtualizarCameras.Size = new System.Drawing.Size(129, 19);
this.btnAtualizarCameras.TabIndex = 26;
this.btnAtualizarCameras.Text = "Atualizar";
this.btnAtualizarCameras.UseVisualStyleBackColor = true;
this.btnAtualizarCameras.Click += new System.EventHandler(this.btnAtualizarCameras_Click);
this.btnFreio.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnFreio.Location = new System.Drawing.Point(867, 499);
this.btnFreio.Name = "btnFreio";
this.btnFreio.Size = new System.Drawing.Size(75, 23);
this.btnFreio.TabIndex = 24;
this.btnFreio.Text = "Freio";
this.btnFreio.UseVisualStyleBackColor = true;
this.btnFreio.Click += new System.EventHandler(this.btnFreio_Click);
//
// cmbModFreio
//
this.cmbModFreio.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbModFreio.FormattingEnabled = true;
this.cmbModFreio.Location = new System.Drawing.Point(867, 477);
this.cmbModFreio.Margin = new System.Windows.Forms.Padding(2);
this.cmbModFreio.Name = "cmbModFreio";
this.cmbModFreio.Size = new System.Drawing.Size(75, 21);
this.cmbModFreio.TabIndex = 27;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(864, 462);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 13);
this.label1.TabIndex = 27;
this.label1.Text = "Módulo";
//
// frmSenConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(954, 585);
this.Controls.Add(this.label1);
this.Controls.Add(this.cmbModFreio);
this.Controls.Add(this.btnFreio);
this.Controls.Add(this.gpbCameras);
this.Controls.Add(this.gpbBateria);
this.Controls.Add(this.lblUltrassom);
@ -443,5 +479,8 @@
private System.Windows.Forms.ComboBox cmbCaminho;
private System.Windows.Forms.Button btnBateriaCalibrar;
private System.Windows.Forms.Button btnAtualizarCameras;
private System.Windows.Forms.Button btnFreio;
private System.Windows.Forms.ComboBox cmbModFreio;
private System.Windows.Forms.Label label1;
}
}

View File

@ -4,12 +4,8 @@ using AgroBase.Models.Modules;
using AgroBase.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
@ -63,6 +59,9 @@ namespace AgroBase.Forms.Sensoriamento
cmbBateriaParametro.Items.AddRange(PZEMService.Parametros.Keys.ToArray());
cmbBateriaParametro.SelectedIndex = 0;
cmbModFreio.Items.Clear();
cmbModFreio.Items.AddRange(Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Select(x => x.Modulo_ID).ToArray());
cmbModFreio.SelectedIndex = 0;
}
private void AtualizarCameras()
@ -272,6 +271,30 @@ namespace AgroBase.Forms.Sensoriamento
ModbusService.AdicionarComandoNaFila(Comando);
}
private void btnFreio_Click(object sender, EventArgs e)
{
string Mod_ID = cmbModFreio.Text;
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.First(x => x.Modulo_ID == Mod_ID);
var ServoFreio = Variaveis.OperacaoEmAndamento.DispSen.Dados.Servos.FirstOrDefault(x => x.ID.Contains(Modulo.Modulo_ID) && x.Inicializado);
if (ServoFreio != null)
{
if (!Modulo.MovMotor.ConfigFreio.Controle)
{
(bool atuar, int angulo) = Modulo.MovMotor.ConfigFreio.AtualizarDadosFreio(true, 0, -1, 5);
if (atuar)
{
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, ServoFreio.ID, angulo);
}
}
else
{
(bool atuar, int angulo) = Modulo.MovMotor.ConfigFreio.AtualizarDadosFreio(false);
if (atuar)
{
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, ServoFreio.ID, angulo);
}
}
}
}
}
}

View File

@ -29,19 +29,27 @@ namespace AgroBase.Forms
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea17 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend17 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series17 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea18 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend18 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series18 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea19 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend19 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series19 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea20 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend20 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series20 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend6 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea7 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend7 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea8 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend8 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.pnlFundo = new System.Windows.Forms.Panel();
this.lblMagnetometro = new System.Windows.Forms.Label();
this.lblGPS = new System.Windows.Forms.Label();
this.pnlOrientacaoMagnetometro = new System.Windows.Forms.Panel();
this.pnlOrientacaoGPS = new System.Windows.Forms.Panel();
this.lblU2 = new System.Windows.Forms.Label();
this.lblU1 = new System.Windows.Forms.Label();
this.lblU4 = new System.Windows.Forms.Label();
this.lblU3 = new System.Windows.Forms.Label();
this.lblUL_A05 = new System.Windows.Forms.Label();
this.lblUL_Wit = new System.Windows.Forms.Label();
this.lblUL_Pzm = new System.Windows.Forms.Label();
@ -116,14 +124,6 @@ namespace AgroBase.Forms
this.lblEFA_SP = new System.Windows.Forms.Label();
this.lblM_EF = new System.Windows.Forms.Label();
this.picEF = new System.Windows.Forms.PictureBox();
this.lblU3 = new System.Windows.Forms.Label();
this.lblU4 = new System.Windows.Forms.Label();
this.lblU2 = new System.Windows.Forms.Label();
this.lblU1 = new System.Windows.Forms.Label();
this.lblMagnetometro = new System.Windows.Forms.Label();
this.lblGPS = new System.Windows.Forms.Label();
this.pnlOrientacaoMagnetometro = new System.Windows.Forms.Panel();
this.pnlOrientacaoGPS = new System.Windows.Forms.Panel();
this.pnlFundo.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.chartET)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.chartDT)).BeginInit();
@ -229,6 +229,94 @@ namespace AgroBase.Forms
this.pnlFundo.Size = new System.Drawing.Size(1473, 811);
this.pnlFundo.TabIndex = 0;
//
// lblMagnetometro
//
this.lblMagnetometro.AutoSize = true;
this.lblMagnetometro.Location = new System.Drawing.Point(744, 97);
this.lblMagnetometro.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblMagnetometro.Name = "lblMagnetometro";
this.lblMagnetometro.Size = new System.Drawing.Size(75, 13);
this.lblMagnetometro.TabIndex = 188;
this.lblMagnetometro.Text = "Magnetômetro";
//
// lblGPS
//
this.lblGPS.AutoSize = true;
this.lblGPS.Location = new System.Drawing.Point(685, 97);
this.lblGPS.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblGPS.Name = "lblGPS";
this.lblGPS.Size = new System.Drawing.Size(29, 13);
this.lblGPS.TabIndex = 187;
this.lblGPS.Text = "GPS";
//
// pnlOrientacaoMagnetometro
//
this.pnlOrientacaoMagnetometro.BackColor = System.Drawing.Color.White;
this.pnlOrientacaoMagnetometro.BackgroundImage = global::AgroBase.Properties.Resources.rosa_dos_ventos;
this.pnlOrientacaoMagnetometro.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.pnlOrientacaoMagnetometro.Location = new System.Drawing.Point(740, 11);
this.pnlOrientacaoMagnetometro.Margin = new System.Windows.Forms.Padding(2);
this.pnlOrientacaoMagnetometro.Name = "pnlOrientacaoMagnetometro";
this.pnlOrientacaoMagnetometro.Size = new System.Drawing.Size(78, 84);
this.pnlOrientacaoMagnetometro.TabIndex = 186;
this.pnlOrientacaoMagnetometro.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlOrientacaoMagnetometro_Paint);
//
// pnlOrientacaoGPS
//
this.pnlOrientacaoGPS.BackColor = System.Drawing.Color.White;
this.pnlOrientacaoGPS.BackgroundImage = global::AgroBase.Properties.Resources.rosa_dos_ventos;
this.pnlOrientacaoGPS.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.pnlOrientacaoGPS.Location = new System.Drawing.Point(658, 11);
this.pnlOrientacaoGPS.Margin = new System.Windows.Forms.Padding(2);
this.pnlOrientacaoGPS.Name = "pnlOrientacaoGPS";
this.pnlOrientacaoGPS.Size = new System.Drawing.Size(78, 84);
this.pnlOrientacaoGPS.TabIndex = 185;
this.pnlOrientacaoGPS.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlOrientacaoGPS_Paint);
//
// lblU2
//
this.lblU2.AutoSize = true;
this.lblU2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU2.Location = new System.Drawing.Point(748, 555);
this.lblU2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU2.Name = "lblU2";
this.lblU2.Size = new System.Drawing.Size(68, 17);
this.lblU2.TabIndex = 184;
this.lblU2.Text = "U2: 0 mm";
//
// lblU1
//
this.lblU1.AutoSize = true;
this.lblU1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU1.Location = new System.Drawing.Point(639, 555);
this.lblU1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU1.Name = "lblU1";
this.lblU1.Size = new System.Drawing.Size(68, 17);
this.lblU1.TabIndex = 183;
this.lblU1.Text = "U1: 0 mm";
//
// lblU4
//
this.lblU4.AutoSize = true;
this.lblU4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU4.Location = new System.Drawing.Point(748, 238);
this.lblU4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU4.Name = "lblU4";
this.lblU4.Size = new System.Drawing.Size(68, 17);
this.lblU4.TabIndex = 182;
this.lblU4.Text = "U4: 0 mm";
//
// lblU3
//
this.lblU3.AutoSize = true;
this.lblU3.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU3.Location = new System.Drawing.Point(639, 238);
this.lblU3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU3.Name = "lblU3";
this.lblU3.Size = new System.Drawing.Size(68, 17);
this.lblU3.TabIndex = 181;
this.lblU3.Text = "U3: 0 mm";
//
// lblUL_A05
//
this.lblUL_A05.AutoSize = true;
@ -370,68 +458,68 @@ namespace AgroBase.Forms
//
// chartET
//
chartArea17.Name = "ChartArea1";
this.chartET.ChartAreas.Add(chartArea17);
legend17.Name = "Legend1";
this.chartET.Legends.Add(legend17);
chartArea5.Name = "ChartArea1";
this.chartET.ChartAreas.Add(chartArea5);
legend5.Name = "Legend1";
this.chartET.Legends.Add(legend5);
this.chartET.Location = new System.Drawing.Point(201, 410);
this.chartET.Margin = new System.Windows.Forms.Padding(2);
this.chartET.Name = "chartET";
series17.ChartArea = "ChartArea1";
series17.Legend = "Legend1";
series17.Name = "Series1";
this.chartET.Series.Add(series17);
series5.ChartArea = "ChartArea1";
series5.Legend = "Legend1";
series5.Name = "Series1";
this.chartET.Series.Add(series5);
this.chartET.Size = new System.Drawing.Size(434, 390);
this.chartET.TabIndex = 94;
this.chartET.Text = "chart1";
//
// chartDT
//
chartArea18.Name = "ChartArea1";
this.chartDT.ChartAreas.Add(chartArea18);
legend18.Name = "Legend1";
this.chartDT.Legends.Add(legend18);
chartArea6.Name = "ChartArea1";
this.chartDT.ChartAreas.Add(chartArea6);
legend6.Name = "Legend1";
this.chartDT.Legends.Add(legend6);
this.chartDT.Location = new System.Drawing.Point(834, 410);
this.chartDT.Margin = new System.Windows.Forms.Padding(2);
this.chartDT.Name = "chartDT";
series18.ChartArea = "ChartArea1";
series18.Legend = "Legend1";
series18.Name = "Series1";
this.chartDT.Series.Add(series18);
series6.ChartArea = "ChartArea1";
series6.Legend = "Legend1";
series6.Name = "Series1";
this.chartDT.Series.Add(series6);
this.chartDT.Size = new System.Drawing.Size(433, 390);
this.chartDT.TabIndex = 110;
this.chartDT.Text = "chart1";
//
// chartDF
//
chartArea19.Name = "ChartArea1";
this.chartDF.ChartAreas.Add(chartArea19);
legend19.Name = "Legend1";
this.chartDF.Legends.Add(legend19);
chartArea7.Name = "ChartArea1";
this.chartDF.ChartAreas.Add(chartArea7);
legend7.Name = "Legend1";
this.chartDF.Legends.Add(legend7);
this.chartDF.Location = new System.Drawing.Point(834, 4);
this.chartDF.Margin = new System.Windows.Forms.Padding(2);
this.chartDF.Name = "chartDF";
series19.ChartArea = "ChartArea1";
series19.Legend = "Legend1";
series19.Name = "Series1";
this.chartDF.Series.Add(series19);
series7.ChartArea = "ChartArea1";
series7.Legend = "Legend1";
series7.Name = "Series1";
this.chartDF.Series.Add(series7);
this.chartDF.Size = new System.Drawing.Size(433, 390);
this.chartDF.TabIndex = 109;
this.chartDF.Text = "chart1";
//
// chartEF
//
chartArea20.Name = "ChartArea1";
this.chartEF.ChartAreas.Add(chartArea20);
legend20.Name = "Legend1";
this.chartEF.Legends.Add(legend20);
chartArea8.Name = "ChartArea1";
this.chartEF.ChartAreas.Add(chartArea8);
legend8.Name = "Legend1";
this.chartEF.Legends.Add(legend8);
this.chartEF.Location = new System.Drawing.Point(201, 4);
this.chartEF.Margin = new System.Windows.Forms.Padding(2);
this.chartEF.Name = "chartEF";
series20.ChartArea = "ChartArea1";
series20.Legend = "Legend1";
series20.Name = "Series1";
this.chartEF.Series.Add(series20);
series8.ChartArea = "ChartArea1";
series8.Legend = "Legend1";
series8.Name = "Series1";
this.chartEF.Series.Add(series8);
this.chartEF.Size = new System.Drawing.Size(434, 390);
this.chartEF.TabIndex = 93;
this.chartEF.Text = "chart1";
@ -1007,94 +1095,6 @@ namespace AgroBase.Forms
this.picEF.TabIndex = 90;
this.picEF.TabStop = false;
//
// lblU3
//
this.lblU3.AutoSize = true;
this.lblU3.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU3.Location = new System.Drawing.Point(639, 238);
this.lblU3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU3.Name = "lblU3";
this.lblU3.Size = new System.Drawing.Size(68, 17);
this.lblU3.TabIndex = 181;
this.lblU3.Text = "U3: 0 mm";
//
// lblU4
//
this.lblU4.AutoSize = true;
this.lblU4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU4.Location = new System.Drawing.Point(748, 238);
this.lblU4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU4.Name = "lblU4";
this.lblU4.Size = new System.Drawing.Size(68, 17);
this.lblU4.TabIndex = 182;
this.lblU4.Text = "U4: 0 mm";
//
// lblU2
//
this.lblU2.AutoSize = true;
this.lblU2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU2.Location = new System.Drawing.Point(748, 555);
this.lblU2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU2.Name = "lblU2";
this.lblU2.Size = new System.Drawing.Size(68, 17);
this.lblU2.TabIndex = 184;
this.lblU2.Text = "U2: 0 mm";
//
// lblU1
//
this.lblU1.AutoSize = true;
this.lblU1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblU1.Location = new System.Drawing.Point(639, 555);
this.lblU1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblU1.Name = "lblU1";
this.lblU1.Size = new System.Drawing.Size(68, 17);
this.lblU1.TabIndex = 183;
this.lblU1.Text = "U1: 0 mm";
//
// lblMagnetometro
//
this.lblMagnetometro.AutoSize = true;
this.lblMagnetometro.Location = new System.Drawing.Point(744, 97);
this.lblMagnetometro.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblMagnetometro.Name = "lblMagnetometro";
this.lblMagnetometro.Size = new System.Drawing.Size(75, 13);
this.lblMagnetometro.TabIndex = 188;
this.lblMagnetometro.Text = "Magnetômetro";
//
// lblGPS
//
this.lblGPS.AutoSize = true;
this.lblGPS.Location = new System.Drawing.Point(685, 97);
this.lblGPS.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblGPS.Name = "lblGPS";
this.lblGPS.Size = new System.Drawing.Size(29, 13);
this.lblGPS.TabIndex = 187;
this.lblGPS.Text = "GPS";
//
// pnlOrientacaoMagnetometro
//
this.pnlOrientacaoMagnetometro.BackColor = System.Drawing.Color.White;
this.pnlOrientacaoMagnetometro.BackgroundImage = global::AgroBase.Properties.Resources.rosa_dos_ventos;
this.pnlOrientacaoMagnetometro.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.pnlOrientacaoMagnetometro.Location = new System.Drawing.Point(740, 11);
this.pnlOrientacaoMagnetometro.Margin = new System.Windows.Forms.Padding(2);
this.pnlOrientacaoMagnetometro.Name = "pnlOrientacaoMagnetometro";
this.pnlOrientacaoMagnetometro.Size = new System.Drawing.Size(78, 84);
this.pnlOrientacaoMagnetometro.TabIndex = 186;
this.pnlOrientacaoMagnetometro.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlOrientacaoMagnetometro_Paint);
//
// pnlOrientacaoGPS
//
this.pnlOrientacaoGPS.BackColor = System.Drawing.Color.White;
this.pnlOrientacaoGPS.BackgroundImage = global::AgroBase.Properties.Resources.rosa_dos_ventos;
this.pnlOrientacaoGPS.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.pnlOrientacaoGPS.Location = new System.Drawing.Point(658, 11);
this.pnlOrientacaoGPS.Margin = new System.Windows.Forms.Padding(2);
this.pnlOrientacaoGPS.Name = "pnlOrientacaoGPS";
this.pnlOrientacaoGPS.Size = new System.Drawing.Size(78, 84);
this.pnlOrientacaoGPS.TabIndex = 185;
this.pnlOrientacaoGPS.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlOrientacaoGPS_Paint);
//
// frmAcompanhamento
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1107,7 +1107,6 @@ namespace AgroBase.Forms
this.Text = "Acompanhamento";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmAcompanhamento_FormClosing);
this.Load += new System.EventHandler(this.frmAcompanhamento_Load);
this.Shown += new System.EventHandler(this.frmAcompanhamento_Shown);
this.pnlFundo.ResumeLayout(false);
this.pnlFundo.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.chartET)).EndInit();

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using static AgroBase.Models.Enums;
@ -14,6 +15,8 @@ namespace AgroBase.Forms
{
public partial class frmAcompanhamento : Form
{
AsyncTaskTimerModel tmrAtualizacao;
public frmAcompanhamento()
{
InitializeComponent();
@ -25,152 +28,175 @@ namespace AgroBase.Forms
picET.Paint += pic_Paint;
picDF.Paint += pic_Paint;
picDT.Paint += pic_Paint;
}
private void frmAcompanhamento_Shown(object sender, EventArgs e)
{
tmrAtualizacao = new AsyncTaskTimerModel(tmrAtualizacao_Tick, 500, this);
tmrAtualizacao.Start();
}
private void frmAcompanhamento_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
tmrAtualizacao.Stop();
}
public void AtualizaGrafico()
public async Task tmrAtualizacao_Tick()
{
picET.Invalidate();
picEF.Invalidate();
picDT.Invalidate();
picDF.Invalidate();
try
{
AtualzarDadosMovimentacao();
}
catch (Exception ex)
{
pnlOrientacaoGPS.Invalidate();
pnlOrientacaoMagnetometro.Invalidate();
AtualzarDadosMovimentacao();
if (PZEMService.Iniciado)
{
lblUL_Pzm.Text = "Ultima Leitura PZM: " + PZEMService.UltimaLeitura.DataHora.ToString("HH:mm:ss");
lblTensao.Text = "Bateria: " + PZEMService.UltimaLeitura.Tensao.ToString("0.00") + " V - " + PZEMService.UltimaLeitura.Corrente.ToString("0.00") + " A - " + PZEMService.UltimaLeitura.Potencia.ToString("0.00") + " W";
}
if (WT901CService.Iniciado)
{
lblUL_Wit.Text = "Ultima Leitura WIT: " + WT901CService.DadosLeitura.Momento.ToString("HH:mm:ss");
}
if (UltrasonicA05Service.Iniciado)
{
lblUL_A05.Text = "Ultima Leitura A05: " + UltrasonicA05Service.DadosLeitura.Momento.ToString("HH:mm:ss");
lblU1.Text = "U1: " + UltrasonicA05Service.DadosLeitura.U1.ToString("") + " mm";
lblU2.Text = "U2: " + UltrasonicA05Service.DadosLeitura.U2.ToString("") + " mm";
lblU3.Text = "U3: " + UltrasonicA05Service.DadosLeitura.U3.ToString("") + " mm";
lblU4.Text = "U4: " + UltrasonicA05Service.DadosLeitura.U4.ToString("") + " mm";
}
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.Conectado)
{
AtualizarDadosSensor("AB3V", lblB3V);
AtualizarDadosSensor("AB5V", lblB5V);
AtualizarDadosSensor("AB7V2", lblB7V2);
AtualizarDadosSensor("AB12V", lblB12V);
}
}
private void AtualizarDadosSensor(string id, Label lbl)
{
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == id);
double d0 = 0;
double d1 = 0;
if (sensor != null && sensor.Inicializado && sensor.Leituras != null && sensor.Leituras.Count() > 0)
{
d0 = sensor.Leituras?[0] ?? 0;
d1 = sensor.Leituras?[1] ?? 0;
}
lbl.Text = "Barramento 3V: " + d0.ToString("0.00") + " V " + d1.ToString("0.00") + " mA";
}
private void AtualzarDadosMovimentacao()
{
if (chartEF.InvokeRequired)
{
chartEF.Invoke(new Action(AtualizaGrafico));
}
else
{
var DispMvd = Variaveis.OperacaoEmAndamento.DispMvd;
var DispMvd = Variaveis.OperacaoEmAndamento.DispMvd;
lblTempoConectado.Text = "Tempo conectado: " + TimeSpan.FromSeconds(DispMvd.TempoConectado).ToString(@"hh\:mm\:ss") + " hrs";
lblTempoEmMovimento.Text = "Tempo em movimento: " + TimeSpan.FromSeconds(DispMvd.Dados.TempoEmAtividade).ToString(@"hh\:mm\:ss") + " hrs";
lblDistanciaTotal.Text = "Distancia percorrida total: " + DispMvd.Dados.DistanciaPercorridaTotal.ToString("0.00") + " m";
lblDistanciaParcial.Text = "Distancia percorrida parcial: " + DispMvd.Dados.DistanciaPercorridaParcial.ToString("0.00") + " m";
lblTempoConectado.Text = "Tempo conectado: " + TimeSpan.FromSeconds(DispMvd.TempoConectado).ToString(@"hh\:mm\:ss") + " hrs";
lblTempoEmMovimento.Text = "Tempo em movimento: " + TimeSpan.FromSeconds(DispMvd.Dados.TempoEmAtividade).ToString(@"hh\:mm\:ss") + " hrs";
lblDistanciaTotal.Text = "Distancia percorrida total: " + DispMvd.Dados.DistanciaPercorridaTotal.ToString("0.00") + " m";
lblDistanciaParcial.Text = "Distancia percorrida parcial: " + DispMvd.Dados.DistanciaPercorridaParcial.ToString("0.00") + " m";
foreach (var Modulo in DispMvd.Dados.Modulos)
foreach (var Modulo in DispMvd.Dados.Modulos)
{
Label lblTitulo = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblM_" + Modulo.Modulo_ID);
lblTitulo.ForeColor = Modulo.MovMotor.Comandar ? Modulo.MovMotor.BLD_Inicializado ? Color.Green : Color.Red : Color.Black;
lblTitulo.Text = lblTitulo.Text.Split(' ')[0] + " (" + Modulo.Modulo_ID + ") - Alm: " + Modulo.MovMotor.CodigoAlarme;
Label lblM_RPMSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPMSP");
lblM_RPMSP.Text = "RPM SP: " + Modulo.MovMotor.RPM_SP_Leitura.ToString("0.00");
Label lblM_RPM = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPM");
lblM_RPM.Text = "RPM Roda: " + Modulo.MovMotor.RPM_Roda.ToString("0.00");
Label lblM_Velocidade = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Velocidade");
lblM_Velocidade.Text = "Velocidade: " + Modulo.MovMotor.VelocidadeInstantanea.ToString("0.00") + " Km/h";
Label lblM_SentidoSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_SentidoSP");
lblM_SentidoSP.Text = "Sentido SP: " + Enum.GetName(typeof(Sentido), Modulo.MovMotor.Sentido_SP);
Label lblM_Sentido = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Sentido");
lblM_Sentido.Text = "Sentido: " + Enum.GetName(typeof(Sentido), Modulo.MovMotor.Sentido);
Label lblM_Temperatura = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Temperatura");
lblM_Temperatura.Text = "Temperatura: " + Modulo.MovMotor.Temperatura.ToString("0.00") + "ºC";
lblM_Temperatura.ForeColor = Modulo.MovMotor.CodigoAlarme > 0 ? Color.Red : Color.Black;
Label lblM_Corrente = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Corrente");
lblM_Corrente.Text = "Corrente: " + Modulo.MovMotor.Corrente_Max.ToString("0.00") + "A";
Label lblM_Tensao = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Tensao");
lblM_Tensao.Text = "Tensão: " + Modulo.MovMotor.Tensao.ToString("0.00") + "V";
MvdMotorMOVSensorimanetoGrafico Log = null;
if (Modulo.MovMotor.LogGrafico.Count > 0)
{
Label lblTitulo = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblM_" + Modulo.Modulo_ID);
lblTitulo.ForeColor = Modulo.MovMotor.Comandar ? Modulo.MovMotor.BLD_Inicializado ? Color.Green : Color.Red : Color.Black;
lblTitulo.Text = lblTitulo.Text.Split(' ')[0] + " (" + Modulo.Modulo_ID + ") - Alm: " + Modulo.MovMotor.CodigoAlarme;
Label lblM_RPMSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPMSP");
lblM_RPMSP.Text = "RPM SP: " + Modulo.MovMotor.RPM_SP_Leitura.ToString("0.00");
Label lblM_RPM = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPM");
lblM_RPM.Text = "RPM Roda: " + Modulo.MovMotor.RPM_Roda.ToString("0.00");
Label lblM_Velocidade = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Velocidade");
lblM_Velocidade.Text = "Velocidade: " + Modulo.MovMotor.VelocidadeInstantanea.ToString("0.00") + " Km/h";
Label lblM_SentidoSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_SentidoSP");
lblM_SentidoSP.Text = "Sentido SP: " + Enum.GetName(typeof(Sentido), Modulo.MovMotor.Sentido_SP);
Label lblM_Sentido = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Sentido");
lblM_Sentido.Text = "Sentido: " + Enum.GetName(typeof(Sentido), Modulo.MovMotor.Sentido);
Label lblM_Temperatura = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Temperatura");
lblM_Temperatura.Text = "Temperatura: " + Modulo.MovMotor.Temperatura.ToString("0.00") + "ºC";
lblM_Temperatura.ForeColor = Modulo.MovMotor.CodigoAlarme > 0 ? Color.Red : Color.Black;
Label lblM_Corrente = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Corrente");
lblM_Corrente.Text = "Corrente: " + Modulo.MovMotor.Corrente_Max.ToString("0.00") + "A";
Label lblM_Tensao = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Tensao");
lblM_Tensao.Text = "Tensão: " + Modulo.MovMotor.Tensao.ToString("0.00") + "V";
Log = Modulo.MovMotor.LogGrafico[Modulo.MovMotor.LogGrafico.Count - 1];
}
MvdMotorMOVSensorimanetoGrafico Log = null;
if (Modulo.MovMotor.LogGrafico.Count > 0)
double Minimo = 0;
double Maximo = 0;
try
{
Chart chart = (Chart)(pnlFundo.Controls.Find("chart" + Modulo.Modulo_ID, false).First());
chart.Titles.Clear();
chart.Titles.Add(Modulo.Modulo_ID);
var Logs = (Modulo.MovMotor.LogGrafico.Count > MovimentacaoModel.LogsManter ? Modulo.MovMotor.LogGrafico.Skip(Math.Max(0, Modulo.MovMotor.LogGrafico.Count - MovimentacaoModel.LogsManter)).Take(MovimentacaoModel.LogsManter).ToList() : Modulo.MovMotor.LogGrafico).Where(log => log.Modulo_ID == Modulo.Modulo_ID).ToList();
chart.Series.Clear();
List<string> Momentos = Logs.Select(x => x.Momento.ToString("mm:ss:fff")).ToList();
var serieTensao = new Series("Tensão: " + (Log != null ? Log.Tensao : 0));
serieTensao.Points.DataBindXY(Momentos, Logs.Select(x => x.Tensao).ToList());
serieTensao.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTensao);
Minimo = Logs.Any() && Logs.Min(x => x.Tensao) < Minimo ? Logs.Min(x => x.Tensao) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.Tensao) > Maximo ? Logs.Max(x => x.Tensao) : Maximo;
var serieRPMsp = new Series("RPM SP: " + (Log != null ? Log.RPM_SP : 0));
serieRPMsp.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_SP).ToList());
serieRPMsp.ChartType = SeriesChartType.Line;
chart.Series.Add(serieRPMsp);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
Maximo = Logs.Any() && Logs.Min(x => x.RPM_SP) > Maximo ? Logs.Min(x => x.RPM_SP) : Maximo;
var serieRPMRoda = new Series("RPM Roda: " + (Log != null ? Log.RPM_Roda : 0));
serieRPMRoda.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Roda).ToList());
serieRPMRoda.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMRoda);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_Roda) < Minimo ? Logs.Min(x => x.RPM_Roda) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.RPM_Roda) > Maximo ? Logs.Max(x => x.RPM_Roda) : Maximo;
var serieRPMMotor = new Series("RPM Motor: " + (Log != null ? Log.RPM_Motor : 0));
serieRPMMotor.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Motor).ToList());
serieRPMMotor.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMMotor);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_Motor) < Minimo ? Logs.Min(x => x.RPM_Motor) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.RPM_Motor) > Maximo ? Logs.Max(x => x.RPM_Motor) : Maximo;
var serieTemperatura = new Series("Motor ºC: " + (Log != null ? Log.Temperatura : 0));
serieTemperatura.Points.DataBindXY(Momentos, Logs.Select(x => x.Temperatura).ToList());
serieTemperatura.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTemperatura);
Minimo = Logs.Any() && Logs.Min(x => x.Temperatura) < Minimo ? Logs.Min(x => x.Temperatura) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.Temperatura) > Maximo ? Logs.Max(x => x.Temperatura) : Maximo;
var serieTempDriver = new Series("Driver ºC: " + (Log != null ? Log.TemperaturaDriver : 0));
serieTempDriver.Points.DataBindXY(Momentos, Logs.Select(x => x.TemperaturaDriver).ToList());
serieTempDriver.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTempDriver);
Minimo = Logs.Any() && Logs.Min(x => x.TemperaturaDriver) < Minimo ? Logs.Min(x => x.TemperaturaDriver) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.TemperaturaDriver) > Maximo ? Logs.Max(x => x.TemperaturaDriver) : Maximo;
foreach (var legend in chart.Legends)
{
Log = Modulo.MovMotor.LogGrafico[Modulo.MovMotor.LogGrafico.Count - 1];
legend.Docking = Docking.Bottom;
}
double Minimo = 0;
double Maximo = 0;
try
{
Chart chart = (Chart)(pnlFundo.Controls.Find("chart" + Modulo.Modulo_ID, false).First());
chart.Titles.Clear();
chart.Titles.Add(Modulo.Modulo_ID);
var Logs = (Modulo.MovMotor.LogGrafico.Count > MovimentacaoModel.LogsManter ? Modulo.MovMotor.LogGrafico.Skip(Math.Max(0, Modulo.MovMotor.LogGrafico.Count - MovimentacaoModel.LogsManter)).Take(MovimentacaoModel.LogsManter).ToList() : Modulo.MovMotor.LogGrafico).Where(log => log.Modulo_ID == Modulo.Modulo_ID).ToList();
chart.Series.Clear();
List<string> Momentos = Logs.Select(x => x.Momento.ToString("mm:ss:fff")).ToList();
var serieTensao = new Series("Tensão: " + (Log != null ? Log.Tensao : 0));
serieTensao.Points.DataBindXY(Momentos, Logs.Select(x => x.Tensao).ToList());
serieTensao.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTensao);
Minimo = Logs.Any() && Logs.Min(x => x.Tensao) < Minimo ? Logs.Min(x => x.Tensao) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.Tensao) > Maximo ? Logs.Max(x => x.Tensao) : Maximo;
var serieRPMsp = new Series("RPM SP: " + (Log != null ? Log.RPM_SP : 0));
serieRPMsp.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_SP).ToList());
serieRPMsp.ChartType = SeriesChartType.Line;
chart.Series.Add(serieRPMsp);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
Maximo = Logs.Any() && Logs.Min(x => x.RPM_SP) > Maximo ? Logs.Min(x => x.RPM_SP) : Maximo;
var serieRPMRoda = new Series("RPM Roda: " + (Log != null ? Log.RPM_Roda : 0));
serieRPMRoda.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Roda).ToList());
serieRPMRoda.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMRoda);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_Roda) < Minimo ? Logs.Min(x => x.RPM_Roda) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.RPM_Roda) > Maximo ? Logs.Max(x => x.RPM_Roda) : Maximo;
var serieRPMMotor = new Series("RPM Motor: " + (Log != null ? Log.RPM_Motor : 0));
serieRPMMotor.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Motor).ToList());
serieRPMMotor.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMMotor);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_Motor) < Minimo ? Logs.Min(x => x.RPM_Motor) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.RPM_Motor) > Maximo ? Logs.Max(x => x.RPM_Motor) : Maximo;
var serieTemperatura = new Series("Motor ºC: " + (Log != null ? Log.Temperatura : 0));
serieTemperatura.Points.DataBindXY(Momentos, Logs.Select(x => x.Temperatura).ToList());
serieTemperatura.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTemperatura);
Minimo = Logs.Any() && Logs.Min(x => x.Temperatura) < Minimo ? Logs.Min(x => x.Temperatura) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.Temperatura) > Maximo ? Logs.Max(x => x.Temperatura) : Maximo;
var serieTempDriver = new Series("Driver ºC: " + (Log != null ? Log.TemperaturaDriver : 0));
serieTempDriver.Points.DataBindXY(Momentos, Logs.Select(x => x.TemperaturaDriver).ToList());
serieTempDriver.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTempDriver);
Minimo = Logs.Any() && Logs.Min(x => x.TemperaturaDriver) < Minimo ? Logs.Min(x => x.TemperaturaDriver) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.TemperaturaDriver) > Maximo ? Logs.Max(x => x.TemperaturaDriver) : Maximo;
foreach (var legend in chart.Legends)
{
legend.Docking = Docking.Bottom;
}
chart.ChartAreas[0].AxisY.Minimum = Minimo - 5;
chart.ChartAreas[0].AxisY.Maximum = Maximo + 5;
}
catch
{
}
chart.ChartAreas[0].AxisY.Minimum = Minimo - 5;
chart.ChartAreas[0].AxisY.Maximum = Maximo + 5;
}
catch
{
}
}
}
@ -332,56 +358,6 @@ namespace AgroBase.Forms
}
delegate void AtualizarSensoresDelegate(string Texto);
public void AtualizarSensores(string Texto)
{
Label lbl =
Texto.Contains("Bateria") ? lblTensao:
Texto.Contains("Temp") ? lblTemperatura:
Texto.Contains("3V") ? lblB3V :
Texto.Contains("5V") ? lblB5V :
Texto.Contains("7V2") ? lblB7V2 :
Texto.Contains("12V") ? lblB12V :
Texto.Contains("PZM") ? lblUL_Pzm :
Texto.Contains("WIT") ? lblUL_Wit :
Texto.Contains("A05") ? lblUL_A05 :
Texto.Contains("U1") ? lblU1 :
Texto.Contains("U2") ? lblU2 :
Texto.Contains("U3") ? lblU3 :
Texto.Contains("U4") ? lblU4 :
new Label();
if (lbl.InvokeRequired)
{
lbl.Invoke(new AtualizarSensoresDelegate(AtualizarSensores), Texto);
}
else
{
lbl.Text = Texto;
}
}
public void AtualizarOrientacao()
{
if (pnlOrientacaoGPS.InvokeRequired)
{
pnlOrientacaoGPS.Invoke(new Action(pnlOrientacaoGPS.Invalidate));
}
else
{
pnlOrientacaoGPS.Invalidate();
}
if (pnlOrientacaoMagnetometro.InvokeRequired)
{
pnlOrientacaoMagnetometro.Invoke(new Action(pnlOrientacaoMagnetometro.Invalidate));
}
else
{
pnlOrientacaoMagnetometro.Invalidate();
}
}
private void pnlOrientacaoGPS_Paint(object sender, PaintEventArgs e)
{
double Angulo = GPSService.UltimaLeitura.Orientacao;
@ -393,6 +369,7 @@ namespace AgroBase.Forms
double Angulo = Variaveis.OperacaoEmAndamento.Sensoriamento.AnguloCarroBussola;
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)Angulo, -90);
}
}
}

View File

@ -1,12 +1,11 @@
using AgroBase.Models;
using AgroBase.Services;
using CefSharp;
using CefSharp.WinForms;
using Newtonsoft.Json;
using SharpDX.Text;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AgroBase.Forms
@ -14,7 +13,7 @@ namespace AgroBase.Forms
public partial class frmGPS : Form
{
private MapasModel Mapa;
private Timer tmrLeitura;
private AsyncTaskTimerModel tmrLeitura;
private List<GPSModel> Trajetoria = new List<GPSModel>();
private string LogID = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss");
@ -31,18 +30,16 @@ namespace AgroBase.Forms
private void frmGPS_Load(object sender, EventArgs e)
{
IniciarMapa();
tmrLeitura = new Timer() { Interval = 1000 };
tmrLeitura.Tick += tmrLeitura_Tick;
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 1000, this);
tmrLeitura.Start();
}
private void frmGPS_FormClosing(object sender, FormClosingEventArgs e)
{
tmrLeitura.Stop();
tmrLeitura.Dispose();
}
private void tmrLeitura_Tick(object sender, EventArgs e)
private async Task tmrLeitura_Tick()
{
lblAltitude.Text = "Altitude: " + GPSService.UltimaLeitura.Altitude.ToString("0.0");
lblDatahora.Text = "Ultima Leitura: " + GPSService.UltimaLeitura.DataHora.ToString("HH:mm:ss");

View File

@ -15,7 +15,6 @@ namespace AgroBase.Forms
public static frmPrincipal frmPrincipal = new frmPrincipal();
public static frmJoystick frmJoystick = new frmJoystick();
public static frmAcompanhamento frmAcompanhamento = new frmAcompanhamento();
public static frmIHM frmIHM = new frmIHM()
{
FormBorderStyle = FormBorderStyle.None,
@ -31,6 +30,7 @@ namespace AgroBase.Forms
MKS057DService.IniciarRotinas();
ModbusService.IniciarRotinas();
KinectService.InicializarRotinas();
GeneralJoystick.IniciarRotinas();
VersionamentoService.AtualizarArquivoVersionamento(true).ConfigureAwait(false);
EncerrarProcessosPython();

View File

@ -13,25 +13,22 @@ namespace AgroBase.Forms
{
LoRaService loraService = Variaveis.ConexaoLoRa;
LoRaParametrosModel Parametros = null;
Timer tmrLeitura = new Timer() { Interval = 1000 };
AsyncTaskTimerModel tmrLeitura;
public frmLoraConfig()
{
InitializeComponent();
tmrLeitura.Tick += tmrLeitura_Tick;
tmrLeitura.Start();
}
private void tmrLeitura_Tick(object sender, EventArgs e)
private void frmLoraConfig_Load(object sender, EventArgs e)
{
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 1000, this);
tmrLeitura.Start();
//Parametros = loraService.CarregarParametros();
if (LoRaService.Iniciado)
{
var MensagemDisponivel = loraService.MensagemPendente;
if (MensagemDisponivel != null)
{
AtualizarConsole(MensagemDisponivel.Remetente, MensagemDisponivel.Destinatario, MensagemDisponivel.Mensagem);
}
AtualizarParametros().ConfigureAwait(false);
}
}
@ -71,12 +68,15 @@ namespace AgroBase.Forms
AtualizarDadosTela();
}
private void frmLoraConfig_Load(object sender, EventArgs e)
private async Task tmrLeitura_Tick()
{
//Parametros = loraService.CarregarParametros();
if (LoRaService.Iniciado)
{
AtualizarParametros().ConfigureAwait(false);
var MensagemDisponivel = loraService.MensagemPendente;
if (MensagemDisponivel != null)
{
AtualizarConsole(MensagemDisponivel.Remetente, MensagemDisponivel.Destinatario, MensagemDisponivel.Mensagem);
}
}
}

View File

@ -10,16 +10,16 @@ using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
using System.Timers;
namespace AgroBase
{
public partial class frmPrincipal : Form
{
System.Timers.Timer tmrDispositivos = new System.Timers.Timer() { Interval = 1000, Enabled = false };
System.Timers.Timer tmrAtualizacaoArquivos = new System.Timers.Timer() { Interval = 300, Enabled = false };
AsyncTaskTimerModel tmrLoopDispositivos;
AsyncTaskTimerModel tmrAtualizacaoArquivos;
public frmPrincipal()
{
@ -28,14 +28,12 @@ namespace AgroBase
private void Form1_Load(object sender, EventArgs e)
{
tmrDispositivos.Elapsed += TmrDispositivos_Elapsed;
tmrDispositivos.Start();
tmrLoopDispositivos = new AsyncTaskTimerModel(tmrLoopDispositivos_Tick, SerialService.InteraloVerificacao, this);
tmrLoopDispositivos.Start();
tmrAtualizacaoArquivos.Elapsed += TmrAtualizacaoArquivos_Elapsed;
tmrAtualizacaoArquivos = new AsyncTaskTimerModel(tmrAtualizacaoArquivos_Tick, 300, this);
tmrAtualizacaoArquivos.Start();
AtualizaDadosGerais();
btnJoyAtt_Click(new object(), new EventArgs());
cmbModoOperacao.Items.Clear();
@ -49,68 +47,6 @@ namespace AgroBase
e.Cancel = true;
}
public void AtualizaDadosGerais()
{
Func<bool> funcVel = new Func<bool>(() =>
{
tkbVelocidade.Minimum = 0;
tkbVelocidade.Maximum = 100;
FuncoesGlobais.PreencheValorTrackBar(tkbVelocidade, Variaveis.OperacaoEmAndamento.Controle.VelocidadeMP);
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(tkbVelocidade, funcVel);
Func<bool> funcAng = new Func<bool>(() =>
{
tkbAngulo.Minimum = 0;
tkbAngulo.Maximum = 90;
FuncoesGlobais.PreencheValorTrackBar(tkbAngulo, Variaveis.OperacaoEmAndamento.Controle.Angulo);
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(tkbAngulo, funcAng);
Func<bool> funcKmh = new Func<bool>(() =>
{
trkKmh.Minimum = 0;
trkKmh.Maximum = 100;
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(trkKmh, funcKmh);
Func<bool> funcRpm = new Func<bool>(() =>
{
trkRPM.Minimum = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
trkRPM.Maximum = VariaveisEquipamento.RPM_Max_Roda;
FuncoesGlobais.PreencheValorTrackBar(trkRPM, Variaveis.OperacaoEmAndamento.Controle.RPM_SP);
int percentual = Convert.ToInt32((trkRPM.Value / (double)VariaveisEquipamento.RPM_Max_Roda) * 100.0);
AtualizaRPM(percentual);
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(trkRPM, funcRpm);
}
private void TmrAtualizacaoArquivos_Elapsed(object sender, ElapsedEventArgs e)
{
tmrAtualizacaoArquivos.Stop();
Func<bool> func = new Func<bool>(() =>
{
lblProgressoAtualizacao.Text = VersionamentoService.AtualizandoArquivos ? $"({VersionamentoService.ProgressoAtualizacao.ToString("0.00")}%) Atualizando arquivos..." : VersionamentoService.ResultadoAtualizacao;
pgbAtualizacaoArquivos.Value = (int)VersionamentoService.ProgressoAtualizacao;
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(pgbAtualizacaoArquivos, func);
tmrAtualizacaoArquivos.Start();
}
private void btnForcarAtualizacao_Click(object sender, EventArgs e)
{
VersionamentoService.ForcarDownloadArquivos = true;
VersionamentoService.AtualizarArquivoVersionamento(true).ConfigureAwait(false);
}
#region DISPOSITIVOS
@ -161,61 +97,93 @@ namespace AgroBase
}
}
private async void TmrDispositivos_Elapsed(object sender, ElapsedEventArgs e)
{
((System.Timers.Timer)sender).Stop();
Func<bool> funcao = new Func<bool>(() =>
{
lstDisponiveis.Items.Clear();
lstDisponiveis.Items.AddRange(
SerialService.DispositivosMapeados
.GroupBy(x => x.Dispositivo)
.Select(x => new ListViewItem()
{
Text =
x.FirstOrDefault().Endereco + " - " + Enum.GetName(typeof(T_Code), x.Key) + " v" + x.FirstOrDefault().Versao +
(SerialService.DispositivosMultiplos.Contains(x.FirstOrDefault().Dispositivo) ? (" (" + string.Join(", ", x.Where(y => y.Conectado).Select(y => y.Mod_ID)) + ")") :
"") + " - " +
(x.Any(y => y.Conectado) ? "Conectado" : "Desconectado")
}).ToArray()
);
if (SerialService.DispositivosMapeados.Count == 0)
{
Variaveis.DispositivosConectados.Where(x => x.Dados.GetStatusConexao()).ToList().ForEach(x => x.AcaoDesconectar());
}
Variaveis.DispositivosConectados.ForEach(x =>
{
x.AcaoConexao();
});
bool opLiberada = Variaveis.OperacaoEmAndamento.OperacaoLiberada;
lblStripOperacaoLiberada.Text = "Operação Liberada: " + (opLiberada ? "Sim" : "Não");
lblStripOperacaoLiberada.ForeColor = opLiberada ? Color.Green : Color.Red;
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(lstDisponiveis, funcao);
if (chbConexaoautomatica.Checked)
{
await SerialService.RealizarVarreduraPortasUSB((System.Timers.Timer)sender);
AtualizaDadosGerais();
}
((System.Timers.Timer)sender).Start();
}
private void cmbDispositivos_SelectedIndexChanged(object sender, EventArgs e)
{
btnJoyAtt_Click(sender, e);
}
private async Task tmrLoopDispositivos_Tick()
{
AtualizaDadosGerais();
lstDisponiveis.Items.Clear();
lstDisponiveis.Items.AddRange(
SerialService.DispositivosMapeados
.GroupBy(x => x.Dispositivo)
.Select(x => new ListViewItem()
{
Text =
x.FirstOrDefault().Endereco + " - " + Enum.GetName(typeof(T_Code), x.Key) + " v" + x.FirstOrDefault().Versao +
(SerialService.DispositivosMultiplos.Contains(x.FirstOrDefault().Dispositivo) ? (" (" + string.Join(", ", x.Where(y => y.Conectado).Select(y => y.Mod_ID)) + ")") :
"") + " - " +
(x.Any(y => y.Conectado) ? "Conectado" : "Desconectado")
}).ToArray()
);
if (SerialService.DispositivosMapeados.Count == 0)
{
Variaveis.DispositivosConectados.Where(x => x.Dados.GetStatusConexao()).ToList().ForEach(x => x.AcaoDesconectar());
}
Variaveis.DispositivosConectados.ForEach(x =>
{
x.AcaoConexao();
});
lblStripMqtt.Text = "MQTT: " + (Variaveis.MqttService.StatusConexao() ? "Conectado" : "Desconectado");
bool opLiberada = Variaveis.OperacaoEmAndamento.OperacaoLiberada;
lblStripOperacaoLiberada.Text = "Operação Liberada: " + (opLiberada ? "Sim" : "Não");
lblStripOperacaoLiberada.ForeColor = opLiberada ? Color.Green : Color.Red;
if (chbConexaoautomatica.Checked)
{
await FuncoesGlobais.SafeExecuteAsync(() => SerialService.RealizarVarreduraPortasUSB());
AtualizaDadosGerais();
}
}
public void AtualizaDadosGerais()
{
tkbVelocidade.Minimum = 0;
tkbVelocidade.Maximum = 100;
FuncoesGlobais.PreencheValorTrackBar(tkbVelocidade, Variaveis.OperacaoEmAndamento.Controle.VelocidadeMP);
tkbAngulo.Minimum = 0;
tkbAngulo.Maximum = 90;
FuncoesGlobais.PreencheValorTrackBar(tkbAngulo, Variaveis.OperacaoEmAndamento.Controle.Angulo);
trkKmh.Minimum = 0;
trkKmh.Maximum = 100;
trkRPM.Minimum = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
trkRPM.Maximum = VariaveisEquipamento.RPM_Max_Roda;
FuncoesGlobais.PreencheValorTrackBar(trkRPM, Variaveis.OperacaoEmAndamento.Controle.RPM_SP);
int percentual = Convert.ToInt32((trkRPM.Value / (double)VariaveisEquipamento.RPM_Max_Roda) * 100.0);
AtualizaRPM(percentual);
}
#endregion
#region VERSIONAMENTO DE ARQUIVOS
private void btnForcarAtualizacao_Click(object sender, EventArgs e)
{
VersionamentoService.ForcarDownloadArquivos = true;
VersionamentoService.AtualizarArquivoVersionamento(true).ConfigureAwait(false);
tmrAtualizacaoArquivos.SetInterval(300);
tmrAtualizacaoArquivos.Restart();
}
private async Task tmrAtualizacaoArquivos_Tick()
{
lblProgressoAtualizacao.Text = VersionamentoService.AtualizandoArquivos ? $"({VersionamentoService.ProgressoAtualizacao.ToString("0.00")}%) Atualizando arquivos..." : VersionamentoService.ResultadoAtualizacao;
pgbAtualizacaoArquivos.Value = (int)VersionamentoService.ProgressoAtualizacao;
tmrAtualizacaoArquivos.SetInterval(VersionamentoService.AtualizandoArquivos ? 300 : 5000);
}
#endregion
@ -332,7 +300,8 @@ namespace AgroBase
private void btnAcompanhamento_Click(object sender, EventArgs e)
{
frmInstancial.frmAcompanhamento.Show();
frmAcompanhamento frm = new frmAcompanhamento();
frm.Show();
}
private void btnCamera_Click(object sender, EventArgs e)

View File

@ -4,6 +4,7 @@ using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
@ -11,8 +12,7 @@ namespace AgroBase.Forms
{
public partial class frmSimulacaoMapaGPS : Form
{
Timer tmrSonar;
Timer tmrLeitura = new Timer() { Interval = 500 };
AsyncTaskTimerModel tmrLeitura;
StatusCarroMapa StatusCarro = StatusCarroMapa.Parado;
MapaDinamicoModel MapaDinamico;
bool calc = false;
@ -23,9 +23,6 @@ namespace AgroBase.Forms
{
InitializeComponent();
tmrLeitura.Tick += Tmr_Tick;
tmrLeitura.Start();
// Ativa o double buffering
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
@ -35,11 +32,30 @@ namespace AgroBase.Forms
MapaDinamico = new MapaDinamicoModel(this, pnlZoomMapa);
}
private void Tmr_Tick(object sender, EventArgs e)
private void frmSimulacaoMapaGPS_Load(object sender, EventArgs e)
{
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 500, this);
tmrLeitura.Start();
Variaveis.OperacaoEmAndamento.Mapa = new MapasModel()
{
pnlMapa = pnlMapa,
};
//Variaveis.OperacaoEmAndamento.Sensoriamento.SonarFrontal = new SonarModel(picSonar);
KinectService.InicializarKinect(null, picSonar, null, null);
}
private void frmSimulacaoMapaGPS_FormClosing(object sender, FormClosingEventArgs e)
{
tmrLeitura.Stop();
Variaveis.OperacaoEmAndamento.Iniciado = false;
}
private async Task tmrLeitura_Tick()
{
if (chbAutomatico.Checked)
{
btnAcrescentarGPS_Click(sender, e);
btnAcrescentarGPS_Click(btnAcrescentarGPS, new EventArgs());
}
}
@ -95,28 +111,7 @@ namespace AgroBase.Forms
}
private void frmSimulacaoMapaGPS_Load(object sender, EventArgs e)
{
Variaveis.OperacaoEmAndamento.Mapa = new MapasModel()
{
pnlMapa = pnlMapa,
};
//Variaveis.OperacaoEmAndamento.Sensoriamento.SonarFrontal = new SonarModel(picSonar);
KinectService.InicializarKinect(null, picSonar, null, null);
}
private void frmSimulacaoMapaGPS_FormClosing(object sender, FormClosingEventArgs e)
{
if (tmrSonar != null && tmrSonar.Enabled)
{
tmrSonar.Stop();
}
if (tmrLeitura != null && tmrLeitura.Enabled)
{
tmrLeitura.Stop();
}
Variaveis.OperacaoEmAndamento.Iniciado = false;
}
private void btnCarregar_Click(object sender, EventArgs e)
{

View File

@ -4,6 +4,7 @@ using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Threading.Tasks;
namespace AgroBase.Forms
{
@ -14,7 +15,7 @@ namespace AgroBase.Forms
double AnguloY = 0;
double AnguloZ = 0;
private Visualizador3DService visualizador3D;
Timer tmrLeitura;
AsyncTaskTimerModel tmrLeitura;
//WT901C485 WT901C = Variaveis.WT901C;
public frmWT901C()
@ -42,29 +43,24 @@ namespace AgroBase.Forms
private void frmWT901C_Load(object sender, EventArgs e)
{
PopularDadosGrid();
tmrLeitura = new Timer() { Interval = 200 };
tmrLeitura.Tick += tmrLeitura_Tick;
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 500, this);
tmrLeitura.Start();
}
private void frmWT901C_FormClosing(object sender, FormClosingEventArgs e)
{
tmrLeitura.Stop();
tmrLeitura.Dispose();
}
private void tmrLeitura_Tick(object sender, EventArgs e)
private async Task tmrLeitura_Tick()
{
((Timer)sender).Stop();
AnguloX = Variaveis.OperacaoEmAndamento.Sensoriamento.InclinacaoX;
AnguloY = Variaveis.OperacaoEmAndamento.Sensoriamento.InclinacaoY;
AnguloZ = Variaveis.OperacaoEmAndamento.Sensoriamento.InclinacaoZ;
OrientacaoMagnetica = Variaveis.OperacaoEmAndamento.Sensoriamento.AnguloCarroBussola;
AtualizarDadosTela();
((Timer)sender).Start();
}
private void PopularDadosGrid()

View File

@ -0,0 +1,134 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AgroBase.Models
{
public class AsyncTaskTimerModel
{
private CancellationTokenSource _cancellationTokenSource;
private Func<Task> _taskToExecute;
private int _interval; // Intervalo em milissegundos
public int Interval { get { return _interval; } }
private Control _uiControl;
/// <summary>
/// Inicializa uma nova instância do AsyncTaskTimerService.
/// </summary>
/// <param name="taskToExecute">A tarefa assíncrona que será executada periodicamente.</param>
/// <param name="interval">Intervalo em milissegundos entre as execuções.</param>
/// <param name="uiControl">Controle para executar tarefas relacionadas à UI. Opcional.</param>
public AsyncTaskTimerModel(Func<Task> taskToExecute, int interval, Control uiControl = null)
{
if (taskToExecute == null) throw new ArgumentNullException(nameof(taskToExecute));
if (interval <= 0) throw new ArgumentException("Interval must be greater than zero.", nameof(interval));
_taskToExecute = taskToExecute;
_interval = interval;
_uiControl = uiControl;
}
/// <summary>
/// Inicia o timer assíncrono.
/// </summary>
public void Start()
{
if (_cancellationTokenSource != null) return;
_cancellationTokenSource = new CancellationTokenSource();
Task.Run(() => TimerLoopAsync(_cancellationTokenSource.Token));
}
/// <summary>
/// Para o timer assíncrono.
/// </summary>
public void Stop()
{
if (_cancellationTokenSource == null) return;
_cancellationTokenSource.Cancel();
_cancellationTokenSource = null;
}
/// <summary>
/// Reinicia o timer assíncrono.
/// </summary>
public void Restart()
{
Stop();
Start();
}
/// <summary>
/// Alterna o status do timer.
/// </summary>
public void Toogle()
{
if (IsRunning)
{
Stop();
}
else
{
Start();
}
}
/// <summary>
/// Define o intervalo entre as execuções.
/// </summary>
/// <param name="interval">Novo intervalo em milissegundos.</param>
public void SetInterval(int interval)
{
if (interval <= 0) throw new ArgumentException("Interval must be greater than zero.", nameof(interval));
_interval = interval;
}
/// <summary>
/// Verifica se o timer está em execução.
/// </summary>
public bool IsRunning => _cancellationTokenSource != null;
/// <summary>
/// Loop interno do timer.
/// </summary>
private async Task TimerLoopAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
try
{
if (_uiControl != null)
{
// Se um controle de UI foi especificado, use-o para executar tarefas relacionadas à UI
await FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThreadAsync(_uiControl, _taskToExecute);
}
else
{
// Caso contrário, execute a tarefa diretamente
await _taskToExecute();
}
// Aguarda o intervalo antes da próxima execução
await Task.Delay(_interval, cancellationToken);
}
catch (OperationCanceledException)
{
// Cancelamento solicitado
break;
}
catch (Exception ex)
{
// Tratar erros inesperados
Console.WriteLine($"Erro no timer: {ex.Message}");
}
}
Console.WriteLine("Timer encerrado.");
}
}
}

View File

@ -1,9 +1,4 @@
using AgroBase.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using static AgroBase.Models.Enums;
namespace AgroBase.Models

View File

@ -53,9 +53,13 @@ namespace AgroBase
//public static double Angulo { get; set; } = 20;
//public static int Velocidade { get; set; } = 50;
public static Timer tmrJoystick = new Timer() { Interval = 100, Enabled = false };
public static AsyncTaskTimerModel tmrJoystick;
public static void IniciarRotinas()
{
tmrJoystick = new AsyncTaskTimerModel(tmrJoystick_Tick, 100);
}
public static void AtualizaDispositivo()
{
Func<bool> funcAtt = new Func<bool>(() =>
@ -98,8 +102,7 @@ namespace AgroBase
if (joystickGuid == Guid.Empty)
{
JoystickConectado = null;
tmrJoystick.Enabled = false;
tmrJoystick.Tick -= TmrJoystick_Tick;
tmrJoystick.Stop();
return;
}
@ -123,8 +126,7 @@ namespace AgroBase
if (JoystickConectado != null)
{
tmrJoystick.Enabled = true;
tmrJoystick.Tick += TmrJoystick_Tick;
tmrJoystick.Start();
frmInstancial.frmPrincipal.cmbJoysticks.SelectedIndex = 0;
}
@ -168,7 +170,7 @@ namespace AgroBase
return mappedValue;
}
private static void TmrJoystick_Tick(object sendder, EventArgs e)
private static async Task tmrJoystick_Tick()
{
if (JoystickConectado == null)
{
@ -694,7 +696,7 @@ namespace AgroBase
var Sinaleiro = DispSen.Dados.Sinaleiros.FirstOrDefault(x => x.ID == ID);
if (Sinaleiro != null)
{
Sinaleiro.Comportamento = Status;
Sinaleiro.Comportamento = (SensorSinaleiroComportamentoModel)Status;
string ProtocoloSinaleiro = Sinaleiro.ProtocoloComando();
DispSen.AdicionarMensagemFila(DispSen.Dados.Modulo_ID, ProtocoloSinaleiro, true, false);
}
@ -712,7 +714,7 @@ namespace AgroBase
var ServoFreio = DispSen.Dados.Servos.FirstOrDefault(x => x.ID == ID);
if (ServoFreio != null)
{
ServoFreio._AnguloControle = VariaveisEquipamento.AnguloFreio[(AcaoFreio)Status];
ServoFreio._AnguloControle = (int)Status;
string ProtocoloFreio = ServoFreio.ProtocoloComando();
DispSen.AdicionarMensagemFila(DispSen.Dados.Modulo_ID, ProtocoloFreio, true, false);
}

View File

@ -1,13 +1,7 @@
using AgroBase.Services;
using Assimp;
using Emgu.CV;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using static AgroBase.Models.Enums;
namespace AgroBase.Models

View File

@ -4,6 +4,7 @@ using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
@ -514,6 +515,7 @@ namespace AgroBase.Models
}
private bool GerandoTrajetoria = false;
private DateTime UltimaAtualizacaoTrajetoriaDinamica = DateTime.MinValue;
private AsyncTaskTimerModel tmrCarregamento;
public void btnCarregar_Click(object sender, EventArgs e, string caminhoArquivo = "", bool monitoramento = false)
@ -535,9 +537,8 @@ namespace AgroBase.Models
picLoading.Visible = true;
pnlMapa.Controls.Add(picLoading);
Timer tmr = new Timer() { Interval = 500 };
tmr.Tick += Tmr_Tick;
tmr.Start();
tmrCarregamento = new AsyncTaskTimerModel(tmrCarregamento_Tick, 500);
tmrCarregamento.Start();
}
}
@ -554,16 +555,29 @@ namespace AgroBase.Models
pnlMapa.Controls.Add(picLoading);
}
mapaService.CarregarMapaGPS(MapasVariaveisModel.NomeArquivoMapaGPS);
Timer tmr = new Timer() { Interval = 500 };
tmr.Tick += Tmr_Tick;
tmr.Start();
tmrCarregamento = new AsyncTaskTimerModel(tmrCarregamento_Tick, 500, pnlMapa);
tmrCarregamento.Start();
}
private void Tmr_Tick(object sender, EventArgs e)
private async Task tmrCarregamento_Tick()
{
if (mapaService.pythonProcess.HasExited)
try
{
((Timer)sender).Stop();
lock (mapaService.pythonProcess)
{
if (mapaService.pythonProcess == null)
{
return;
}
if (mapaService.pythonProcess != null && !mapaService.pythonProcess.HasExited)
{
return;
}
}
// Processo finalizado ou não associado
picLoading.Visible = false;
mapaService.Carregado = true;
@ -579,6 +593,20 @@ namespace AgroBase.Models
}
IniciarProcessamento();
lock (mapaService.pythonProcess)
{
mapaService.pythonProcess.Dispose();
mapaService.pythonProcess = null;
}
tmrCarregamento.Stop();
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Erro ao verificar o estado do processo: {ex.Message}");
picLoading.Visible = false;
tmrCarregamento.Stop();
}
}

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static AgroBase.Models.Enums;
namespace AgroBase.Models

View File

@ -1,9 +1,4 @@
using OpenTK.Platform.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using static AgroBase.Models.Enums;
namespace AgroBase.Models

View File

@ -265,7 +265,7 @@ namespace AgroBase.Models.Modules
if (Variaveis.DispositivosConectados.Any(x => x.Dispositivo == T_Code.Dir))
{
//((frmDirPlot)(frmPrincipal.Dispositivos.First(x => x.Dispositivo == T_Code.Dir).frmPlot)).AtualizaGrafico();
frmInstancial.frmAcompanhamento.AtualizaGrafico();
//frmInstancial.frmAcompanhamento.tmrAtualizacao_Tick();
}
}

View File

@ -43,7 +43,7 @@ namespace AgroBase.Models
public double DistanciaPercorridaTotal { get; set; } = 0;
public double DistanciaPercorridaParcial { get; set; } = 0;
public double DistanciaPercorridaOperacao { get; set; } = 0;
public Timer tmrRegistrador { get; set; }
public AsyncTaskTimerModel tmrRegistrador { get; set; }
@ -258,7 +258,7 @@ namespace AgroBase.Models
}
frmInstancial.frmAcompanhamento.AtualizaGrafico();
//frmInstancial.frmAcompanhamento.tmrAtualizacao_Tick();
}
}
catch (Exception ex)
@ -296,16 +296,11 @@ namespace AgroBase.Models
public void IniciarRegistrador()
{
tmrRegistrador = new Timer()
{
Interval = 1000,
Enabled = false
};
tmrRegistrador.Tick += TmrRegistrador_Tick;
tmrRegistrador = new AsyncTaskTimerModel(tmrRegistrador_Tick, 1000);
tmrRegistrador.Start();
}
private void TmrRegistrador_Tick(object sender, EventArgs e)
private async Task tmrRegistrador_Tick()
{
if (UltimaDirecao != Direcao.Parado)
{

View File

@ -132,7 +132,7 @@ namespace AgroBase.Models.Modules
Dados.Modulos.ForEach(x =>
{
x.MovMotor.Alarme = false;
x.MovMotor.Freio = false;
x.MovMotor.ConfigFreio.Leitura = false;
x.MovMotor.Ligado = false;
x.MovMotor.LogGrafico = new List<MvdMotorMOVSensorimanetoGrafico>();
x.MovMotor.TemperaturaDriver = 0;
@ -215,7 +215,7 @@ namespace AgroBase.Models.Modules
int.TryParse(Dados[8], out sentido);
Modulo.MovMotor.Sentido = (Sentido)sentido;
bool freio = Dados[9] == "1";
Modulo.MovMotor.Freio = freio;
Modulo.MovMotor.ConfigFreio.Leitura = freio;
int codAlarme = 0;
int.TryParse(Dados[10], out codAlarme);
Modulo.MovMotor.CodigoAlarme = codAlarme;
@ -275,7 +275,7 @@ namespace AgroBase.Models.Modules
int.TryParse(Dados[8], out sentido);
Modulo.MovMotor.Sentido = (Sentido)sentido;
bool freio = Dados[9] == "1";
Modulo.MovMotor.Freio = freio;
Modulo.MovMotor.ConfigFreio.Leitura = freio;
int codAlarme = 0;
int.TryParse(Dados[10], out codAlarme);
Modulo.MovMotor.CodigoAlarme = codAlarme;
@ -343,8 +343,6 @@ namespace AgroBase.Models.Modules
{
Modulo.MovMotor.LogGrafico.RemoveAt(0);
}
frmInstancial.frmAcompanhamento.AtualizaGrafico();
}
public void DefineStatusConexao(string Mod_ID, bool conecatdo)
@ -483,7 +481,8 @@ namespace AgroBase.Models.Modules
}
}
}
public class ModuloMvdModel
@ -659,7 +658,7 @@ namespace AgroBase.Models.Modules
// SETs
public string Endereco { get; set; }
public bool Ligado { get; set; } = false;
public bool Freio { get; set; } = false;
//public bool Freio { get; set; } = false;
public int CodigoAlarme { get; set; } = 0;
public int RPM_SP { get; set; } = 0;
public int RPM_SP_Controle { get; set; } = 0;
@ -721,6 +720,8 @@ namespace AgroBase.Models.Modules
public List<MvdMotorMOVSensorimanetoGrafico> LogGrafico { get; set; } = new List<MvdMotorMOVSensorimanetoGrafico>();
public List<AlarmeModel> Alarmes { get; set; } = new List<AlarmeModel>();
public MvdServoFreioModel ConfigFreio { get; set; } = new MvdServoFreioModel();
public static MvdMotorBLDC CarregarParametrosIniciais(string Mod_ID, string _Endereco)
{
@ -736,6 +737,12 @@ namespace AgroBase.Models.Modules
FuncoesPinout.PWM,
FuncoesPinout.BRK,
},
ConfigFreio = new MvdServoFreioModel()
{
AnguloInicial = 10,
Incremental = Mod_ID.Contains("E"),
Leitura = false,
},
ConfigSentidos = new Dictionary<TipoMovimentoDirecional, ConfiguracaoSentidoMotor>()
{
{
@ -744,8 +751,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario,
Tras = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario
Frente = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario,
Tras = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario
}
},
{
@ -754,8 +761,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario,
Tras = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario
Frente = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario,
Tras = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario
}
},
{
@ -764,8 +771,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario,
Tras = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario
Frente = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario,
Tras = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario
}
},
{
@ -774,8 +781,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario,
Tras = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario
Frente = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario,
Tras = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario
}
},
{
@ -784,8 +791,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Sentido.Antihorario,
Tras = Sentido.Horario
Frente = Sentido.Horario,
Tras = Sentido.Antihorario
}
},
{
@ -794,8 +801,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Mod_ID.Contains("T") ? Sentido.Antihorario : Sentido.Horario,
Tras = Mod_ID.Contains("T") ? Sentido.Horario : Sentido.Antihorario
Frente = Mod_ID.Contains("T") ? Sentido.Horario : Sentido.Antihorario,
Tras = Mod_ID.Contains("T") ? Sentido.Antihorario : Sentido.Horario
}
},
{
@ -804,8 +811,8 @@ namespace AgroBase.Models.Modules
{
Direita = Sentido.Parado,
Esquerda = Sentido.Parado,
Frente = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario,
Tras = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario
Frente = Mod_ID.Contains("E") ? Sentido.Horario : Sentido.Antihorario,
Tras = Mod_ID.Contains("E") ? Sentido.Antihorario : Sentido.Horario
}
},
},
@ -840,7 +847,8 @@ namespace AgroBase.Models.Modules
{
string ProtocoloMotor = "";
AcaoFreio AcaoDoFreio = AcaoFreio.SemAcao;
bool Freado = DirecaoAtual == Direcao.EmFreio;
(bool AtuarServo, int AnguloFreio) = ConfigFreio.AtualizarDadosFreio(Freado, 0, -1, 5);
if (Comandar && ((!Alarme && CodigoAlarme == 0) || CmdAlarme))
{
@ -851,7 +859,7 @@ namespace AgroBase.Models.Modules
RPM_SP_Controle = Variaveis.OperacaoEmAndamento.Controle.RPM_Motor;
RPM_SP =
DirecaoAtual == Direcao.Parado || CmdAlarme ? 0 :
DirecaoAtual == Direcao.Parado || Freado || CmdAlarme ? 0 :
RPM_SP_Controle;
Ligado = RPM_SP > 0;
@ -866,8 +874,6 @@ namespace AgroBase.Models.Modules
break;
}
Freio = DirecaoAtual == Direcao.EmFreio;
if (BLD_Inicializado)
{
byte Addr = Convert.ToByte(Endereco.Replace("0x", ""), 16);
@ -898,19 +904,17 @@ namespace AgroBase.Models.Modules
TimeoutResposta = 500,
});
}
if (Leitura == null || Leitura.Freado != Freio)
if (Leitura == null || Leitura.Freado != ConfigFreio.Leitura)
{
BLD300RService.AdicionarComandoNaFila(new BLD300RService.BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Breaked"),
Valor = Freio ? 1 : 0,
Valor = Freado ? 1 : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 500,
});
AcaoDoFreio = Freio ? AcaoFreio.Ativar : AcaoFreio.Desativar;
}
if (Leitura == null || Leitura.Ativado != Ligado)
{
@ -932,17 +936,17 @@ namespace AgroBase.Models.Modules
ID + SerialService.SplitParams +
((int)Sentido_SP).ToString() + SerialService.SplitParams +
RPM_SP.ToString() + SerialService.SplitParams +
(Freio ? "1" : "0");
(Freado ? "1" : "0");
}
}
if (AcaoDoFreio != AcaoFreio.SemAcao)
if (AtuarServo)
{
string Mod_ID = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.MovMotor.Endereco == Endereco)?.Modulo_ID ?? "";
var ServoFreio = Variaveis.OperacaoEmAndamento.DispSen.Dados.Servos.FirstOrDefault(x => x.ID.Contains(Mod_ID) && x.Inicializado && x.Controlar);
if (ServoFreio != null)
{
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, ServoFreio.ID, AcaoDoFreio);
GeneralJoystick.EnviarComandoSensoriamento(S_Code.sFRO, ServoFreio.ID, AnguloFreio);
}
}
@ -1389,6 +1393,113 @@ namespace AgroBase.Models.Modules
public double Corrente { get; set; }
}
public class MvdServoFreioModel
{
public bool Incremental { get; set; }
public int AnguloInicial { get; set; }
private int AnguloControle { get; set; } = -1;
private int AnguloControleMin
{
get
{
if (Incremental)
{
return AnguloMin;
}
else
{
return AnguloMax;
}
}
}
private int AnguloControleMax { get; set; } = 20;
public bool Leitura { get; set; }
private bool _controle { get; set; }
public bool Controle
{
get
{
return _controle;
}
}
private int RPM_SP { get; set; }
private int MargemRPM { get; set; } = 2; // Margem de tolerância no RPM
private int AnguloMin { get; set; } = 0; // Ângulo mínimo permitido pelo servo
private int AnguloMax { get; set; } = 180; // Ângulo máximo permitido pelo servo
private int FatorEscala { get; set; } = 10; // Fator de ajuste do controle proporcional
public (bool, int) AtualizarDadosFreio(bool status, int rpm_sp = 0, int anguloInicial = -1, int anguloSP = -1)
{
bool mudou = _controle != status;
_controle = status;
RPM_SP = rpm_sp;
if (!_controle)
{
AnguloControle = AnguloControleMin; // Solta o freio se não estiver no modo de controle
return (mudou, AnguloControle);
}
if (anguloInicial == -1)
{
anguloInicial = AnguloInicial;
}
if (AnguloControle == -1)
{
AnguloControle = AnguloControleMin;
}
if (AnguloControle == AnguloControleMin)
{
AnguloControle = anguloInicial;
}
int ajuste = anguloSP;
if (anguloSP == -1)
{
double Rpm_Atual = MovimentacaoModel.CalculaRPMVelocidade(Variaveis.OperacaoEmAndamento.Sensoriamento.VelocidadeMedia);
// Garante que os valores de RPM sejam válidos
Rpm_Atual = Math.Max(Rpm_Atual, 0);
RPM_SP = Math.Max(RPM_SP, 0);
// Verifica se o RPM atual está dentro da margem de tolerância
if (Math.Abs(Rpm_Atual - RPM_SP) <= MargemRPM)
{
return (false, AnguloControle); // Se dentro da margem, não ajusta o ângulo
}
// Calcula o erro e ajusta proporcionalmente
int erroRPM = RPM_SP - (int)Rpm_Atual;
ajuste = erroRPM / FatorEscala;
// Se incremental, aplica um ajuste limitado
if (Incremental)
{
ajuste = Math.Abs(ajuste); // Garante que o ajuste seja positivo
}
else
{
ajuste = -Math.Abs(ajuste); // Garante que o ajuste seja negativo
}
}
// Atualiza o ângulo de controle, garantindo que fique dentro dos limites
int limiteMax = AnguloInicial + (Incremental ? AnguloControleMax : -AnguloControleMax);
if (Incremental)
{
AnguloControle = (int)FuncoesMatematicas.Clamp(AnguloControle + ajuste, AnguloMin, limiteMax);
}
else
{
AnguloControle = (int)FuncoesMatematicas.Clamp(AnguloControle - ajuste, limiteMax, AnguloMax);
}
return (true, AnguloControle);
}
}
}

View File

@ -638,11 +638,6 @@ namespace AgroBase.Models.Modules
vShunt,
};
if (Sensor.ID.Contains("AB"))
{
frmInstancial.frmAcompanhamento.AtualizarSensores(Sensor.ID.Replace("AB", "Barramento ") + ": " + vBarramento.ToString("0.00") + " V " + corrente.ToString("0.00") + " mA");
}
AtualizaGrafico = true;
break;
}
@ -668,7 +663,7 @@ namespace AgroBase.Models.Modules
if (Sensor.Descricao.ToLower().Contains("bateria"))
{
frmInstancial.frmAcompanhamento.AtualizarSensores("Tensão atual: " + realVoltage.ToString("0.00") + "V - Mín: " + Sensor.ValorMinimo.ToString("0.00") + "V - Máx: " + Sensor.ValorMaximo.ToString("0.00") + "V");
//frmInstancial.frmAcompanhamento.AtualizarSensores("Tensão atual: " + realVoltage.ToString("0.00") + "V - Mín: " + Sensor.ValorMinimo.ToString("0.00") + "V - Máx: " + Sensor.ValorMaximo.ToString("0.00") + "V");
//Variaveis.OperacaoEmAndamento.Sensoriamento.PorcentagemBateria = (realVoltage / Sensor.LimiteMaximo) * 100;
if (Variaveis.OperacaoEmAndamento.Sensoriamento.PorcentagemBateria < 0)
{
@ -691,7 +686,7 @@ namespace AgroBase.Models.Modules
if (Sensor.Descricao.ToLower().Contains("bateria"))
{
frmInstancial.frmAcompanhamento.AtualizarSensores(Tc.ToString("0.00") + " ºC");
//frmInstancial.frmAcompanhamento.AtualizarSensores(Tc.ToString("0.00") + " ºC");
}
AtualizaGrafico = true;
@ -1134,10 +1129,19 @@ namespace AgroBase.Models.Modules
EnderecoExpansor = Pinout.EnderecoExpansor,
Pinos = Pinout.Pinos.ToList(),
};
bool incremental = true;
var freio = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => ID.Contains(x.Modulo_ID));
if (freio != null)
{
incremental = freio.MovMotor.ConfigFreio.Incremental;
}
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
string Protocolo = ((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
(Conectar ? "1" : "0") + SerialService.SplitParams +
(incremental ? "1" : "0") + SerialService.SplitParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes);
return Protocolo;
}

View File

@ -1888,7 +1888,7 @@ namespace AgroBase.Models
Sentido = Modulo.MovMotor.Sentido,
Velocidade = Modulo.MovMotor.VelocidadeInstantanea,
CodAlarme = Modulo.MovMotor.CodigoAlarme,
EmFreio = Modulo.MovMotor.Freio,
EmFreio = Modulo.MovMotor.ConfigFreio.Leitura,
Ativado = Modulo.MovMotor.Ligado,
};
SalvarLog(T_Code.Mov.ToString(), logMov, false);

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AgroBase.Models
{

View File

@ -13,6 +13,7 @@ using Microsoft.Win32;
using System.Reflection;
using CefSharp.WinForms;
using System.IO;
using System.Threading;
namespace AgroBase.Models
{
@ -738,24 +739,34 @@ namespace AgroBase.Models
}
public static T ExecutarMetodoComVerificacaoCrossThread<T>(Control controle, Func<T> acao)
public static async Task ExecutarMetodoComVerificacaoCrossThreadAsync(Control controle, Func<Task> acao)
{
T res = default(T);
if (controle != null && controle.InvokeRequired)
if (controle.InvokeRequired)
{
controle.Invoke((MethodInvoker)delegate
{
res = acao();
});
await (Task)controle.Invoke(new Func<Task>(() => acao()));
}
else
{
res = acao();
await acao();
}
return res;
}
public static T ExecutarMetodoComVerificacaoCrossThread<T>(Control controle, Func<T> acao)
{
if (controle == null)
throw new ArgumentNullException(nameof(controle));
if (controle.InvokeRequired)
{
return (T)controle.Invoke(new Func<T>(() => acao()));
}
else
{
return acao();
}
}
public static string MontarStringPerformance(float? gpuLoad, float? cpuLoad, float? ramUsage, float? cpuTemp, float? gpuTemp)
{
@ -766,6 +777,26 @@ namespace AgroBase.Models
$"Temp GPU: {gpuTemp?.ToString("0.0") ?? "N/A"}°C";
}
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
public static async Task SafeExecuteAsync(Func<Task> action)
{
await semaphore.WaitAsync();
try
{
await action();
}
finally
{
semaphore.Release();
}
}
}
public static class FuncoesMatematicas

View File

@ -109,7 +109,7 @@ namespace AgroBase.Services
Chave = "Enabled",
Descricao = "Verifica/Define o status do motor",
Escala = 1,
LeituraLoop = false,
LeituraLoop = true,
LeituraGeral = true,
N_Registros = 0x0001,
Registro = 0x0066
@ -119,7 +119,7 @@ namespace AgroBase.Services
Chave = "Breaked",
Descricao = "Verifica/Define o status do freio do motor",
Escala = 1,
LeituraLoop = false,
LeituraLoop = true,
LeituraGeral = true,
N_Registros = 0x0001,
Registro = 0x006A
@ -129,7 +129,7 @@ namespace AgroBase.Services
Chave = "Direction",
Descricao = "Verifica/Define o sentido de giro do motor",
Escala = 1,
LeituraLoop = false,
LeituraLoop = true,
LeituraGeral = true,
N_Registros = 0x0001,
Registro = 0x006D
@ -182,24 +182,18 @@ namespace AgroBase.Services
private static readonly object FilaLock = new object();
private static System.Timers.Timer tmrLoopComandos = new System.Timers.Timer() { Interval = 100, Enabled = false };
private static System.Timers.Timer tmrReceberDados = new System.Timers.Timer() { Interval = TaxaAmostragem, Enabled = false };
private static AsyncTaskTimerModel tmrLoopComandos;
private static AsyncTaskTimerModel tmrReceberDados;
private static bool EnvioLiberado { get; set; } = true;
public static void IniciarRotinas()
{
//Task.Run(() => LoopEnvioComandos()); // Inicia o loop de comandos em segundo plano
//Task.Run(() => ReceberDados()); // Inicia a recepção de dados em segundo plano
if (!tmrReceberDados.Enabled)
{
tmrReceberDados.Elapsed += TmrReceberDados_Elapsed; ;
tmrReceberDados.Start();
}
if (!tmrLoopComandos.Enabled)
{
tmrLoopComandos.Elapsed += TmrLoopComandos_Elapsed;
tmrLoopComandos.Start();
}
tmrLoopComandos = new AsyncTaskTimerModel(tmrLoopComandos_Tick, 100);
tmrLoopComandos.Start();
tmrReceberDados = new AsyncTaskTimerModel(tmrReceberDados_Tick, TaxaAmostragem);
tmrReceberDados.Start();
}
// Inicializa o serviço Ethernet com IP e porta específicos
@ -319,7 +313,7 @@ namespace AgroBase.Services
// Recebe a resposta via Ethernet, independentemente de precisar processá-la ou não
byte[] resposta = await _ethernetService.ReceiveDataAsync(7, Comando.TimeoutResposta); // Timeout ajustável, aqui 1 segundo
SerialService.MostrarComandoResposta(T_Code.Bld, comando, resposta);
//SerialService.MostrarComandoResposta(T_Code.Bld, comando, resposta);
if (Comando.AguardaResposta)
{
@ -377,6 +371,67 @@ namespace AgroBase.Services
}
}
private static void ConfigurarDriver(byte Addr)
{
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Convert.ToByte(x.MovMotor.Endereco.Replace("0x", ""), 16) == Addr);
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "ControleRS485"),
Valor = 1
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "AlarmeCode"),
Valor = 0
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "NumPolos"),
Valor = Modulo.MovMotor.NumeroPolos
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "RPM_Max"),
Valor = (int)Variaveis.OperacaoEmAndamento.DispMvd.Dados.RPM_Max_MotorBLDC
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "Rampa"),
Valor = Modulo.MovMotor.Rampa
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "Enabled"),
Valor = 0
});
DadosLeitura.Where(x => x.Endereco == Addr).First().Configurado = true;
}
private static bool DecifrarResposta(byte[] resposta, ModbusParametrosModel Parametro, byte Addr)
{
try
@ -480,23 +535,8 @@ namespace AgroBase.Services
}
}
private static async void TmrLoopComandos_Elapsed(object sender, EventArgs e)
private static async Task tmrReceberDados_Tick()
{
((System.Timers.Timer)sender).Stop();
if (EnvioLiberado)
{
await LoopEnvioComandos();
}
((System.Timers.Timer)sender).Start();
}
private static void TmrReceberDados_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
((System.Timers.Timer)sender).Stop();
if (!Iniciado && SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Bld))
{
foreach (var Leitura in DadosLeitura.Where(x => x.UltimoComandoRecebido.AddSeconds(10) < DateTime.Now))
@ -512,7 +552,7 @@ namespace AgroBase.Services
TaxaAmostragem = 3000;
((System.Timers.Timer)sender).Start();
tmrReceberDados.SetInterval(TaxaAmostragem);
return;
}
@ -540,7 +580,7 @@ namespace AgroBase.Services
Modulo.MovMotor.Corrente_Max = Math.Round(Leitura.CorrenteMax, 2);
Modulo.MovMotor.Tensao = Math.Round(Leitura.Tensao, 2);
Modulo.MovMotor.Ligado = Leitura.Ativado;
Modulo.MovMotor.Freio = Leitura.Freado;
Modulo.MovMotor.ConfigFreio.Leitura = Leitura.Freado;
Modulo.MovMotor.Sentido = Leitura.Direcao;
Modulo.MovMotor.CodigoAlarme = Leitura.CodigoAlarme;
@ -565,84 +605,16 @@ namespace AgroBase.Services
Modulo.MovMotor.ProtocoloComando(Controle.UltimaDirecao);
}
}
((System.Timers.Timer)sender).Start();
}
private static void ConfigurarDriver(byte Addr)
private static async Task tmrLoopComandos_Tick()
{
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Convert.ToByte(x.MovMotor.Endereco.Replace("0x", ""), 16) == Addr);
AdicionarComandoNaFila(new BLDComandoModel()
if (!EnvioLiberado)
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "ControleRS485"),
Valor = 1
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "AlarmeCode"),
Valor = 0
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "NumPolos"),
Valor = Modulo.MovMotor.NumeroPolos
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "RPM_Max"),
Valor = (int)Variaveis.OperacaoEmAndamento.DispMvd.Dados.RPM_Max_MotorBLDC
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "Rampa"),
Valor = Modulo.MovMotor.Rampa
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "Enabled"),
Valor = 0
});
DadosLeitura.Where(x => x.Endereco == Addr).First().Configurado = true;
}
public static void AdicionarComandoNaFila(BLDComandoModel Comando)
{
lock (FilaLock)
{
if (!FilaComandos.Any(x => x.Endereco == Comando.Endereco && x.Parametro.Registro == Comando.Parametro.Registro && x.Get == Comando.Get && !x.Enviado))
{
FilaComandos.Add(Comando);
}
return;
}
}
private static async Task LoopEnvioComandos()
{
EnvioLiberado = false;
// Verifica se a conexão foi perdida e tenta reconectar
@ -682,6 +654,17 @@ namespace AgroBase.Services
}
}
public static void AdicionarComandoNaFila(BLDComandoModel Comando)
{
lock (FilaLock)
{
if (!FilaComandos.Any(x => x.Endereco == Comando.Endereco && x.Parametro.Registro == Comando.Parametro.Registro && x.Get == Comando.Get && !x.Enviado))
{
FilaComandos.Add(Comando);
}
}
}
private static async Task ProcessarFilaPrioridade()
{
var FilaPrioridade = new List<BLDComandoModel>();

View File

@ -48,7 +48,7 @@ namespace AgroBase.Comum
public Form frmPin { get; set; }
public Timer tmrLimpeza = new Timer() { Interval = 10000, Enabled = false };
public AsyncTaskTimerModel tmrLimpeza;
public int Ticks { get; set; } = 0;
public int TempoConectado { get; set; } = 0;
@ -212,7 +212,7 @@ namespace AgroBase.Comum
throw new Exception("A porta " + _Porta.PortName + " não está aberta");
}
AtualizarConsole("> " + DateTime.Now.ToString("HH:mm:ss:fff") + " - " + Dados);
AtualizarConsole("> " + DateTime.Now.ToString("HH:mm:ss:fff") + " - " + Dados).ConfigureAwait(false);
try
{
@ -473,13 +473,7 @@ namespace AgroBase.Comum
Size = new System.Drawing.Size() { Height = 141, Width = 300 },
ReadOnly = true
};
tmrLimpeza = new Timer()
{
Interval = 1000,
Enabled = false
};
tmrLimpeza.Tick -= TmrLimpeza_Tick;
tmrLimpeza.Tick += TmrLimpeza_Tick;
tmrLimpeza = new AsyncTaskTimerModel(tmrLimpeza_Tick, 1000);
Button btnConfig = new Button()
{
@ -559,7 +553,7 @@ namespace AgroBase.Comum
}
}
private void TmrLimpeza_Tick(object sender, EventArgs e)
private async Task tmrLimpeza_Tick()
{
if (Ticks % 5 == 0)
{
@ -822,7 +816,7 @@ namespace AgroBase.Comum
});
}
AtualizarConsole("< " + DateTime.Now.ToString("HH:mm:ss:fff") + " - " + Recebido);
AtualizarConsole("< " + DateTime.Now.ToString("HH:mm:ss:fff") + " - " + Recebido).ConfigureAwait(false);
if (mensagem != "" && mensagem[0].ToString() == SerialService.BeginSensor && !EqualityComparer<T>.Default.Equals(Dados, default(T)))
{
@ -903,7 +897,7 @@ namespace AgroBase.Comum
txtEnvios.Text = "";
btnConectar.Text = "Conectar";
tmrLimpeza.Enabled = false;
tmrLimpeza.Stop();
SalvarLog();
}
@ -928,7 +922,7 @@ namespace AgroBase.Comum
txtEnvios.ReadOnly = false;
txtEnvios.Text = "";
btnConectar.Text = "Desconectar";
tmrLimpeza.Enabled = true;
tmrLimpeza.Start();
}
}
@ -938,21 +932,21 @@ namespace AgroBase.Comum
}
delegate void AtualizarConsoleDelegate(string Texto);
private void AtualizarConsole(string Texto)
private async Task AtualizarConsole(string texto)
{
Texto += Environment.NewLine;
texto += Environment.NewLine;
if (txaConsole.InvokeRequired)
{
txaConsole.Invoke(new AtualizarConsoleDelegate(AtualizarConsole), Texto);
await Task.Run(() => txaConsole.Invoke(new Action(() => txaConsole.Text += texto)));
}
else
{
txaConsole.Text += Texto;
txaConsole.Text += texto;
}
}
private T CarregarParametros(dynamic empty)
{
//string nomeArquivo = Variaveis.CaminhoParametros + "parameters" + Enum.GetName(typeof(T_Code), Dispositivo) + ".par";

View File

@ -176,7 +176,7 @@ public class EthernetService
{
await _networkStream.ReadAsync(tempBuffer, 0, tempBuffer.Length);
}
Console.WriteLine("Buffer limpo.");
//Console.WriteLine("Buffer limpo.");
}
}
catch (Exception ex)

View File

@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
namespace AgroBase.Services
@ -13,6 +12,7 @@ namespace AgroBase.Services
private static List<MensagemFilaModel> MensagensFila;
private static readonly object _lock = new object();
private static int _counter = 1;
private static AsyncTaskTimerModel tmrFila;
public static bool Liberado
{
@ -28,7 +28,8 @@ namespace AgroBase.Services
public static void Inicializar()
{
MensagensFila = new List<MensagemFilaModel>();
EnviarMensagensLoop().ConfigureAwait(false);
tmrFila = new AsyncTaskTimerModel(tmrFila_Tick, 10);
tmrFila.Start();
}
public static void AdicionarMensagemFila(string Modulo_ID, T_Code Dispositivo, string Mensagem, bool _prioridade, bool _aguardaCallback)
@ -139,50 +140,45 @@ namespace AgroBase.Services
}
}
public static async Task EnviarMensagensLoop()
public static async Task tmrFila_Tick()
{
while (true)
{
RemoverDuplicatas();
RemoverDuplicatas();
lock (_lock)
lock (_lock)
{
var Filas = MensagensFila.Where(x => !x.Enviado).GroupBy(x => x.Dispositivo);
foreach (var Fila in Filas)
{
var Filas = MensagensFila.Where(x => !x.Enviado).GroupBy(x => x.Dispositivo);
foreach (var Fila in Filas)
var Dispositivo = Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == Fila.Key);
if (!Dispositivo._Porta.IsOpen)
{
var Dispositivo = Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == Fila.Key);
if (!Dispositivo._Porta.IsOpen)
lock (_lock)
{
lock (_lock)
{
MensagensFila.RemoveAll(x => x.Dispositivo == Fila.Key);
}
continue;
MensagensFila.RemoveAll(x => x.Dispositivo == Fila.Key);
}
continue;
}
if (FilaLiberada(Fila.Key))
{
MensagemFilaModel Mensagem = null;
lock (_lock)
{
Mensagem = MensagensFila.Where(x => x.Dispositivo == Fila.Key).OrderByDescending(x => x.Prioridade).ThenBy(x => x.AdicionadoEm).FirstOrDefault(x => !x.Enviado);
}
if (FilaLiberada(Fila.Key))
if (Mensagem != null)
{
MensagemFilaModel Mensagem = null;
lock (_lock)
if (RealizarEnvio(Mensagem))
{
Mensagem = MensagensFila.Where(x => x.Dispositivo == Fila.Key).OrderByDescending(x => x.Prioridade).ThenBy(x => x.AdicionadoEm).FirstOrDefault(x => !x.Enviado);
}
if (Mensagem != null)
{
if (RealizarEnvio(Mensagem))
{
MarcarMensagemEnviada(Mensagem.Id);
}
MarcarMensagemEnviada(Mensagem.Id);
}
}
}
}
VerificarMensagensSemResposta();
await Task.Delay(10);
}
VerificarMensagensSemResposta();
}
private static void RemoverDuplicatas()

View File

@ -593,8 +593,6 @@ namespace AgroBase.Services
DefinirAnguloCarroGPS();
frmInstancial.frmAcompanhamento.AtualizarOrientacao();
int ID = Convert.ToInt32(Variaveis.ConexaoLoRa.parametros.address);
double angulo = ((Variaveis.OperacaoEmAndamento.Sensoriamento?.AnguloCarro ?? 0) - 180);
EnviarCoordenadasParaMapa(UltimaLeitura.Latitude, UltimaLeitura.Longitude, angulo, Variaveis.OperacaoEmAndamento.Iniciado, ID);

View File

@ -49,7 +49,7 @@ namespace AgroBase.Services
public static Bitmap bitmapRGB;
public static Bitmap bitmapHeat;
public static Bitmap bitmapMap;
private static System.Timers.Timer tmrLeitura;
private static AsyncTaskTimerModel tmrLeitura;
private static DataGridView gridDados;
public static PictureBox picRGB;
public static PictureBox picProfundidade;
@ -72,12 +72,8 @@ namespace AgroBase.Services
public static void InicializarRotinas()
{
if (tmrLeitura == null || !tmrLeitura.Enabled)
{
tmrLeitura = new System.Timers.Timer() { Interval = 200 };
tmrLeitura.Elapsed += TmrLeitura_Elapsed;
tmrLeitura.Start();
}
tmrLeitura = new AsyncTaskTimerModel(tmrLeitura_Tick, 200);
tmrLeitura.Start();
}
public static bool InicializarKinect(DataGridView dg = null, PictureBox pcRgb = null, PictureBox pcPf = null, TrackBar tkAng = null)
@ -307,19 +303,15 @@ namespace AgroBase.Services
}
}
private static void TmrLeitura_Elapsed(object sender, EventArgs e)
private static async Task tmrLeitura_Tick()
{
((System.Timers.Timer)sender).Stop();
tmrLeitura.SetInterval(Iniciado ? 200 : 1000);
if (!Iniciado)
{
((System.Timers.Timer)sender).Interval = 1000;
((System.Timers.Timer)sender).Start();
return;
}
((System.Timers.Timer)sender).Interval = 200;
Leitura.Obstaculos = IdentificarObstaculos();
Leitura.AtualizarUltimoStatusDeteccao();
@ -342,8 +334,6 @@ namespace AgroBase.Services
{
GeneralJoystick.EnviaComandoMotor(Keys.Escape, T_Code.Mov);
}
((System.Timers.Timer)sender).Start();
}
private static void KinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)

View File

@ -123,8 +123,9 @@ namespace AgroBase.Services
public static readonly object _dadosOperacaoLock = new object();
public static List<LoRaProtocoloTransmissaoModel> LeituraDadosOperacao = new List<LoRaProtocoloTransmissaoModel>();
private static AsyncTaskTimerModel tmrEnvio;
private static bool RotinaEnvioIniciada = false;
private static AsyncTaskTimerModel tmrPing;
private static bool RotinaPingsIniciada = false;
@ -200,11 +201,15 @@ namespace AgroBase.Services
if (!RotinaEnvioIniciada)
{
LoopEnvioBuffer().ConfigureAwait(false);
RotinaEnvioIniciada = true;
tmrEnvio = new AsyncTaskTimerModel(tmrEnvio_Tick, 500);
tmrEnvio.Start();
}
if (!RotinaPingsIniciada && !Variaveis.IsAgroMonitor)
{
EnviarPingComunicacao().ConfigureAwait(false);
RotinaPingsIniciada = true;
tmrPing = new AsyncTaskTimerModel(tmrPing_Tick, VariaveisEquipamento.TempoEntrePingsConexao);
tmrEnvio.Start();
}
}
}
@ -679,27 +684,21 @@ namespace AgroBase.Services
}
private static async Task LoopEnvioBuffer()
private static async Task tmrEnvio_Tick()
{
RotinaEnvioIniciada = true;
while (true)
var mensagens = bufferEnvio.ToList();
foreach (var buffer in mensagens)
{
var mensagens = bufferEnvio.ToList();
foreach (var buffer in mensagens)
{
EnviarComando(_PortaLoRa, buffer);
await Task.Delay(1500);
}
mensagens.ForEach(x => bufferEnvio.Remove(x));
EnviarComando(_PortaLoRa, buffer);
await Task.Delay(1500);
}
mensagens.ForEach(x => bufferEnvio.Remove(x));
var mensagensAntigas = bufferRecebido.Where(x => x.Key.AddSeconds(10) <= DateTime.Now).ToList();
foreach (var item in mensagensAntigas)
{
bufferRecebido.Remove(item.Key);
}
await Task.Delay(500);
var mensagensAntigas = bufferRecebido.Where(x => x.Key.AddSeconds(10) <= DateTime.Now).ToList();
foreach (var item in mensagensAntigas)
{
bufferRecebido.Remove(item.Key);
}
}
@ -745,19 +744,12 @@ namespace AgroBase.Services
}
public static async Task EnviarPingComunicacao()
public static async Task tmrPing_Tick()
{
RotinaPingsIniciada = true;
while (true)
if (!Variaveis.OperacaoEmAndamento.Iniciado)
{
await Task.Delay(VariaveisEquipamento.TempoEntrePingsConexao);
if (!Variaveis.OperacaoEmAndamento.Iniciado)
{
Console.WriteLine("Enviando ping de comunicação para a base...");
EnviarDadosParaBase();
}
Console.WriteLine("Enviando ping de comunicação para a base...");
EnviarDadosParaBase();
}
}

View File

@ -21,8 +21,8 @@ namespace AgroBase.Services
}
}
public static int TaxaAmostragem { get; set; } = 1000;
private static System.Timers.Timer tmrLoopComandos = new System.Timers.Timer() { Interval = 100, Enabled = false };
private static System.Timers.Timer tmrReceberDados = new System.Timers.Timer() { Interval = TaxaAmostragem, Enabled = false };
private static AsyncTaskTimerModel tmrLoopComandos;
private static AsyncTaskTimerModel tmrReceberDados;
private static List<MKS057ComandoModel> FilaComandos = new List<MKS057ComandoModel>();
private static readonly object FilaLock = new object();
private static bool EnvioLiberado { get; set; } = true;
@ -42,18 +42,8 @@ namespace AgroBase.Services
public static void IniciarRotinas()
{
//Task.Run(() => LoopEnvioComandos()); // Inicia o loop de comandos em segundo plano
//Task.Run(() => ReceberDados()); // Inicia a recepção de dados em segundo plano
if (!tmrReceberDados.Enabled)
{
tmrReceberDados.Elapsed += TmrReceberDados_Elapsed;
tmrReceberDados.Start();
}
if (!tmrLoopComandos.Enabled)
{
tmrLoopComandos.Elapsed += TmrLoopComandos_Elapsed;
tmrLoopComandos.Start();
}
tmrLoopComandos = new AsyncTaskTimerModel(tmrLoopComandos_Tick, 100);
tmrReceberDados = new AsyncTaskTimerModel(tmrReceberDados_Tick, TaxaAmostragem);
}
// Inicializa o serviço Ethernet com IP e porta específicos
@ -183,13 +173,16 @@ namespace AgroBase.Services
}
}
}
private static void TmrReceberDados_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
private static bool EnderecoValido(byte addr)
{
((System.Timers.Timer)sender).Stop();
return Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => Convert.ToByte(x.DirMotor.Endereco.Replace("0x", ""), 16) == addr);
}
private static async Task tmrReceberDados_Tick()
{
if (!Iniciado && SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks))
{
foreach (var Leitura in DadosLeitura.Where(x => x.UltimoComandoRecebido.AddSeconds(10) < DateTime.Now))
@ -198,8 +191,6 @@ namespace AgroBase.Services
}
TaxaAmostragem = 3000;
((System.Timers.Timer)sender).Start();
return;
}
@ -217,27 +208,10 @@ namespace AgroBase.Services
AdicionarComandoNaFila(MontarComandoRequisicaoPulsos(Convert.ToByte(Modulo.DirMotor.Endereco, 16)));
}
}
((System.Timers.Timer)sender).Start();
}
private static async void TmrLoopComandos_Elapsed(object sender, EventArgs e)
{
((System.Timers.Timer)sender).Stop();
if (EnvioLiberado)
{
await LoopEnvioComandos();
}
((System.Timers.Timer)sender).Start();
}
private static bool EnderecoValido(byte addr)
{
return Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => Convert.ToByte(x.DirMotor.Endereco.Replace("0x", ""), 16) == addr);
}
public static void AdicionarComandoNaFila(MKS057ComandoModel Comando)
{
if (!EnderecoValido(Comando.Endereco))
@ -254,8 +228,13 @@ namespace AgroBase.Services
}
}
private static async Task LoopEnvioComandos()
private static async Task tmrLoopComandos_Tick()
{
if (!EnvioLiberado)
{
return;
}
EnvioLiberado = false;
// Verifica se a conexão foi perdida e tenta reconectar

View File

@ -43,22 +43,16 @@ namespace AgroBase.Services
public static List<ModbusComandoModel> FilaComandos = new List<ModbusComandoModel>();
private static readonly object FilaLock = new object();
private static System.Timers.Timer tmrLoopComandos = new System.Timers.Timer() { Interval = 100, Enabled = false };
private static System.Timers.Timer tmrReceberDados = new System.Timers.Timer() { Interval = 1000, Enabled = false };
private static AsyncTaskTimerModel tmrLoopComandos;
private static AsyncTaskTimerModel tmrReceberDados;
public static void IniciarRotinas()
{
if (!tmrReceberDados.Enabled)
{
tmrReceberDados.Elapsed += TmrReceberDados_Elapsed;
tmrReceberDados.Start();
}
if (!tmrLoopComandos.Enabled)
{
tmrLoopComandos.Elapsed += TmrLoopComandos_Elapsed;
tmrLoopComandos.Start();
}
tmrLoopComandos = new AsyncTaskTimerModel(tmrLoopComandos_Tick, 100);
tmrLoopComandos.Start();
tmrReceberDados = new AsyncTaskTimerModel(tmrReceberDados_Tick, TaxaAmostragem);
tmrReceberDados.Start();
}
public static void DefinirPortaCOM(SerialPort Porta)
@ -99,10 +93,8 @@ namespace AgroBase.Services
}
}
private static void TmrReceberDados_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
private static async Task tmrReceberDados_Tick()
{
((System.Timers.Timer)sender).Stop();
if (Iniciado)
{
if (PZEMService.Iniciado && !PZEMService.ModoLeitura)
@ -143,14 +135,11 @@ namespace AgroBase.Services
}
}
((System.Timers.Timer)sender).Interval = TaxaAmostragem;
((System.Timers.Timer)sender).Start();
tmrReceberDados.SetInterval(TaxaAmostragem);
}
private static async void TmrLoopComandos_Elapsed(object sender, EventArgs e)
private static async Task tmrLoopComandos_Tick()
{
((System.Timers.Timer)sender).Stop();
if (EnvioLiberado && !Verificando && !frmInstancial.Fechando)
{
EnvioLiberado = false;
@ -178,8 +167,6 @@ namespace AgroBase.Services
EnvioLiberado = true;
}
}
((System.Timers.Timer)sender).Start();
}
@ -261,34 +248,16 @@ namespace AgroBase.Services
case T_Code.Pzm:
{
sucesso = PZEMService.ProcessarResposta(Comando.Resposta);
if (frmInstancial.DebugMode)
{
frmInstancial.frmAcompanhamento.AtualizarSensores("Ultima Leitura PZM: " + PZEMService.UltimaLeitura.DataHora.ToString("HH:mm:ss"));
frmInstancial.frmAcompanhamento.AtualizarSensores("Bateria: " + PZEMService.UltimaLeitura.Tensao.ToString("0.00") + " V - " + PZEMService.UltimaLeitura.Corrente.ToString("0.00") + " A - " + PZEMService.UltimaLeitura.Potencia.ToString("0.00") + " W");
}
break;
}
case T_Code.Wit:
{
sucesso = WT901CService.ProcessarResposta(Comando.Resposta, Comando.Comando);
if (frmInstancial.DebugMode)
{
frmInstancial.frmAcompanhamento.AtualizarSensores("Ultima Leitura WIT: " + WT901CService.DadosLeitura.Momento.ToString("HH:mm:ss"));
frmInstancial.frmAcompanhamento.AtualizarOrientacao();
}
break;
}
case T_Code.A05:
{
sucesso = UltrasonicA05Service.DecifrarRespostaAquisicao(Comando.Resposta);
if (frmInstancial.DebugMode)
{
frmInstancial.frmAcompanhamento.AtualizarSensores("Ultima Leitura A05: " + UltrasonicA05Service.DadosLeitura.Momento.ToString("HH:mm:ss"));
frmInstancial.frmAcompanhamento.AtualizarSensores("U1: " + UltrasonicA05Service.DadosLeitura.U1.ToString("") + " mm");
frmInstancial.frmAcompanhamento.AtualizarSensores("U2: " + UltrasonicA05Service.DadosLeitura.U2.ToString("") + " mm");
frmInstancial.frmAcompanhamento.AtualizarSensores("U3: " + UltrasonicA05Service.DadosLeitura.U3.ToString("") + " mm");
frmInstancial.frmAcompanhamento.AtualizarSensores("U4: " + UltrasonicA05Service.DadosLeitura.U4.ToString("") + " mm");
}
break;
}
}

View File

@ -15,7 +15,7 @@ public class MqttService
{
private IMqttClient _client;
private IMqttClientOptions _options;
private System.Timers.Timer tmrCheck = new System.Timers.Timer() { Interval = 1000, Enabled = false };
private AsyncTaskTimerModel tmrCheck;
public List<MqttTopicosModel> Topicos = new List<MqttTopicosModel>()
{
@ -112,27 +112,16 @@ public class MqttService
}
});
tmrCheck.Elapsed += TmrCheck_Elapsed;
tmrCheck = new AsyncTaskTimerModel(tmrCheck_Tick, 1000);
tmrCheck.Start();
}
private async void TmrCheck_Elapsed(object sender, EventArgs e)
private async Task tmrCheck_Tick()
{
((System.Timers.Timer)sender).Stop();
if (!_client.IsConnected)
{
await ConnectAsync();
}
Func<bool> funcao = new Func<bool>(() =>
{
frmInstancial.frmPrincipal.lblStripMqtt.Text = "MQTT: " + (_client.IsConnected ? "Conectado" : "Desconectado");
return true;
});
FuncoesGlobais.ExecutarMetodoComVerificacaoCrossThread(frmInstancial.frmPrincipal, funcao);
((System.Timers.Timer)sender).Start();
}
public bool StatusConexao()

View File

@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace AgroBase.Services
{
@ -59,40 +61,71 @@ namespace AgroBase.Services
public static Process RunScript(string Script, string[] Argumentos)
{
string ScriptPath = CaminhoGeral + CaminhoScripts + Script;
string Args = "";
foreach (var arg in Argumentos)
try
{
Args += ' '.ToString() + '"'.ToString() + arg.Replace("\\", "/") + '"'.ToString();
string ScriptPath = CaminhoGeral + CaminhoScripts + Script;
string Args = string.Join(" ", Argumentos.Select(arg => $"\"{arg.Replace("\\", "/")}\""));
Process pythonProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "python",
Arguments = $"{ScriptPath} {Args}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
Verb = Variaveis.NomeAplicacao
}
};
//pythonProcess.Exited += PythonProcess_Exited;
//pythonProcess.OutputDataReceived += PythonProcess_OutputDataReceived;
//pythonProcess.ErrorDataReceived += PythonProcess_ErrorDataReceived;
pythonProcess.Start();
//pythonProcess.BeginOutputReadLine();
//pythonProcess.BeginErrorReadLine();
lock (processosIniciados)
{
processosIniciados.Add(pythonProcess);
}
return pythonProcess;
}
catch (Exception ex)
{
Console.WriteLine($"Erro ao iniciar script Python: {ex.Message}");
return null;
}
}
public static async Task<bool> RunScriptWithTimeout(string Script, string[] Argumentos, int timeoutMs)
{
var processo = RunScript(Script, Argumentos);
if (processo == null) return false;
var completed = await Task.Run(() => processo.WaitForExit(timeoutMs));
if (!completed)
{
Console.WriteLine("Script Python excedeu o tempo limite e será encerrado.");
processo.Kill();
return false;
}
Process pythonProcess = new Process();
pythonProcess.StartInfo.FileName = "python";
pythonProcess.StartInfo.Arguments = ScriptPath + Args;
pythonProcess.StartInfo.UseShellExecute = false;
pythonProcess.StartInfo.RedirectStandardOutput = true;
pythonProcess.StartInfo.RedirectStandardError = true;
pythonProcess.StartInfo.CreateNoWindow = true;
pythonProcess.StartInfo.Verb = Variaveis.NomeAplicacao;
pythonProcess.Exited += PythonProcess_Exited;
pythonProcess.OutputDataReceived += PythonProcess_OutputDataReceived;
pythonProcess.ErrorDataReceived += PythonProcess_ErrorDataReceived;
pythonProcess.Start();
pythonProcess.BeginOutputReadLine();
pythonProcess.BeginErrorReadLine();
processosIniciados.Add(pythonProcess);
return pythonProcess;
return true;
}
private static void PythonProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine("Erro recebidos pelo Python: " + e.Data);
if (!string.IsNullOrWhiteSpace(e.Data))
{
Console.WriteLine($"Erro recebidos pelo Python: {e.Data}");
// Log adicional ou notificação pode ser adicionado aqui
}
}
private static void PythonProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
@ -107,7 +140,14 @@ namespace AgroBase.Services
{
if (DebugMode)
{
Console.WriteLine("Processo finalizado");
Console.WriteLine("Processo Python finalizado");
}
lock (processosIniciados)
{
var processo = (Process)sender;
processosIniciados.Remove(processo);
processo.Dispose();
}
}

View File

@ -267,9 +267,9 @@ namespace AgroBase.Services
public static async Task RealizarVarreduraPortasUSB(System.Timers.Timer tmr)
public static async Task RealizarVarreduraPortasUSB() // System.Timers.Timer tmr
{
tmr.Interval = InteraloVerificacao;
//tmr.Interval = InteraloVerificacao;
if (VarreduraEmAndamento || frmInstancial.Fechando)
{
@ -661,9 +661,18 @@ namespace AgroBase.Services
return false;
}
bool ProcurarPzm = !PZEMService.Iniciado || !DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Pzm);
bool ProcurarWit = !WT901CService.Iniciado || !DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Wit);
bool ProcurarA05 = !UltrasonicA05Service.Iniciado || !DispositivosMapeados.Any(x => x.Dispositivo == T_Code.A05);
if (!ProcurarPzm && !ProcurarWit && !ProcurarA05)
{
return false;
}
AtualizarConsole("Procurando dispositivos Modbus");
if (!PZEMService.Iniciado || !DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Pzm))
if (ProcurarPzm)
{
AtualizarConsole("Procurando dispositivo PZM");
bool _encontrado = await PZEMService.VerificaPortaPZEM(ModbusService.Iniciado ? ModbusService._PortaModbus : porta);
@ -674,7 +683,7 @@ namespace AgroBase.Services
return _encontrado;
}
}
if (!WT901CService.Iniciado || !DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Wit))
if (ProcurarWit)
{
AtualizarConsole("Procurando dispositivo WIT");
bool _encontrado = await WT901CService.VerificaPortaWT901C(ModbusService.Iniciado ? ModbusService._PortaModbus : porta);
@ -684,7 +693,7 @@ namespace AgroBase.Services
return _encontrado;
}
}
if (!UltrasonicA05Service.Iniciado || !DispositivosMapeados.Any(x => x.Dispositivo == T_Code.A05))
if (ProcurarA05)
{
AtualizarConsole("Procurando dispositivo A05");
bool _encontrado = await UltrasonicA05Service.VerificaPortaA05(ModbusService.Iniciado ? ModbusService._PortaModbus : porta);
@ -694,21 +703,6 @@ namespace AgroBase.Services
return _encontrado;
}
}
/*if (Variaveis.OperacaoEmAndamento.DispMvd != null && Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => !x.MovMotor.DadosDriver.Iniciado))
{
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.MovMotor.DadosDriver.Iniciado))
{
Encontrado = await Modulo.MovMotor.DadosDriver.VerificaPortaBLD(ModbusService._PortaModbus);
if (Encontrado)
{
await Modulo.MovMotor.DadosDriver.AtualizarDadosDriver();
if (PararAoEncontrar)
{
return Encontrado;
}
}
}
}*/
return ModbusService.Iniciado;
}

File diff suppressed because it is too large Load Diff

View File

@ -15,3 +15,5 @@
11/11/2024 09:35:21:159 - Porta COM68 - 0: Erro ao processar fila de comandos. Erro=The port is closed.
11/11/2024 13:38:33:524 - Porta COM85 - 0: Erro ao processar fila de comandos. Erro=The port is closed.
21/11/2024 13:26:00:651 - Porta COM90 - 0: Erro ao processar fila de comandos. Erro=The port is closed.
22/11/2024 08:24:14:797 - Porta COM88 - 0: Erro ao processar fila de comandos. Erro=The port is closed.
22/11/2024 15:31:48:366 - Porta COM - 0: Erro ao processar fila de comandos. Erro=The port is closed.

View File

@ -1 +1 @@
{"Modulo_ID":"Atu","RequisitarDados":false,"Conectado":false,"QuantidadeBicos":4,"DensidadeHerbicida":1.05,"AtuacaoNivelAlto":true,"BicosPulverizadores":[{"ID":"B01","Posicao":1,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B02","Posicao":2,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B03","Posicao":3,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B04","Posicao":4,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0}],"BombaPressurizadora":{"ID":"BOMBA","BombaAtuada":false,"Ligado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[14,35,36,37,5],"Pressao":0.0,"Potencia":0.0},"Sensores":[{"LogGrafico":[],"ID":"FLXLN","Prioridade":23,"Descricao":"Fluxo na linha principal","Componente":198,"Aferir":true,"DelayAmostragem":300,"Inicializado":false,"Testando":false,"Funcoes":[25],"Parametros":[],"UnidadeMedida":"mL/s","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"MASRS","Prioridade":3,"Descricao":"Massa do reservatório de herbicida","Componente":532,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[22,23],"Parametros":[],"UnidadeMedida":"Kg","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":50.0,"LimiteMinimo":5.0},{"LogGrafico":[],"ID":"PRSLN","Prioridade":3,"Descricao":"Pressão na linha principal","Componente":333,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[24],"Parametros":[["Vmin","000.00"],["Vmax","004.50"],["Pmax","174.04"]],"UnidadeMedida":"psi","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":120.0,"LimiteMinimo":60.0}],"ScriptDeteccaoErvas":"weed_detector-1_0.py","_MassaRef":0.8,"_MassaLeituraRef":40876.37,"_MassaLeituraExtra":1895800.0,"_MassaLeitura":1895800.0,"MassaReservatorio":0.0,"VolumeReservatorio":0.0,"PercentualReservatorio":0.0,"VolumeVazaoAferido":0.0,"_FluxoMlRef":102.0,"_FluxoPulsoRef":80.0,"_LeituraPulsos":0,"_LeituraPeriodo":0,"VazaoFluxoMLpS":0.0,"VolumeVazaoML":0.0,"InicioAtuacao":"0001-01-01T00:00:00","FimAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0,"_PressaoVmin":0.0,"_PressaoVmax":4.5,"_PressaoMax":174.045,"_LeituraPressao":0.0,"PressaoLinha":0.0,"PressaoLinhaCalc":0.0}
{"Modulo_ID":"Atu","RequisitarDados":false,"Conectado":false,"QuantidadeBicos":4,"DensidadeHerbicida":1.05,"AtuacaoNivelAlto":true,"BicosPulverizadores":[{"ID":"B01","Posicao":1,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B02","Posicao":2,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B03","Posicao":3,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0},{"ID":"B04","Posicao":4,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0,"Atuacoes":0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0}],"BombaPressurizadora":{"ID":"BOMBA","BombaAtuada":false,"Ligado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[14,35,36,37,5],"Pressao":0.0,"Potencia":0.0},"Sensores":[{"LogGrafico":[],"ID":"FLXLN","Prioridade":23,"Descricao":"Fluxo na linha principal","Componente":198,"Aferir":true,"DelayAmostragem":300,"Inicializado":false,"Testando":false,"Funcoes":[25],"Parametros":[],"UnidadeMedida":"mL/s","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"MASRS","Prioridade":3,"Descricao":"Massa do reservatório de herbicida","Componente":532,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[22,23],"Parametros":[],"UnidadeMedida":"Kg","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":50.0,"LimiteMinimo":5.0},{"LogGrafico":[],"ID":"PRSLN","Prioridade":3,"Descricao":"Pressão na linha principal","Componente":333,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[24],"Parametros":[["Vmin","000.00"],["Vmax","004.50"],["Pmax","174.04"]],"UnidadeMedida":"psi","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":120.0,"LimiteMinimo":60.0}],"ScriptDeteccaoErvas":"weed_detector-1_0.py","_MassaRef":0.8,"_MassaLeituraRef":40876.37,"_MassaLeituraExtra":1895800.0,"_MassaLeitura":1895800.0,"MassaReservatorio":0.0,"VolumeReservatorio":0.0,"PercentualReservatorio":0.0,"VolumeVazaoAferido":0.0,"_FluxoMlRef":102.0,"_FluxoPulsoRef":80.0,"_LeituraPulsos":0,"_LeituraPeriodo":0,"VazaoFluxoMLpS":0.0,"VolumeVazaoML":0.0,"InicioAtuacao":"0001-01-01T00:00:00","TempoAtuado":0.0,"_PressaoVmin":0.0,"_PressaoVmax":4.5,"_PressaoMax":174.045,"_LeituraPressao":0.0,"PressaoLinha":0.0,"PressaoLinhaCalc":0.0}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Id":"1517","Name":"11_11_2024_14_08_37","Length":0.0,"Dist1":0.0,"Dist2":0.0},"geometry":{"id":null,"type":"LineString","coordinates":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]]}}]}
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Id":"1517","Name":"22_11_2024_17_15_15","Length":0.0,"Dist1":0.0,"Dist2":0.0},"geometry":{"id":null,"type":"LineString","coordinates":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]]}}]}

View File

@ -25,7 +25,7 @@
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
#map_fa1fb12b82d67d7b576b4a6c72021b43 {
#map_07a098740876f040ece2bf1f6f913e03 {
position: relative;
width: 100.0%;
height: 100.0%;
@ -39,14 +39,14 @@
<body>
<div class="folium-map" id="map_fa1fb12b82d67d7b576b4a6c72021b43" ></div>
<div class="folium-map" id="map_07a098740876f040ece2bf1f6f913e03" ></div>
</body>
<script>
var map_fa1fb12b82d67d7b576b4a6c72021b43 = L.map(
"map_fa1fb12b82d67d7b576b4a6c72021b43",
var map_07a098740876f040ece2bf1f6f913e03 = L.map(
"map_07a098740876f040ece2bf1f6f913e03",
{
center: [0.0, 0.0],
crs: L.CRS.EPSG3857,
@ -60,13 +60,13 @@
var tile_layer_fc2a48162ee97dadb749ec5c9d4585d1 = L.tileLayer(
var tile_layer_ebd09008a2ea454b658d8ddf7b42809d = L.tileLayer(
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
);
tile_layer_fc2a48162ee97dadb749ec5c9d4585d1.addTo(map_fa1fb12b82d67d7b576b4a6c72021b43);
tile_layer_ebd09008a2ea454b658d8ddf7b42809d.addTo(map_07a098740876f040ece2bf1f6f913e03);
</script>
@ -87,7 +87,7 @@
}
trajeto_json_add({"features": []});
trajeto_json.addTo(map_fa1fb12b82d67d7b576b4a6c72021b43);
trajeto_json.addTo(map_07a098740876f040ece2bf1f6f913e03);
function adicionarGeometria(novaGeometria) {
trajeto_json.addData(novaGeometria);
@ -145,7 +145,7 @@
var marcadorDinamico = L.marker([0, 0], {
icon: customIcon
}).addTo(map_fa1fb12b82d67d7b576b4a6c72021b43);
}).addTo(map_07a098740876f040ece2bf1f6f913e03);
// Conectar ao broker MQTT
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
@ -183,7 +183,7 @@
marcadorDinamico.setRotationAngle(angulo);
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
map_fa1fb12b82d67d7b576b4a6c72021b43.setView(novaPosicao, map_fa1fb12b82d67d7b576b4a6c72021b43.getZoom());
map_07a098740876f040ece2bf1f6f913e03.setView(novaPosicao, map_07a098740876f040ece2bf1f6f913e03.getZoom());
});
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {

View File

@ -25,7 +25,7 @@
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
#map_9bc1c08b3771a8d9d88d8c84ea53aafc {
#map_f4618322b26ef6900f1125b33a98b933 {
position: relative;
width: 100.0%;
height: 100.0%;
@ -39,14 +39,14 @@
<body>
<div class="folium-map" id="map_9bc1c08b3771a8d9d88d8c84ea53aafc" ></div>
<div class="folium-map" id="map_f4618322b26ef6900f1125b33a98b933" ></div>
</body>
<script>
var map_9bc1c08b3771a8d9d88d8c84ea53aafc = L.map(
"map_9bc1c08b3771a8d9d88d8c84ea53aafc",
var map_f4618322b26ef6900f1125b33a98b933 = L.map(
"map_f4618322b26ef6900f1125b33a98b933",
{
center: [0.0, 0.0],
crs: L.CRS.EPSG3857,
@ -60,13 +60,13 @@
var tile_layer_05bcea44b7b0f79e78a69feab7be7c58 = L.tileLayer(
var tile_layer_51e21784728e165fdac4114417c9be97 = L.tileLayer(
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
);
tile_layer_05bcea44b7b0f79e78a69feab7be7c58.addTo(map_9bc1c08b3771a8d9d88d8c84ea53aafc);
tile_layer_51e21784728e165fdac4114417c9be97.addTo(map_f4618322b26ef6900f1125b33a98b933);
@ -82,7 +82,7 @@
}*/
});
}
function geo_json_9fbf11020c519372602572fe907c2112_onEachFeature(feature, layer) {
function geo_json_0724bb7f6b75e35871d716caa4a037af_onEachFeature(feature, layer) {
layer.on({
click: function(e) {
@ -118,20 +118,20 @@
}*/
});
};
var geo_json_9fbf11020c519372602572fe907c2112 = L.geoJson(null, {
onEachFeature: geo_json_9fbf11020c519372602572fe907c2112_onEachFeature,
var geo_json_0724bb7f6b75e35871d716caa4a037af = L.geoJson(null, {
onEachFeature: geo_json_0724bb7f6b75e35871d716caa4a037af_onEachFeature,
});
function geo_json_9fbf11020c519372602572fe907c2112_add (data) {
geo_json_9fbf11020c519372602572fe907c2112
function geo_json_0724bb7f6b75e35871d716caa4a037af_add (data) {
geo_json_0724bb7f6b75e35871d716caa4a037af
.addData(data);
}
geo_json_9fbf11020c519372602572fe907c2112_add({"features": [{"geometry": {"coordinates": [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], "id": null, "type": "LineString"}, "id": 0, "properties": {"Dist1": 0.0, "Dist2": 0.0, "Id": "1517", "Length": 0.0, "Name": "11_11_2024_14_08_37"}, "type": "Feature"}], "type": "FeatureCollection"});
geo_json_0724bb7f6b75e35871d716caa4a037af_add({"features": [{"geometry": {"coordinates": [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], "id": null, "type": "LineString"}, "id": 0, "properties": {"Dist1": 0.0, "Dist2": 0.0, "Id": "1517", "Length": 0.0, "Name": "22_11_2024_17_15_15"}, "type": "Feature"}], "type": "FeatureCollection"});
geo_json_9fbf11020c519372602572fe907c2112.addTo(map_9bc1c08b3771a8d9d88d8c84ea53aafc);
geo_json_0724bb7f6b75e35871d716caa4a037af.addTo(map_f4618322b26ef6900f1125b33a98b933);
</script>
@ -152,7 +152,7 @@
}
trajeto_json_add({"features": []});
trajeto_json.addTo(map_9bc1c08b3771a8d9d88d8c84ea53aafc);
trajeto_json.addTo(map_f4618322b26ef6900f1125b33a98b933);
function adicionarGeometria(novaGeometria) {
trajeto_json.addData(novaGeometria);
@ -210,7 +210,7 @@
}
trajeto_dinamico_json_add({"features": []});
trajeto_dinamico_json.addTo(map_9bc1c08b3771a8d9d88d8c84ea53aafc);
trajeto_dinamico_json.addTo(map_f4618322b26ef6900f1125b33a98b933);
function adicionarGeometriaDinamica(novaGeometria) {
trajeto_dinamico_json.addData(novaGeometria);
@ -263,9 +263,9 @@
var marcadorEquipamento = L.marker([0, 0], {
icon: customIcon
}).addTo(map_9bc1c08b3771a8d9d88d8c84ea53aafc);
}).addTo(map_f4618322b26ef6900f1125b33a98b933);
var marcadorBase = L.marker([0, 0], {}).addTo(map_9bc1c08b3771a8d9d88d8c84ea53aafc);
var marcadorBase = L.marker([0, 0], {}).addTo(map_f4618322b26ef6900f1125b33a98b933);
var icon = L.AwesomeMarkers.icon(
{"extraClasses": "fa-rotate-0", "icon": "info-sign", "iconColor": "white", "markerColor": "red", "prefix": "glyphicon"}
);
@ -347,7 +347,7 @@
}
if (foco) {
map_9bc1c08b3771a8d9d88d8c84ea53aafc.setView(novaPosicao, map_9bc1c08b3771a8d9d88d8c84ea53aafc.getZoom());
map_f4618322b26ef6900f1125b33a98b933.setView(novaPosicao, map_f4618322b26ef6900f1125b33a98b933.getZoom());
}
}
@ -364,7 +364,7 @@
function atualizarSelecaoRuas(selecionadas) {
selecionadas = JSON.parse(selecionadas);
RuasSelecionadas = Array.isArray(selecionadas) ? [...selecionadas] : [];
geo_json_9fbf11020c519372602572fe907c2112.eachLayer(function (layer) {
geo_json_0724bb7f6b75e35871d716caa4a037af.eachLayer(function (layer) {
if (RuasSelecionadas.includes(parseInt(layer.feature.id))) {
layer.setStyle({ color: 'blue' });
} else {

View File

@ -1 +1 @@
d183f77e5e1a919a1748ce240aac9f56e10790c2389f0601b3ac9063fe720309
afe56ee07a44e7bdf0ff34262548be78816ffa76793d188967eb564a704ab6d0

View File

@ -13,7 +13,7 @@ namespace AgroMonitor.Forms
{
public partial class frmAjustesOperacao : Form
{
Timer tmrDadosMapa = new Timer();
AsyncTaskTimerModel tmrDadosMapa;
string path = Variaveis.CaminhoSistema + Variaveis.CaminhoOperacoes + "\\" + MapasVariaveisModel.NomeArquivoMapaInterativoSaida;
UltrasonicA05Configuracoes ConfigUltrassom = UltrasonicA05Helper.CarregarConfiguracaoPadrao(ConfiguracaoSensorUltrassonico.NaoUtilizado);
@ -35,7 +35,10 @@ namespace AgroMonitor.Forms
private void frmAjustesOperacao_FormClosing(object sender, FormClosingEventArgs e)
{
tmrDadosMapa.Stop();
if (tmrDadosMapa != null)
{
tmrDadosMapa.Stop();
}
}
@ -98,15 +101,14 @@ namespace AgroMonitor.Forms
Variaveis.OperacaoEmAndamento.Mapa.btnCarregar_Click(sender, e);
if (!tmrDadosMapa.Enabled)
if (tmrDadosMapa != null && !tmrDadosMapa.IsRunning)
{
tmrDadosMapa = new Timer() { Interval = 500 };
tmrDadosMapa.Tick += tmrDadosMapa_Tick;
tmrDadosMapa = new AsyncTaskTimerModel(tmrDadosMapa_Tick, 500, this);
tmrDadosMapa.Start();
}
}
private void tmrDadosMapa_Tick(object sender, EventArgs e)
private async Task tmrDadosMapa_Tick()
{
if (Variaveis.OperacaoEmAndamento.Mapa.mapaService.DadosMapa == null)
{
@ -165,8 +167,7 @@ namespace AgroMonitor.Forms
MessageBox.Show("Operação carregada com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
tmrDadosMapa = new Timer() { Interval = 500 };
tmrDadosMapa.Tick += tmrDadosMapa_Tick;
tmrDadosMapa = new AsyncTaskTimerModel(tmrDadosMapa_Tick, 500, this);
tmrDadosMapa.Start();
await Task.Delay(1000);

View File

@ -118,6 +118,7 @@
this.Name = "frmInicial";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Agro Monitoramento";
this.Load += new System.EventHandler(this.frmInicial_Load);
((System.ComponentModel.ISupportInitialize)(this.picRastreamento)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picRede)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picAjustes)).EndInit();

View File

@ -4,13 +4,14 @@ using AgroBase.Services;
using AgroMonitor.Forms;
using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AgroMonitor
{
public partial class frmInicial : Form
{
Timer tmrDispositivos = new Timer() { Interval = 1000, Enabled = false };
AsyncTaskTimerModel tmrDispositivos;
public frmInicial()
{
@ -44,17 +45,19 @@ namespace AgroMonitor
}, true);
}
private void frmInicial_Load(object sender, EventArgs e)
{
tmrDispositivos = new AsyncTaskTimerModel(tmrDispositivos_Tick, 1000, this);
}
private void IniciarDependencias()
{
tmrDispositivos.Tick += TmrDispositivos_Elapsed;
tmrDispositivos.Start();
}
private async void TmrDispositivos_Elapsed(object sender, EventArgs e)
private async Task tmrDispositivos_Tick()
{
var tmr = ((Timer)sender);
tmr.Stop();
Func<bool> funcao = new Func<bool>(() =>
{
lblMqtt.Text = "MQTT: " + (Variaveis.MqttService.StatusConexao() ? "Conectado" : "Desconectado");
@ -73,17 +76,15 @@ namespace AgroMonitor
if (!GPSService.Iniciado || !LoRaService.Iniciado)
{
await SerialService.RealizarVarreduraPortasUSB(new System.Timers.Timer());
tmr.Interval = SerialService.InteraloVerificacao;
await SerialService.RealizarVarreduraPortasUSB();
tmrDispositivos.SetInterval(SerialService.InteraloVerificacao);
}
else
{
tmr.Interval = 10000;
tmrDispositivos.SetInterval(10000);
}
tmr.Start();
}
}
}

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
@ -11,7 +12,7 @@ namespace AgroMonitor.Forms
{
public partial class frmMonitoramento : Form
{
Timer tmrLeituras = new Timer();
AsyncTaskTimerModel tmrLeituras;
DateTime MomentoLog = DateTime.Now;
private MapasModel Mapa;
Dictionary<byte, List<LoRaProtocoloTransmissaoModel>> Logs = new Dictionary<byte, List<LoRaProtocoloTransmissaoModel>>();
@ -25,8 +26,7 @@ namespace AgroMonitor.Forms
private void frmMonitoramento_Load(object sender, EventArgs e)
{
tmrLeituras.Interval = 1000;
tmrLeituras.Tick += tmrLeituras_Tick;
tmrLeituras = new AsyncTaskTimerModel(tmrLeituras_Tick, 1000, this);
tmrLeituras.Start();
cmbTipoMovimento.Items.Clear();
@ -42,7 +42,7 @@ namespace AgroMonitor.Forms
Logs = new Dictionary<byte, List<LoRaProtocoloTransmissaoModel>>(VariaveisMonitoramento.EquipamentosConectadosLogs);
}
private void tmrLeituras_Tick(object sender, EventArgs e)
private async Task tmrLeituras_Tick()
{
string EquipamentoSelecionado = cmbEquipamento.Text;
if (cmbEquipamento.Items.Count != VariaveisMonitoramento.EquipamentosConectados.Count())

View File

@ -913,6 +913,9 @@ class ServoFreio {
String _ID;
PinoModel _pino;
bool Incremental = true;
bool Iniciado = false;
int _Angulo = 0;
@ -928,7 +931,7 @@ class ServoFreio {
if (_pino.Definido()) {
_Servo.attach(_pino.num);
_Servo.write(0);
_Servo.write(Incremental ? 0 : 180);
}
Iniciado = true;
@ -1159,10 +1162,12 @@ void ProcessarCfg(ProtocoloSerial Mensagem) {
}
}
else if (_freio != nullptr) {
TiposBarramentos pinoB = (TiposBarramentos)Partes[2].toInt();
int pino = Partes[3].toInt();
bool inc = Partes[2] == "1";
TiposBarramentos pinoB = (TiposBarramentos)Partes[3].toInt();
int pino = Partes[4].toInt();
if (pino > -1) {
if (Conectar) {
_freio->Incremental = inc;
_freio->_pino = PinoModel(pino, pinoB, _OUTPUT);
_freio->Inicializar();
}