2024-07-05 18:59:05 +00:00
|
|
|
|
using AgroBase.Forms.IHM;
|
|
|
|
|
|
using AgroBase.Models;
|
2024-04-24 18:01:25 +00:00
|
|
|
|
using AgroBase.Services;
|
2023-10-09 16:06:23 +00:00
|
|
|
|
using System;
|
2024-12-13 19:39:31 +00:00
|
|
|
|
using System.Threading;
|
2023-08-31 11:50:53 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AgroBase.Forms
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class frmInstancial : Form
|
|
|
|
|
|
{
|
2024-11-27 17:38:56 +00:00
|
|
|
|
public static AsyncTaskTimerModel tmrVarreduraDispositivos;
|
|
|
|
|
|
|
2023-08-31 11:50:53 +00:00
|
|
|
|
public static frmPrincipal frmPrincipal = new frmPrincipal();
|
|
|
|
|
|
public static frmJoystick frmJoystick = new frmJoystick();
|
2024-07-05 18:59:05 +00:00
|
|
|
|
public static frmIHM frmIHM = new frmIHM()
|
|
|
|
|
|
{
|
|
|
|
|
|
FormBorderStyle = FormBorderStyle.None,
|
2024-12-12 22:04:05 +00:00
|
|
|
|
//WindowState = FormWindowState.Maximized,
|
|
|
|
|
|
//TopMost = true
|
2024-07-05 18:59:05 +00:00
|
|
|
|
};
|
2023-08-31 11:50:53 +00:00
|
|
|
|
|
|
|
|
|
|
public frmInstancial()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2024-12-03 16:19:16 +00:00
|
|
|
|
|
2024-12-13 19:39:31 +00:00
|
|
|
|
ThreadPool.SetMinThreads(workerThreads: 50, completionPortThreads: 50);
|
|
|
|
|
|
|
2024-12-05 12:52:28 +00:00
|
|
|
|
APIService.IniciarRotinas();
|
2025-02-21 19:50:54 +00:00
|
|
|
|
|
2024-11-25 12:14:59 +00:00
|
|
|
|
GeneralJoystick.IniciarRotinas();
|
2025-06-06 20:46:08 +00:00
|
|
|
|
|
2024-11-27 17:38:56 +00:00
|
|
|
|
VersionamentoService.IniciarRotinas();
|
2024-09-24 19:02:54 +00:00
|
|
|
|
|
2025-04-02 20:37:56 +00:00
|
|
|
|
PythonService.EncerrarProcessos();
|
2025-06-06 20:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
await VariaveisOperacao.Operadores.IniciarProcessamento(false);
|
|
|
|
|
|
});
|
2023-08-31 11:50:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void frmInstancial_Shown(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2025-03-27 11:47:00 +00:00
|
|
|
|
if (!Variaveis.Producao)
|
2024-07-05 18:59:05 +00:00
|
|
|
|
{
|
2024-10-04 13:11:23 +00:00
|
|
|
|
frmIHM.FormClosing += FrmIHM_FormClosing;
|
2024-07-05 18:59:05 +00:00
|
|
|
|
frmPrincipal.FormClosing += frmPrincipal_FormClosing;
|
|
|
|
|
|
frmPrincipal.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
frmIHM.FormClosing += frmPrincipal_FormClosing;
|
|
|
|
|
|
frmIHM.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-31 11:50:53 +00:00
|
|
|
|
this.Hide();
|
|
|
|
|
|
}
|
2024-03-01 19:49:20 +00:00
|
|
|
|
|
2024-10-04 13:11:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
2024-07-05 18:59:05 +00:00
|
|
|
|
private void frmInstancial_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
FuncoesGlobais.AddApplicationToStartup();
|
|
|
|
|
|
IniciarConexaoMqtt();
|
2024-11-27 17:38:56 +00:00
|
|
|
|
|
|
|
|
|
|
Control control = new Control();
|
2025-03-27 11:47:00 +00:00
|
|
|
|
if (!Variaveis.Producao)
|
2024-11-27 17:38:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
control = frmPrincipal;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
control = frmIHM;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-29 20:28:25 +00:00
|
|
|
|
tmrVarreduraDispositivos = new AsyncTaskTimerModel("tmrVarreduraDispositivos", tmrVarreduraDispositivos_Tick, SerialService.InteraloVerificacao, null, 15000);
|
2024-11-27 17:38:56 +00:00
|
|
|
|
tmrVarreduraDispositivos.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task tmrVarreduraDispositivos_Tick()
|
|
|
|
|
|
{
|
2024-11-29 20:28:25 +00:00
|
|
|
|
await SerialService.RealizarVarreduraPortasUSB();
|
2024-07-05 18:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void IniciarConexaoMqtt()
|
|
|
|
|
|
{
|
|
|
|
|
|
await Variaveis.MqttService.ConnectAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task EncerrarProcessos()
|
|
|
|
|
|
{
|
2025-03-27 11:47:00 +00:00
|
|
|
|
Variaveis.Fechando = true;
|
2024-07-05 18:59:05 +00:00
|
|
|
|
|
2024-11-27 17:38:56 +00:00
|
|
|
|
AsyncTaskTimerModel.PararTimers();
|
|
|
|
|
|
|
2024-07-05 18:59:05 +00:00
|
|
|
|
foreach (var Disp in Variaveis.DispositivosConectados)
|
|
|
|
|
|
{
|
2024-11-29 20:28:25 +00:00
|
|
|
|
Disp.EnviarProtocolosConfiguracao(false);
|
2024-07-05 18:59:05 +00:00
|
|
|
|
Disp.SalvarParametros(Disp.Dados);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (!FilaService.Liberado)
|
|
|
|
|
|
{
|
|
|
|
|
|
await Task.Delay(500);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-02 20:37:56 +00:00
|
|
|
|
PythonService.EncerrarProcessos();
|
2024-09-24 19:02:54 +00:00
|
|
|
|
|
2024-07-05 18:59:05 +00:00
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-02 20:37:56 +00:00
|
|
|
|
|
2024-09-24 19:02:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
2024-07-05 18:59:05 +00:00
|
|
|
|
|
2024-11-27 17:38:56 +00:00
|
|
|
|
private async void frmPrincipal_FormClosing(object sender, FormClosingEventArgs e)
|
2024-07-05 18:59:05 +00:00
|
|
|
|
{
|
2024-11-27 17:38:56 +00:00
|
|
|
|
await EncerrarProcessos();
|
2024-07-05 18:59:05 +00:00
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-04 13:11:23 +00:00
|
|
|
|
private void FrmIHM_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
frmIHM.Hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-31 11:50:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|