diff --git a/AgroBase/AgroBase/AgroBase.csproj b/AgroBase/AgroBase/AgroBase.csproj
index c852c9229..7553bd512 100644
--- a/AgroBase/AgroBase/AgroBase.csproj
+++ b/AgroBase/AgroBase/AgroBase.csproj
@@ -282,6 +282,12 @@
frmAtuConfig.cs
+
+ Form
+
+
+ frmCanEthernetConfig.cs
+
Form
@@ -565,6 +571,7 @@
+
@@ -624,6 +631,7 @@
+
@@ -710,6 +718,9 @@
frmAtuConfig.cs
+
+ frmCanEthernetConfig.cs
+
frmDirConfig.cs
diff --git a/AgroBase/AgroBase/Forms/IHM/frmAjustes.Designer.cs b/AgroBase/AgroBase/Forms/IHM/frmAjustes.Designer.cs
index 5621f8bb4..86200486e 100644
--- a/AgroBase/AgroBase/Forms/IHM/frmAjustes.Designer.cs
+++ b/AgroBase/AgroBase/Forms/IHM/frmAjustes.Designer.cs
@@ -40,36 +40,36 @@
this.picAtualizar = new System.Windows.Forms.PictureBox();
this.btnCalibrarSonar = new System.Windows.Forms.Button();
this.gpbComunicacao = new System.Windows.Forms.GroupBox();
- this.gpbCameras = new System.Windows.Forms.GroupBox();
- this.picCaminho = new System.Windows.Forms.PictureBox();
- this.flwCamerasSolo = new System.Windows.Forms.FlowLayoutPanel();
- this.gpbBase = new System.Windows.Forms.GroupBox();
- this.lblPortaErvas = new System.Windows.Forms.Label();
this.gpbEquipamento = new System.Windows.Forms.GroupBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ this.txtEquipamentoGateway = new System.Windows.Forms.TextBox();
+ this.txtEquipamentoSubmask = new System.Windows.Forms.TextBox();
+ this.lblInterface = new System.Windows.Forms.Label();
+ this.cmbInterface = new System.Windows.Forms.ComboBox();
this.txtEquipamentoIP = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtEquipamentoSerial = new System.Windows.Forms.TextBox();
this.lblEquipamentoSerial = new System.Windows.Forms.Label();
- this.nudPortaCaminho = new System.Windows.Forms.NumericUpDown();
+ this.gpbBase = new System.Windows.Forms.GroupBox();
this.nudPortaErvas = new System.Windows.Forms.NumericUpDown();
- this.cmbInterface = new System.Windows.Forms.ComboBox();
- this.lblInterface = new System.Windows.Forms.Label();
- this.txtEquipamentoSubmask = new System.Windows.Forms.TextBox();
- this.txtEquipamentoGateway = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
+ this.nudPortaCaminho = new System.Windows.Forms.NumericUpDown();
+ this.lblPortaErvas = new System.Windows.Forms.Label();
+ this.gpbCameras = new System.Windows.Forms.GroupBox();
+ this.picCaminho = new System.Windows.Forms.PictureBox();
+ this.flwCamerasSolo = new System.Windows.Forms.FlowLayoutPanel();
((System.ComponentModel.ISupportInitialize)(this.picVoltar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picSalvar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picLer)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picGravar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picAtualizar)).BeginInit();
this.gpbComunicacao.SuspendLayout();
+ this.gpbEquipamento.SuspendLayout();
+ this.gpbBase.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.nudPortaErvas)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.nudPortaCaminho)).BeginInit();
this.gpbCameras.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picCaminho)).BeginInit();
- this.gpbBase.SuspendLayout();
- this.gpbEquipamento.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.nudPortaCaminho)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.nudPortaErvas)).BeginInit();
this.SuspendLayout();
//
// cmbCameraCaminho
@@ -189,66 +189,6 @@
this.gpbComunicacao.TabStop = false;
this.gpbComunicacao.Text = "COMUNICAÇÃO";
//
- // gpbCameras
- //
- this.gpbCameras.Controls.Add(this.picCaminho);
- this.gpbCameras.Controls.Add(this.flwCamerasSolo);
- this.gpbCameras.Controls.Add(this.picVoltar);
- this.gpbCameras.Controls.Add(this.picSalvar);
- this.gpbCameras.Controls.Add(this.picAtualizar);
- this.gpbCameras.Controls.Add(this.btnCalibrarSonar);
- this.gpbCameras.Controls.Add(this.cmbCameraCaminho);
- this.gpbCameras.Location = new System.Drawing.Point(12, 12);
- this.gpbCameras.Name = "gpbCameras";
- this.gpbCameras.Size = new System.Drawing.Size(1000, 322);
- this.gpbCameras.TabIndex = 41;
- this.gpbCameras.TabStop = false;
- this.gpbCameras.Text = "CÂMERAS";
- //
- // picCaminho
- //
- this.picCaminho.BackColor = System.Drawing.Color.Black;
- this.picCaminho.Location = new System.Drawing.Point(137, 19);
- this.picCaminho.Name = "picCaminho";
- this.picCaminho.Size = new System.Drawing.Size(320, 234);
- this.picCaminho.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
- this.picCaminho.TabIndex = 37;
- this.picCaminho.TabStop = false;
- //
- // flwCamerasSolo
- //
- this.flwCamerasSolo.Location = new System.Drawing.Point(463, 19);
- this.flwCamerasSolo.Name = "flwCamerasSolo";
- this.flwCamerasSolo.Size = new System.Drawing.Size(531, 297);
- this.flwCamerasSolo.TabIndex = 39;
- //
- // gpbBase
- //
- this.gpbBase.Controls.Add(this.nudPortaErvas);
- this.gpbBase.Controls.Add(this.nudPortaCaminho);
- this.gpbBase.Controls.Add(this.lblPortaErvas);
- this.gpbBase.Controls.Add(this.txtBaseIP);
- this.gpbBase.Controls.Add(this.lblBaseIP);
- this.gpbBase.Controls.Add(this.lblPortaCaminho);
- this.gpbBase.Location = new System.Drawing.Point(6, 19);
- this.gpbBase.Name = "gpbBase";
- this.gpbBase.Size = new System.Drawing.Size(374, 223);
- this.gpbBase.TabIndex = 35;
- this.gpbBase.TabStop = false;
- this.gpbBase.Text = "BASE";
- //
- // lblPortaErvas
- //
- this.lblPortaErvas.AutoSize = true;
- this.lblPortaErvas.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lblPortaErvas.LiveSetting = System.Windows.Forms.Automation.AutomationLiveSetting.Polite;
- this.lblPortaErvas.Location = new System.Drawing.Point(14, 158);
- this.lblPortaErvas.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.lblPortaErvas.Name = "lblPortaErvas";
- this.lblPortaErvas.Size = new System.Drawing.Size(124, 25);
- this.lblPortaErvas.TabIndex = 34;
- this.lblPortaErvas.Text = "Porta Ervas";
- //
// gpbEquipamento
//
this.gpbEquipamento.Controls.Add(this.label3);
@@ -268,6 +208,64 @@
this.gpbEquipamento.TabStop = false;
this.gpbEquipamento.Text = "EQUIPAMENTO";
//
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(217, 200);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(51, 13);
+ this.label3.TabIndex = 38;
+ this.label3.Text = "Submask";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(68, 200);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(49, 13);
+ this.label1.TabIndex = 37;
+ this.label1.Text = "Gateway";
+ //
+ // txtEquipamentoGateway
+ //
+ this.txtEquipamentoGateway.Location = new System.Drawing.Point(123, 197);
+ this.txtEquipamentoGateway.Name = "txtEquipamentoGateway";
+ this.txtEquipamentoGateway.Size = new System.Drawing.Size(86, 20);
+ this.txtEquipamentoGateway.TabIndex = 36;
+ this.txtEquipamentoGateway.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ this.txtEquipamentoGateway.TextChanged += new System.EventHandler(this.txtEquipamentoGateway_TextChanged);
+ //
+ // txtEquipamentoSubmask
+ //
+ this.txtEquipamentoSubmask.Location = new System.Drawing.Point(274, 197);
+ this.txtEquipamentoSubmask.Name = "txtEquipamentoSubmask";
+ this.txtEquipamentoSubmask.Size = new System.Drawing.Size(86, 20);
+ this.txtEquipamentoSubmask.TabIndex = 35;
+ this.txtEquipamentoSubmask.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ this.txtEquipamentoSubmask.TextChanged += new System.EventHandler(this.txtEquipamentoSubmask_TextChanged);
+ //
+ // lblInterface
+ //
+ this.lblInterface.AutoSize = true;
+ this.lblInterface.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.lblInterface.Location = new System.Drawing.Point(14, 106);
+ this.lblInterface.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+ this.lblInterface.Name = "lblInterface";
+ this.lblInterface.Size = new System.Drawing.Size(95, 25);
+ this.lblInterface.TabIndex = 34;
+ this.lblInterface.Text = "Interface";
+ //
+ // cmbInterface
+ //
+ this.cmbInterface.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.cmbInterface.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.cmbInterface.FormattingEnabled = true;
+ this.cmbInterface.Location = new System.Drawing.Point(123, 97);
+ this.cmbInterface.Name = "cmbInterface";
+ this.cmbInterface.Size = new System.Drawing.Size(237, 39);
+ this.cmbInterface.TabIndex = 33;
+ this.cmbInterface.SelectedIndexChanged += new System.EventHandler(this.cmbInterface_SelectedIndexChanged);
+ //
// txtEquipamentoIP
//
this.txtEquipamentoIP.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@@ -312,29 +310,20 @@
this.lblEquipamentoSerial.TabIndex = 32;
this.lblEquipamentoSerial.Text = "Serial";
//
- // nudPortaCaminho
+ // gpbBase
//
- this.nudPortaCaminho.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.nudPortaCaminho.Location = new System.Drawing.Point(240, 98);
- this.nudPortaCaminho.Maximum = new decimal(new int[] {
- 9999,
- 0,
- 0,
- 0});
- this.nudPortaCaminho.Minimum = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.nudPortaCaminho.Name = "nudPortaCaminho";
- this.nudPortaCaminho.Size = new System.Drawing.Size(120, 38);
- this.nudPortaCaminho.TabIndex = 33;
- this.nudPortaCaminho.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
- this.nudPortaCaminho.Value = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
+ this.gpbBase.Controls.Add(this.nudPortaErvas);
+ this.gpbBase.Controls.Add(this.nudPortaCaminho);
+ this.gpbBase.Controls.Add(this.lblPortaErvas);
+ this.gpbBase.Controls.Add(this.txtBaseIP);
+ this.gpbBase.Controls.Add(this.lblBaseIP);
+ this.gpbBase.Controls.Add(this.lblPortaCaminho);
+ this.gpbBase.Location = new System.Drawing.Point(6, 19);
+ this.gpbBase.Name = "gpbBase";
+ this.gpbBase.Size = new System.Drawing.Size(374, 223);
+ this.gpbBase.TabIndex = 35;
+ this.gpbBase.TabStop = false;
+ this.gpbBase.Text = "BASE";
//
// nudPortaErvas
//
@@ -360,63 +349,74 @@
0,
0});
//
- // cmbInterface
+ // nudPortaCaminho
//
- this.cmbInterface.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmbInterface.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.cmbInterface.FormattingEnabled = true;
- this.cmbInterface.Location = new System.Drawing.Point(123, 97);
- this.cmbInterface.Name = "cmbInterface";
- this.cmbInterface.Size = new System.Drawing.Size(237, 39);
- this.cmbInterface.TabIndex = 33;
- this.cmbInterface.SelectedIndexChanged += new System.EventHandler(this.cmbInterface_SelectedIndexChanged);
+ this.nudPortaCaminho.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.nudPortaCaminho.Location = new System.Drawing.Point(240, 98);
+ this.nudPortaCaminho.Maximum = new decimal(new int[] {
+ 9999,
+ 0,
+ 0,
+ 0});
+ this.nudPortaCaminho.Minimum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.nudPortaCaminho.Name = "nudPortaCaminho";
+ this.nudPortaCaminho.Size = new System.Drawing.Size(120, 38);
+ this.nudPortaCaminho.TabIndex = 33;
+ this.nudPortaCaminho.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ this.nudPortaCaminho.Value = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
//
- // lblInterface
+ // lblPortaErvas
//
- this.lblInterface.AutoSize = true;
- this.lblInterface.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lblInterface.Location = new System.Drawing.Point(14, 106);
- this.lblInterface.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.lblInterface.Name = "lblInterface";
- this.lblInterface.Size = new System.Drawing.Size(95, 25);
- this.lblInterface.TabIndex = 34;
- this.lblInterface.Text = "Interface";
+ this.lblPortaErvas.AutoSize = true;
+ this.lblPortaErvas.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.lblPortaErvas.LiveSetting = System.Windows.Forms.Automation.AutomationLiveSetting.Polite;
+ this.lblPortaErvas.Location = new System.Drawing.Point(14, 158);
+ this.lblPortaErvas.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+ this.lblPortaErvas.Name = "lblPortaErvas";
+ this.lblPortaErvas.Size = new System.Drawing.Size(124, 25);
+ this.lblPortaErvas.TabIndex = 34;
+ this.lblPortaErvas.Text = "Porta Ervas";
//
- // txtEquipamentoSubmask
+ // gpbCameras
//
- this.txtEquipamentoSubmask.Location = new System.Drawing.Point(274, 197);
- this.txtEquipamentoSubmask.Name = "txtEquipamentoSubmask";
- this.txtEquipamentoSubmask.Size = new System.Drawing.Size(86, 20);
- this.txtEquipamentoSubmask.TabIndex = 35;
- this.txtEquipamentoSubmask.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
- this.txtEquipamentoSubmask.TextChanged += new System.EventHandler(this.txtEquipamentoSubmask_TextChanged);
+ this.gpbCameras.Controls.Add(this.picCaminho);
+ this.gpbCameras.Controls.Add(this.flwCamerasSolo);
+ this.gpbCameras.Controls.Add(this.picVoltar);
+ this.gpbCameras.Controls.Add(this.picSalvar);
+ this.gpbCameras.Controls.Add(this.picAtualizar);
+ this.gpbCameras.Controls.Add(this.btnCalibrarSonar);
+ this.gpbCameras.Controls.Add(this.cmbCameraCaminho);
+ this.gpbCameras.Location = new System.Drawing.Point(12, 12);
+ this.gpbCameras.Name = "gpbCameras";
+ this.gpbCameras.Size = new System.Drawing.Size(1000, 322);
+ this.gpbCameras.TabIndex = 41;
+ this.gpbCameras.TabStop = false;
+ this.gpbCameras.Text = "CÂMERAS";
//
- // txtEquipamentoGateway
+ // picCaminho
//
- this.txtEquipamentoGateway.Location = new System.Drawing.Point(123, 197);
- this.txtEquipamentoGateway.Name = "txtEquipamentoGateway";
- this.txtEquipamentoGateway.Size = new System.Drawing.Size(86, 20);
- this.txtEquipamentoGateway.TabIndex = 36;
- this.txtEquipamentoGateway.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
- this.txtEquipamentoGateway.TextChanged += new System.EventHandler(this.txtEquipamentoGateway_TextChanged);
+ this.picCaminho.BackColor = System.Drawing.Color.Black;
+ this.picCaminho.Location = new System.Drawing.Point(137, 19);
+ this.picCaminho.Name = "picCaminho";
+ this.picCaminho.Size = new System.Drawing.Size(320, 234);
+ this.picCaminho.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
+ this.picCaminho.TabIndex = 37;
+ this.picCaminho.TabStop = false;
//
- // label1
+ // flwCamerasSolo
//
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(68, 200);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(49, 13);
- this.label1.TabIndex = 37;
- this.label1.Text = "Gateway";
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(217, 200);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(51, 13);
- this.label3.TabIndex = 38;
- this.label3.Text = "Submask";
+ this.flwCamerasSolo.Location = new System.Drawing.Point(463, 19);
+ this.flwCamerasSolo.Name = "flwCamerasSolo";
+ this.flwCamerasSolo.Size = new System.Drawing.Size(531, 297);
+ this.flwCamerasSolo.TabIndex = 39;
//
// frmAjustes
//
@@ -440,14 +440,14 @@
((System.ComponentModel.ISupportInitialize)(this.picGravar)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picAtualizar)).EndInit();
this.gpbComunicacao.ResumeLayout(false);
- this.gpbCameras.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.picCaminho)).EndInit();
- this.gpbBase.ResumeLayout(false);
- this.gpbBase.PerformLayout();
this.gpbEquipamento.ResumeLayout(false);
this.gpbEquipamento.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.nudPortaCaminho)).EndInit();
+ this.gpbBase.ResumeLayout(false);
+ this.gpbBase.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPortaErvas)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.nudPortaCaminho)).EndInit();
+ this.gpbCameras.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.picCaminho)).EndInit();
this.ResumeLayout(false);
}
diff --git a/AgroBase/AgroBase/Forms/IHM/frmAjustes.cs b/AgroBase/AgroBase/Forms/IHM/frmAjustes.cs
index 0894aee64..4756f4c2a 100644
--- a/AgroBase/AgroBase/Forms/IHM/frmAjustes.cs
+++ b/AgroBase/AgroBase/Forms/IHM/frmAjustes.cs
@@ -445,7 +445,7 @@ namespace AgroBase.Forms.IHM
nudPortaCaminho.Value = p.base_porta_caminho;
nudPortaErvas.Value = p.base_porta_ervas;
- cmbInterface.Text = p.rover_interface;
+ cmbInterface.Text = p.comunicacao_interface;
txtEquipamentoSerial.Text = p.serial_number;
txtEquipamentoIP.Text = p.rover_ip;
txtEquipamentoGateway.Text = p.rover_gateway;
@@ -454,7 +454,7 @@ namespace AgroBase.Forms.IHM
var interfaces = EthernetService.ObterNomesInterfaces().Where(x => x.Contains("Ativa")).ToList();
cmbInterface.Items.Clear();
cmbInterface.Items.AddRange(interfaces.ToArray());
- cmbInterface.SelectedIndex = interfaces.IndexOf(interfaces.FirstOrDefault(x => x.Contains(p.rover_interface ?? "")));
+ cmbInterface.SelectedIndex = interfaces.IndexOf(interfaces.FirstOrDefault(x => x.Contains(p.comunicacao_interface ?? "")));
}
private async void SalvarParametrosConfiguracao()
@@ -469,7 +469,7 @@ namespace AgroBase.Forms.IHM
p.base_porta_caminho = (int)nudPortaCaminho.Value;
p.base_porta_ervas = (int)nudPortaErvas.Value;
- p.rover_interface = _interface;
+ p.comunicacao_interface = _interface;
p.rover_ip = txtEquipamentoIP.Text;
p.rover_gateway = txtEquipamentoGateway.Text;
p.rover_submask = txtEquipamentoSubmask.Text;
diff --git a/AgroBase/AgroBase/Forms/frmCanEthernetConfig.Designer.cs b/AgroBase/AgroBase/Forms/frmCanEthernetConfig.Designer.cs
new file mode 100644
index 000000000..76d3e6830
--- /dev/null
+++ b/AgroBase/AgroBase/Forms/frmCanEthernetConfig.Designer.cs
@@ -0,0 +1,804 @@
+namespace AgroBase.Forms
+{
+ partial class frmCanEthernetConfig
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.btnEncontrarDispositivo = new System.Windows.Forms.Button();
+ this.btnRequisitarDados = new System.Windows.Forms.Button();
+ this.btnGravarParametros = new System.Windows.Forms.Button();
+ this.label1 = new System.Windows.Forms.Label();
+ this.txtModelo = new System.Windows.Forms.TextBox();
+ this.txtTipo = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.txtVersaoFirmware = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.txtEnderecoSN = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.txtEnderecoMAC = new System.Windows.Forms.TextBox();
+ this.label5 = new System.Windows.Forms.Label();
+ this.cmbTipoFrame = new System.Windows.Forms.ComboBox();
+ this.label6 = new System.Windows.Forms.Label();
+ this.txtCANID = new System.Windows.Forms.TextBox();
+ this.label7 = new System.Windows.Forms.Label();
+ this.label8 = new System.Windows.Forms.Label();
+ this.cmbBaudRate = new System.Windows.Forms.ComboBox();
+ this.txtModDNS = new System.Windows.Forms.TextBox();
+ this.label9 = new System.Windows.Forms.Label();
+ this.txtModSubnet = new System.Windows.Forms.TextBox();
+ this.label10 = new System.Windows.Forms.Label();
+ this.txtModGateway = new System.Windows.Forms.TextBox();
+ this.label11 = new System.Windows.Forms.Label();
+ this.txtModIP = new System.Windows.Forms.TextBox();
+ this.label12 = new System.Windows.Forms.Label();
+ this.label13 = new System.Windows.Forms.Label();
+ this.cmdModoConversao = new System.Windows.Forms.ComboBox();
+ this.label14 = new System.Windows.Forms.Label();
+ this.txtDirecaoConversao = new System.Windows.Forms.ComboBox();
+ this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.rdbUDPServer = new System.Windows.Forms.RadioButton();
+ this.rdbUDPClient = new System.Windows.Forms.RadioButton();
+ this.rdbTCPServer = new System.Windows.Forms.RadioButton();
+ this.rdbTCPClient = new System.Windows.Forms.RadioButton();
+ this.txtQtdConexoes = new System.Windows.Forms.TextBox();
+ this.label15 = new System.Windows.Forms.Label();
+ this.txtServerIP = new System.Windows.Forms.TextBox();
+ this.label16 = new System.Windows.Forms.Label();
+ this.txtPortaLocal = new System.Windows.Forms.TextBox();
+ this.label17 = new System.Windows.Forms.Label();
+ this.txtPortaRemota = new System.Windows.Forms.TextBox();
+ this.label18 = new System.Windows.Forms.Label();
+ this.groupBox2 = new System.Windows.Forms.GroupBox();
+ this.rdbModoLoopback = new System.Windows.Forms.RadioButton();
+ this.rdbModoOnlyListen = new System.Windows.Forms.RadioButton();
+ this.cmbModoNormal = new System.Windows.Forms.RadioButton();
+ this.rtbComandosAT = new System.Windows.Forms.RichTextBox();
+ this.label19 = new System.Windows.Forms.Label();
+ this.btnReiniciarModulo = new System.Windows.Forms.Button();
+ this.btnAplicarPerfilAgrobot = new System.Windows.Forms.Button();
+ this.txtSubnet = new System.Windows.Forms.TextBox();
+ this.label21 = new System.Windows.Forms.Label();
+ this.txtGateway = new System.Windows.Forms.TextBox();
+ this.label22 = new System.Windows.Forms.Label();
+ this.txtIP = new System.Windows.Forms.TextBox();
+ this.label23 = new System.Windows.Forms.Label();
+ this.label20 = new System.Windows.Forms.Label();
+ this.cmbInterface = new System.Windows.Forms.ComboBox();
+ this.btnEntrarModoConfig = new System.Windows.Forms.Button();
+ this.btnSairModoConfig = new System.Windows.Forms.Button();
+ this.btnTestarTCP = new System.Windows.Forms.Button();
+ this.btnSalvarIP = new System.Windows.Forms.Button();
+ this.groupBox1.SuspendLayout();
+ this.groupBox2.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // btnEncontrarDispositivo
+ //
+ this.btnEncontrarDispositivo.Location = new System.Drawing.Point(12, 12);
+ this.btnEncontrarDispositivo.Name = "btnEncontrarDispositivo";
+ this.btnEncontrarDispositivo.Size = new System.Drawing.Size(149, 38);
+ this.btnEncontrarDispositivo.TabIndex = 0;
+ this.btnEncontrarDispositivo.Text = "Encontrar Dispositivo";
+ this.btnEncontrarDispositivo.UseVisualStyleBackColor = true;
+ this.btnEncontrarDispositivo.Click += new System.EventHandler(this.btnEncontrarDispositivo_Click);
+ //
+ // btnRequisitarDados
+ //
+ this.btnRequisitarDados.Location = new System.Drawing.Point(12, 56);
+ this.btnRequisitarDados.Name = "btnRequisitarDados";
+ this.btnRequisitarDados.Size = new System.Drawing.Size(149, 38);
+ this.btnRequisitarDados.TabIndex = 1;
+ this.btnRequisitarDados.Text = "Requisitar Dados";
+ this.btnRequisitarDados.UseVisualStyleBackColor = true;
+ this.btnRequisitarDados.Click += new System.EventHandler(this.btnRequisitarDados_Click);
+ //
+ // btnGravarParametros
+ //
+ this.btnGravarParametros.Location = new System.Drawing.Point(12, 100);
+ this.btnGravarParametros.Name = "btnGravarParametros";
+ this.btnGravarParametros.Size = new System.Drawing.Size(149, 38);
+ this.btnGravarParametros.TabIndex = 2;
+ this.btnGravarParametros.Text = "Gravar Parametros";
+ this.btnGravarParametros.UseVisualStyleBackColor = true;
+ this.btnGravarParametros.Click += new System.EventHandler(this.btnGravarParametros_Click);
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(187, 84);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(42, 13);
+ this.label1.TabIndex = 3;
+ this.label1.Text = "Modelo";
+ //
+ // txtModelo
+ //
+ this.txtModelo.Location = new System.Drawing.Point(190, 100);
+ this.txtModelo.Name = "txtModelo";
+ this.txtModelo.Size = new System.Drawing.Size(100, 20);
+ this.txtModelo.TabIndex = 4;
+ //
+ // txtTipo
+ //
+ this.txtTipo.Location = new System.Drawing.Point(296, 100);
+ this.txtTipo.Name = "txtTipo";
+ this.txtTipo.Size = new System.Drawing.Size(100, 20);
+ this.txtTipo.TabIndex = 6;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(293, 84);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(28, 13);
+ this.label2.TabIndex = 5;
+ this.label2.Text = "Tipo";
+ //
+ // txtVersaoFirmware
+ //
+ this.txtVersaoFirmware.Location = new System.Drawing.Point(402, 100);
+ this.txtVersaoFirmware.Name = "txtVersaoFirmware";
+ this.txtVersaoFirmware.Size = new System.Drawing.Size(100, 20);
+ this.txtVersaoFirmware.TabIndex = 8;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(399, 84);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(85, 13);
+ this.label3.TabIndex = 7;
+ this.label3.Text = "Versão Firmware";
+ //
+ // txtEnderecoSN
+ //
+ this.txtEnderecoSN.Location = new System.Drawing.Point(508, 100);
+ this.txtEnderecoSN.Name = "txtEnderecoSN";
+ this.txtEnderecoSN.Size = new System.Drawing.Size(100, 20);
+ this.txtEnderecoSN.TabIndex = 10;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(505, 84);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(71, 13);
+ this.label4.TabIndex = 9;
+ this.label4.Text = "Endereço SN";
+ //
+ // txtEnderecoMAC
+ //
+ this.txtEnderecoMAC.Location = new System.Drawing.Point(614, 100);
+ this.txtEnderecoMAC.Name = "txtEnderecoMAC";
+ this.txtEnderecoMAC.Size = new System.Drawing.Size(100, 20);
+ this.txtEnderecoMAC.TabIndex = 12;
+ //
+ // label5
+ //
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(611, 84);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(79, 13);
+ this.label5.TabIndex = 11;
+ this.label5.Text = "Endereço MAC";
+ //
+ // cmbTipoFrame
+ //
+ this.cmbTipoFrame.FormattingEnabled = true;
+ this.cmbTipoFrame.Location = new System.Drawing.Point(190, 167);
+ this.cmbTipoFrame.Name = "cmbTipoFrame";
+ this.cmbTipoFrame.Size = new System.Drawing.Size(100, 21);
+ this.cmbTipoFrame.TabIndex = 13;
+ //
+ // label6
+ //
+ this.label6.AutoSize = true;
+ this.label6.Location = new System.Drawing.Point(187, 151);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(75, 13);
+ this.label6.TabIndex = 14;
+ this.label6.Text = "Tipo de Frame";
+ //
+ // txtCANID
+ //
+ this.txtCANID.Location = new System.Drawing.Point(296, 167);
+ this.txtCANID.Name = "txtCANID";
+ this.txtCANID.Size = new System.Drawing.Size(100, 20);
+ this.txtCANID.TabIndex = 16;
+ //
+ // label7
+ //
+ this.label7.AutoSize = true;
+ this.label7.Location = new System.Drawing.Point(293, 151);
+ this.label7.Name = "label7";
+ this.label7.Size = new System.Drawing.Size(74, 13);
+ this.label7.TabIndex = 15;
+ this.label7.Text = "CAN ID (HEX)";
+ //
+ // label8
+ //
+ this.label8.AutoSize = true;
+ this.label8.Location = new System.Drawing.Point(399, 151);
+ this.label8.Name = "label8";
+ this.label8.Size = new System.Drawing.Size(55, 13);
+ this.label8.TabIndex = 18;
+ this.label8.Text = "BaudRate";
+ //
+ // cmbBaudRate
+ //
+ this.cmbBaudRate.FormattingEnabled = true;
+ this.cmbBaudRate.Location = new System.Drawing.Point(402, 167);
+ this.cmbBaudRate.Name = "cmbBaudRate";
+ this.cmbBaudRate.Size = new System.Drawing.Size(100, 21);
+ this.cmbBaudRate.TabIndex = 17;
+ //
+ // txtModDNS
+ //
+ this.txtModDNS.Location = new System.Drawing.Point(508, 207);
+ this.txtModDNS.Name = "txtModDNS";
+ this.txtModDNS.Size = new System.Drawing.Size(100, 20);
+ this.txtModDNS.TabIndex = 26;
+ //
+ // label9
+ //
+ this.label9.AutoSize = true;
+ this.label9.Location = new System.Drawing.Point(505, 191);
+ this.label9.Name = "label9";
+ this.label9.Size = new System.Drawing.Size(79, 13);
+ this.label9.TabIndex = 25;
+ this.label9.Text = "Endereço DNS";
+ //
+ // txtModSubnet
+ //
+ this.txtModSubnet.Location = new System.Drawing.Point(402, 207);
+ this.txtModSubnet.Name = "txtModSubnet";
+ this.txtModSubnet.Size = new System.Drawing.Size(100, 20);
+ this.txtModSubnet.TabIndex = 24;
+ //
+ // label10
+ //
+ this.label10.AutoSize = true;
+ this.label10.Location = new System.Drawing.Point(399, 191);
+ this.label10.Name = "label10";
+ this.label10.Size = new System.Drawing.Size(85, 13);
+ this.label10.TabIndex = 23;
+ this.label10.Text = "Máscara Subnet";
+ //
+ // txtModGateway
+ //
+ this.txtModGateway.Location = new System.Drawing.Point(296, 207);
+ this.txtModGateway.Name = "txtModGateway";
+ this.txtModGateway.Size = new System.Drawing.Size(100, 20);
+ this.txtModGateway.TabIndex = 22;
+ //
+ // label11
+ //
+ this.label11.AutoSize = true;
+ this.label11.Location = new System.Drawing.Point(293, 191);
+ this.label11.Name = "label11";
+ this.label11.Size = new System.Drawing.Size(49, 13);
+ this.label11.TabIndex = 21;
+ this.label11.Text = "Gateway";
+ //
+ // txtModIP
+ //
+ this.txtModIP.Location = new System.Drawing.Point(190, 207);
+ this.txtModIP.Name = "txtModIP";
+ this.txtModIP.Size = new System.Drawing.Size(100, 20);
+ this.txtModIP.TabIndex = 20;
+ //
+ // label12
+ //
+ this.label12.AutoSize = true;
+ this.label12.Location = new System.Drawing.Point(187, 191);
+ this.label12.Name = "label12";
+ this.label12.Size = new System.Drawing.Size(58, 13);
+ this.label12.TabIndex = 19;
+ this.label12.Text = "IP Estático";
+ //
+ // label13
+ //
+ this.label13.AutoSize = true;
+ this.label13.Location = new System.Drawing.Point(187, 263);
+ this.label13.Name = "label13";
+ this.label13.Size = new System.Drawing.Size(103, 13);
+ this.label13.TabIndex = 28;
+ this.label13.Text = "Modo de Conversão";
+ //
+ // cmdModoConversao
+ //
+ this.cmdModoConversao.FormattingEnabled = true;
+ this.cmdModoConversao.Location = new System.Drawing.Point(190, 279);
+ this.cmdModoConversao.Name = "cmdModoConversao";
+ this.cmdModoConversao.Size = new System.Drawing.Size(206, 21);
+ this.cmdModoConversao.TabIndex = 27;
+ //
+ // label14
+ //
+ this.label14.AutoSize = true;
+ this.label14.Location = new System.Drawing.Point(399, 263);
+ this.label14.Name = "label14";
+ this.label14.Size = new System.Drawing.Size(113, 13);
+ this.label14.TabIndex = 30;
+ this.label14.Text = "Direção da Conversão";
+ //
+ // txtDirecaoConversao
+ //
+ this.txtDirecaoConversao.FormattingEnabled = true;
+ this.txtDirecaoConversao.Location = new System.Drawing.Point(402, 279);
+ this.txtDirecaoConversao.Name = "txtDirecaoConversao";
+ this.txtDirecaoConversao.Size = new System.Drawing.Size(206, 21);
+ this.txtDirecaoConversao.TabIndex = 29;
+ //
+ // groupBox1
+ //
+ this.groupBox1.Controls.Add(this.rdbUDPServer);
+ this.groupBox1.Controls.Add(this.rdbUDPClient);
+ this.groupBox1.Controls.Add(this.rdbTCPServer);
+ this.groupBox1.Controls.Add(this.rdbTCPClient);
+ this.groupBox1.Location = new System.Drawing.Point(190, 329);
+ this.groupBox1.Name = "groupBox1";
+ this.groupBox1.Size = new System.Drawing.Size(524, 48);
+ this.groupBox1.TabIndex = 31;
+ this.groupBox1.TabStop = false;
+ this.groupBox1.Text = "Socket";
+ //
+ // rdbUDPServer
+ //
+ this.rdbUDPServer.AutoSize = true;
+ this.rdbUDPServer.Location = new System.Drawing.Point(418, 19);
+ this.rdbUDPServer.Name = "rdbUDPServer";
+ this.rdbUDPServer.Size = new System.Drawing.Size(82, 17);
+ this.rdbUDPServer.TabIndex = 3;
+ this.rdbUDPServer.TabStop = true;
+ this.rdbUDPServer.Text = "UDP Server";
+ this.rdbUDPServer.UseVisualStyleBackColor = true;
+ //
+ // rdbUDPClient
+ //
+ this.rdbUDPClient.AutoSize = true;
+ this.rdbUDPClient.Location = new System.Drawing.Point(276, 19);
+ this.rdbUDPClient.Name = "rdbUDPClient";
+ this.rdbUDPClient.Size = new System.Drawing.Size(77, 17);
+ this.rdbUDPClient.TabIndex = 2;
+ this.rdbUDPClient.TabStop = true;
+ this.rdbUDPClient.Text = "UDP Client";
+ this.rdbUDPClient.UseVisualStyleBackColor = true;
+ //
+ // rdbTCPServer
+ //
+ this.rdbTCPServer.AutoSize = true;
+ this.rdbTCPServer.Location = new System.Drawing.Point(126, 19);
+ this.rdbTCPServer.Name = "rdbTCPServer";
+ this.rdbTCPServer.Size = new System.Drawing.Size(80, 17);
+ this.rdbTCPServer.TabIndex = 1;
+ this.rdbTCPServer.TabStop = true;
+ this.rdbTCPServer.Text = "TCP Server";
+ this.rdbTCPServer.UseVisualStyleBackColor = true;
+ //
+ // rdbTCPClient
+ //
+ this.rdbTCPClient.AutoSize = true;
+ this.rdbTCPClient.Location = new System.Drawing.Point(6, 19);
+ this.rdbTCPClient.Name = "rdbTCPClient";
+ this.rdbTCPClient.Size = new System.Drawing.Size(75, 17);
+ this.rdbTCPClient.TabIndex = 0;
+ this.rdbTCPClient.TabStop = true;
+ this.rdbTCPClient.Text = "TCP Client";
+ this.rdbTCPClient.UseVisualStyleBackColor = true;
+ //
+ // txtQtdConexoes
+ //
+ this.txtQtdConexoes.Location = new System.Drawing.Point(190, 408);
+ this.txtQtdConexoes.Name = "txtQtdConexoes";
+ this.txtQtdConexoes.Size = new System.Drawing.Size(100, 20);
+ this.txtQtdConexoes.TabIndex = 33;
+ //
+ // label15
+ //
+ this.label15.AutoSize = true;
+ this.label15.Location = new System.Drawing.Point(187, 392);
+ this.label15.Name = "label15";
+ this.label15.Size = new System.Drawing.Size(74, 13);
+ this.label15.TabIndex = 32;
+ this.label15.Text = "Qtd Conexões";
+ //
+ // txtServerIP
+ //
+ this.txtServerIP.Location = new System.Drawing.Point(296, 408);
+ this.txtServerIP.Name = "txtServerIP";
+ this.txtServerIP.Size = new System.Drawing.Size(100, 20);
+ this.txtServerIP.TabIndex = 35;
+ //
+ // label16
+ //
+ this.label16.AutoSize = true;
+ this.label16.Location = new System.Drawing.Point(293, 392);
+ this.label16.Name = "label16";
+ this.label16.Size = new System.Drawing.Size(51, 13);
+ this.label16.TabIndex = 34;
+ this.label16.Text = "Server IP";
+ //
+ // txtPortaLocal
+ //
+ this.txtPortaLocal.Location = new System.Drawing.Point(402, 408);
+ this.txtPortaLocal.Name = "txtPortaLocal";
+ this.txtPortaLocal.Size = new System.Drawing.Size(100, 20);
+ this.txtPortaLocal.TabIndex = 37;
+ //
+ // label17
+ //
+ this.label17.AutoSize = true;
+ this.label17.Location = new System.Drawing.Point(399, 392);
+ this.label17.Name = "label17";
+ this.label17.Size = new System.Drawing.Size(61, 13);
+ this.label17.TabIndex = 36;
+ this.label17.Text = "Porta Local";
+ //
+ // txtPortaRemota
+ //
+ this.txtPortaRemota.Location = new System.Drawing.Point(508, 408);
+ this.txtPortaRemota.Name = "txtPortaRemota";
+ this.txtPortaRemota.Size = new System.Drawing.Size(100, 20);
+ this.txtPortaRemota.TabIndex = 39;
+ //
+ // label18
+ //
+ this.label18.AutoSize = true;
+ this.label18.Location = new System.Drawing.Point(505, 392);
+ this.label18.Name = "label18";
+ this.label18.Size = new System.Drawing.Size(72, 13);
+ this.label18.TabIndex = 38;
+ this.label18.Text = "Porta Remota";
+ //
+ // groupBox2
+ //
+ this.groupBox2.Controls.Add(this.rdbModoLoopback);
+ this.groupBox2.Controls.Add(this.rdbModoOnlyListen);
+ this.groupBox2.Controls.Add(this.cmbModoNormal);
+ this.groupBox2.Location = new System.Drawing.Point(190, 450);
+ this.groupBox2.Name = "groupBox2";
+ this.groupBox2.Size = new System.Drawing.Size(524, 48);
+ this.groupBox2.TabIndex = 32;
+ this.groupBox2.TabStop = false;
+ this.groupBox2.Text = "Modo de Trabalho";
+ //
+ // rdbModoLoopback
+ //
+ this.rdbModoLoopback.AutoSize = true;
+ this.rdbModoLoopback.Location = new System.Drawing.Point(276, 19);
+ this.rdbModoLoopback.Name = "rdbModoLoopback";
+ this.rdbModoLoopback.Size = new System.Drawing.Size(73, 17);
+ this.rdbModoLoopback.TabIndex = 2;
+ this.rdbModoLoopback.TabStop = true;
+ this.rdbModoLoopback.Text = "Loopback";
+ this.rdbModoLoopback.UseVisualStyleBackColor = true;
+ //
+ // rdbModoOnlyListen
+ //
+ this.rdbModoOnlyListen.AutoSize = true;
+ this.rdbModoOnlyListen.Location = new System.Drawing.Point(126, 19);
+ this.rdbModoOnlyListen.Name = "rdbModoOnlyListen";
+ this.rdbModoOnlyListen.Size = new System.Drawing.Size(77, 17);
+ this.rdbModoOnlyListen.TabIndex = 1;
+ this.rdbModoOnlyListen.TabStop = true;
+ this.rdbModoOnlyListen.Text = "Only Listen";
+ this.rdbModoOnlyListen.UseVisualStyleBackColor = true;
+ //
+ // cmbModoNormal
+ //
+ this.cmbModoNormal.AutoSize = true;
+ this.cmbModoNormal.Location = new System.Drawing.Point(6, 19);
+ this.cmbModoNormal.Name = "cmbModoNormal";
+ this.cmbModoNormal.Size = new System.Drawing.Size(58, 17);
+ this.cmbModoNormal.TabIndex = 0;
+ this.cmbModoNormal.TabStop = true;
+ this.cmbModoNormal.Text = "Normal";
+ this.cmbModoNormal.UseVisualStyleBackColor = true;
+ //
+ // rtbComandosAT
+ //
+ this.rtbComandosAT.Location = new System.Drawing.Point(734, 25);
+ this.rtbComandosAT.Name = "rtbComandosAT";
+ this.rtbComandosAT.Size = new System.Drawing.Size(363, 473);
+ this.rtbComandosAT.TabIndex = 40;
+ this.rtbComandosAT.Text = "";
+ //
+ // label19
+ //
+ this.label19.AutoSize = true;
+ this.label19.Location = new System.Drawing.Point(734, 9);
+ this.label19.Name = "label19";
+ this.label19.Size = new System.Drawing.Size(103, 13);
+ this.label19.TabIndex = 41;
+ this.label19.Text = "Log / Comandos AT";
+ //
+ // btnReiniciarModulo
+ //
+ this.btnReiniciarModulo.Location = new System.Drawing.Point(12, 144);
+ this.btnReiniciarModulo.Name = "btnReiniciarModulo";
+ this.btnReiniciarModulo.Size = new System.Drawing.Size(149, 38);
+ this.btnReiniciarModulo.TabIndex = 42;
+ this.btnReiniciarModulo.Text = "Reiniciar Módulo";
+ this.btnReiniciarModulo.UseVisualStyleBackColor = true;
+ this.btnReiniciarModulo.Click += new System.EventHandler(this.btnReiniciarModulo_Click);
+ //
+ // btnAplicarPerfilAgrobot
+ //
+ this.btnAplicarPerfilAgrobot.Location = new System.Drawing.Point(12, 188);
+ this.btnAplicarPerfilAgrobot.Name = "btnAplicarPerfilAgrobot";
+ this.btnAplicarPerfilAgrobot.Size = new System.Drawing.Size(149, 38);
+ this.btnAplicarPerfilAgrobot.TabIndex = 43;
+ this.btnAplicarPerfilAgrobot.Text = "Aplicar Perfil Agrobot";
+ this.btnAplicarPerfilAgrobot.UseVisualStyleBackColor = true;
+ this.btnAplicarPerfilAgrobot.Click += new System.EventHandler(this.btnAplicarPerfilAgrobot_Click);
+ //
+ // txtSubnet
+ //
+ this.txtSubnet.Location = new System.Drawing.Point(508, 30);
+ this.txtSubnet.Name = "txtSubnet";
+ this.txtSubnet.Size = new System.Drawing.Size(100, 20);
+ this.txtSubnet.TabIndex = 49;
+ //
+ // label21
+ //
+ this.label21.AutoSize = true;
+ this.label21.Location = new System.Drawing.Point(505, 14);
+ this.label21.Name = "label21";
+ this.label21.Size = new System.Drawing.Size(85, 13);
+ this.label21.TabIndex = 48;
+ this.label21.Text = "Máscara Subnet";
+ //
+ // txtGateway
+ //
+ this.txtGateway.Location = new System.Drawing.Point(402, 30);
+ this.txtGateway.Name = "txtGateway";
+ this.txtGateway.Size = new System.Drawing.Size(100, 20);
+ this.txtGateway.TabIndex = 47;
+ //
+ // label22
+ //
+ this.label22.AutoSize = true;
+ this.label22.Location = new System.Drawing.Point(399, 14);
+ this.label22.Name = "label22";
+ this.label22.Size = new System.Drawing.Size(49, 13);
+ this.label22.TabIndex = 46;
+ this.label22.Text = "Gateway";
+ //
+ // txtIP
+ //
+ this.txtIP.Location = new System.Drawing.Point(296, 30);
+ this.txtIP.Name = "txtIP";
+ this.txtIP.Size = new System.Drawing.Size(100, 20);
+ this.txtIP.TabIndex = 45;
+ //
+ // label23
+ //
+ this.label23.AutoSize = true;
+ this.label23.Location = new System.Drawing.Point(293, 14);
+ this.label23.Name = "label23";
+ this.label23.Size = new System.Drawing.Size(17, 13);
+ this.label23.TabIndex = 44;
+ this.label23.Text = "IP";
+ //
+ // label20
+ //
+ this.label20.AutoSize = true;
+ this.label20.Location = new System.Drawing.Point(187, 14);
+ this.label20.Name = "label20";
+ this.label20.Size = new System.Drawing.Size(49, 13);
+ this.label20.TabIndex = 51;
+ this.label20.Text = "Interface";
+ //
+ // cmbInterface
+ //
+ this.cmbInterface.FormattingEnabled = true;
+ this.cmbInterface.Location = new System.Drawing.Point(190, 30);
+ this.cmbInterface.Name = "cmbInterface";
+ this.cmbInterface.Size = new System.Drawing.Size(100, 21);
+ this.cmbInterface.TabIndex = 50;
+ this.cmbInterface.SelectedIndexChanged += new System.EventHandler(this.cmbInterface_SelectedIndexChanged);
+ //
+ // btnEntrarModoConfig
+ //
+ this.btnEntrarModoConfig.Location = new System.Drawing.Point(12, 232);
+ this.btnEntrarModoConfig.Name = "btnEntrarModoConfig";
+ this.btnEntrarModoConfig.Size = new System.Drawing.Size(149, 38);
+ this.btnEntrarModoConfig.TabIndex = 52;
+ this.btnEntrarModoConfig.Text = "Entrar no Modo Config";
+ this.btnEntrarModoConfig.UseVisualStyleBackColor = true;
+ //
+ // btnSairModoConfig
+ //
+ this.btnSairModoConfig.Location = new System.Drawing.Point(12, 276);
+ this.btnSairModoConfig.Name = "btnSairModoConfig";
+ this.btnSairModoConfig.Size = new System.Drawing.Size(149, 38);
+ this.btnSairModoConfig.TabIndex = 53;
+ this.btnSairModoConfig.Text = "Sair do Modo Config";
+ this.btnSairModoConfig.UseVisualStyleBackColor = true;
+ //
+ // btnTestarTCP
+ //
+ this.btnTestarTCP.Location = new System.Drawing.Point(12, 320);
+ this.btnTestarTCP.Name = "btnTestarTCP";
+ this.btnTestarTCP.Size = new System.Drawing.Size(149, 38);
+ this.btnTestarTCP.TabIndex = 54;
+ this.btnTestarTCP.Text = "Testar TCP";
+ this.btnTestarTCP.UseVisualStyleBackColor = true;
+ //
+ // btnSalvarIP
+ //
+ this.btnSalvarIP.Location = new System.Drawing.Point(615, 28);
+ this.btnSalvarIP.Name = "btnSalvarIP";
+ this.btnSalvarIP.Size = new System.Drawing.Size(99, 23);
+ this.btnSalvarIP.TabIndex = 55;
+ this.btnSalvarIP.Text = "Salvar";
+ this.btnSalvarIP.UseVisualStyleBackColor = true;
+ this.btnSalvarIP.Click += new System.EventHandler(this.btnSalvarIP_Click);
+ //
+ // frmCanEthernetConfig
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1109, 514);
+ this.Controls.Add(this.btnSalvarIP);
+ this.Controls.Add(this.btnTestarTCP);
+ this.Controls.Add(this.btnSairModoConfig);
+ this.Controls.Add(this.btnEntrarModoConfig);
+ this.Controls.Add(this.label20);
+ this.Controls.Add(this.cmbInterface);
+ this.Controls.Add(this.txtSubnet);
+ this.Controls.Add(this.label21);
+ this.Controls.Add(this.txtGateway);
+ this.Controls.Add(this.label22);
+ this.Controls.Add(this.txtIP);
+ this.Controls.Add(this.label23);
+ this.Controls.Add(this.btnAplicarPerfilAgrobot);
+ this.Controls.Add(this.btnReiniciarModulo);
+ this.Controls.Add(this.label19);
+ this.Controls.Add(this.rtbComandosAT);
+ this.Controls.Add(this.groupBox2);
+ this.Controls.Add(this.txtPortaRemota);
+ this.Controls.Add(this.label18);
+ this.Controls.Add(this.txtPortaLocal);
+ this.Controls.Add(this.label17);
+ this.Controls.Add(this.txtServerIP);
+ this.Controls.Add(this.label16);
+ this.Controls.Add(this.txtQtdConexoes);
+ this.Controls.Add(this.label15);
+ this.Controls.Add(this.groupBox1);
+ this.Controls.Add(this.label14);
+ this.Controls.Add(this.txtDirecaoConversao);
+ this.Controls.Add(this.label13);
+ this.Controls.Add(this.cmdModoConversao);
+ this.Controls.Add(this.txtModDNS);
+ this.Controls.Add(this.label9);
+ this.Controls.Add(this.txtModSubnet);
+ this.Controls.Add(this.label10);
+ this.Controls.Add(this.txtModGateway);
+ this.Controls.Add(this.label11);
+ this.Controls.Add(this.txtModIP);
+ this.Controls.Add(this.label12);
+ this.Controls.Add(this.label8);
+ this.Controls.Add(this.cmbBaudRate);
+ this.Controls.Add(this.txtCANID);
+ this.Controls.Add(this.label7);
+ this.Controls.Add(this.label6);
+ this.Controls.Add(this.cmbTipoFrame);
+ this.Controls.Add(this.txtEnderecoMAC);
+ this.Controls.Add(this.label5);
+ this.Controls.Add(this.txtEnderecoSN);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.txtVersaoFirmware);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.txtTipo);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.txtModelo);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.btnGravarParametros);
+ this.Controls.Add(this.btnRequisitarDados);
+ this.Controls.Add(this.btnEncontrarDispositivo);
+ this.Name = "frmCanEthernetConfig";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "Configuração do Conversor CAN Ethernet USR-CAN115";
+ this.groupBox1.ResumeLayout(false);
+ this.groupBox1.PerformLayout();
+ this.groupBox2.ResumeLayout(false);
+ this.groupBox2.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Button btnEncontrarDispositivo;
+ private System.Windows.Forms.Button btnRequisitarDados;
+ private System.Windows.Forms.Button btnGravarParametros;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox txtModelo;
+ private System.Windows.Forms.TextBox txtTipo;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox txtVersaoFirmware;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox txtEnderecoSN;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.TextBox txtEnderecoMAC;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.ComboBox cmbTipoFrame;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.TextBox txtCANID;
+ private System.Windows.Forms.Label label7;
+ private System.Windows.Forms.Label label8;
+ private System.Windows.Forms.ComboBox cmbBaudRate;
+ private System.Windows.Forms.TextBox txtModDNS;
+ private System.Windows.Forms.Label label9;
+ private System.Windows.Forms.TextBox txtModSubnet;
+ private System.Windows.Forms.Label label10;
+ private System.Windows.Forms.TextBox txtModGateway;
+ private System.Windows.Forms.Label label11;
+ private System.Windows.Forms.TextBox txtModIP;
+ private System.Windows.Forms.Label label12;
+ private System.Windows.Forms.Label label13;
+ private System.Windows.Forms.ComboBox cmdModoConversao;
+ private System.Windows.Forms.Label label14;
+ private System.Windows.Forms.ComboBox txtDirecaoConversao;
+ private System.Windows.Forms.GroupBox groupBox1;
+ private System.Windows.Forms.RadioButton rdbUDPServer;
+ private System.Windows.Forms.RadioButton rdbUDPClient;
+ private System.Windows.Forms.RadioButton rdbTCPServer;
+ private System.Windows.Forms.RadioButton rdbTCPClient;
+ private System.Windows.Forms.TextBox txtQtdConexoes;
+ private System.Windows.Forms.Label label15;
+ private System.Windows.Forms.TextBox txtServerIP;
+ private System.Windows.Forms.Label label16;
+ private System.Windows.Forms.TextBox txtPortaLocal;
+ private System.Windows.Forms.Label label17;
+ private System.Windows.Forms.TextBox txtPortaRemota;
+ private System.Windows.Forms.Label label18;
+ private System.Windows.Forms.GroupBox groupBox2;
+ private System.Windows.Forms.RadioButton rdbModoLoopback;
+ private System.Windows.Forms.RadioButton rdbModoOnlyListen;
+ private System.Windows.Forms.RadioButton cmbModoNormal;
+ private System.Windows.Forms.RichTextBox rtbComandosAT;
+ private System.Windows.Forms.Label label19;
+ private System.Windows.Forms.Button btnReiniciarModulo;
+ private System.Windows.Forms.Button btnAplicarPerfilAgrobot;
+ private System.Windows.Forms.TextBox txtSubnet;
+ private System.Windows.Forms.Label label21;
+ private System.Windows.Forms.TextBox txtGateway;
+ private System.Windows.Forms.Label label22;
+ private System.Windows.Forms.TextBox txtIP;
+ private System.Windows.Forms.Label label23;
+ private System.Windows.Forms.Label label20;
+ private System.Windows.Forms.ComboBox cmbInterface;
+ private System.Windows.Forms.Button btnEntrarModoConfig;
+ private System.Windows.Forms.Button btnSairModoConfig;
+ private System.Windows.Forms.Button btnTestarTCP;
+ private System.Windows.Forms.Button btnSalvarIP;
+ }
+}
\ No newline at end of file
diff --git a/AgroBase/AgroBase/Forms/frmCanEthernetConfig.cs b/AgroBase/AgroBase/Forms/frmCanEthernetConfig.cs
new file mode 100644
index 000000000..ea2c0bc97
--- /dev/null
+++ b/AgroBase/AgroBase/Forms/frmCanEthernetConfig.cs
@@ -0,0 +1,596 @@
+using AgroBase.Models;
+using System;
+using System.Data;
+using System.Linq;
+using System.Windows.Forms;
+using AgroBase.Services;
+
+namespace AgroBase.Forms
+{
+ public partial class frmCanEthernetConfig : Form
+ {
+ private UsrCan115Service _usrCanService;
+ private string _ipModuloAtual = "";
+
+ public frmCanEthernetConfig()
+ {
+ InitializeComponent();
+
+ _usrCanService = new UsrCan115Service(LogAT);
+
+ CarregarOpcoesTela();
+
+ VariaveisEquipamento.Parametros.AtualizarParametros();
+ var p = VariaveisEquipamento.Parametros;
+ cmbInterface.Text = p.comunicacao_interface;
+ txtIP.Text = p.can_ip_pc;
+ txtGateway.Text = p.can_gateway;
+ txtSubnet.Text = p.can_submask;
+
+ var interfaces = EthernetService.ObterNomesInterfaces().Where(x => x.Contains("Ativa")).ToList();
+ cmbInterface.Items.Clear();
+ cmbInterface.Items.AddRange(interfaces.ToArray());
+ cmbInterface.SelectedIndex = interfaces.IndexOf(interfaces.FirstOrDefault(x => x.Contains(p.can_interface ?? "")));
+ }
+
+ private void LogAT(string msg)
+ {
+ if (InvokeRequired)
+ {
+ BeginInvoke(new Action(() => LogAT(msg)));
+ return;
+ }
+
+ rtbComandosAT.AppendText($"{DateTime.Now:HH:mm:ss.fff} {msg}\n");
+ rtbComandosAT.ScrollToCaret();
+ }
+
+ private void CarregarOpcoesTela()
+ {
+ CarregarComboTipoFrame();
+ CarregarComboBaudRate();
+ CarregarComboModoConversao();
+ CarregarComboDirecaoConversao();
+
+ rdbTCPServer.Checked = true;
+ cmbModoNormal.Checked = true;
+ }
+
+ private void CarregarComboTipoFrame()
+ {
+ cmbTipoFrame.Items.Clear();
+
+ cmbTipoFrame.Items.Add(new ComboItem("Standard Frame", "0"));
+ cmbTipoFrame.Items.Add(new ComboItem("Extended Frame", "1"));
+
+ cmbTipoFrame.SelectedIndex = 0;
+ }
+
+ private void CarregarComboBaudRate()
+ {
+ cmbBaudRate.Items.Clear();
+
+ cmbBaudRate.Items.Add(new ComboItem("125K", "125"));
+ cmbBaudRate.Items.Add(new ComboItem("250K", "250"));
+ cmbBaudRate.Items.Add(new ComboItem("500K", "500"));
+ cmbBaudRate.Items.Add(new ComboItem("1000K", "1000"));
+
+ SelecionarComboPorValue(cmbBaudRate, "250");
+ }
+
+ private void CarregarComboModoConversao()
+ {
+ cmdModoConversao.Items.Clear();
+
+ cmdModoConversao.Items.Add(new ComboItem("Transparent Conversion", "TRANS"));
+ cmdModoConversao.Items.Add(new ComboItem("Transparent Band ID Conversion", "MARK"));
+ cmdModoConversao.Items.Add(new ComboItem("Standard Protocol Conversion", "PROTOL"));
+
+ SelecionarComboPorValue(cmdModoConversao, "PROTOL");
+ }
+
+ private void CarregarComboDirecaoConversao()
+ {
+ txtDirecaoConversao.Items.Clear();
+
+ txtDirecaoConversao.Items.Add(new ComboItem("Both way", "BOTHWAY"));
+ txtDirecaoConversao.Items.Add(new ComboItem("CAN to Network", "CANTONET"));
+ txtDirecaoConversao.Items.Add(new ComboItem("Network to CAN", "NETTOCAN"));
+
+ SelecionarComboPorValue(txtDirecaoConversao, "BOTHWAY");
+ }
+
+ private void SelecionarComboPorValue(ComboBox combo, string value)
+ {
+ if (combo == null || value == null)
+ return;
+
+ for (int i = 0; i < combo.Items.Count; i++)
+ {
+ if (combo.Items[i] is ComboItem item &&
+ string.Equals(item.Value, value, StringComparison.OrdinalIgnoreCase))
+ {
+ combo.SelectedIndex = i;
+ return;
+ }
+ }
+
+ combo.Text = value;
+ }
+
+ private void SelecionarComboPorText(ComboBox combo, string text)
+ {
+ if (combo == null || text == null)
+ return;
+
+ for (int i = 0; i < combo.Items.Count; i++)
+ {
+ if (combo.Items[i] is ComboItem item &&
+ string.Equals(item.Text, text, StringComparison.OrdinalIgnoreCase))
+ {
+ combo.SelectedIndex = i;
+ return;
+ }
+ }
+
+ combo.Text = text;
+ }
+
+ private string ObterComboValue(ComboBox combo)
+ {
+ if (combo?.SelectedItem is ComboItem item)
+ return item.Value;
+
+ return combo?.Text?.Trim();
+ }
+
+ private async void btnSalvarIP_Click(object sender, EventArgs e)
+ {
+ string _interface = cmbInterface.Text.Split('(')[0].Trim();
+ string _ipInterface = EthernetService.ObterIpAtual(_interface);
+
+ var p = VariaveisEquipamento.Parametros;
+ bool ip_mudou = p.can_ip_pc != txtIP.Text || p.can_gateway != txtGateway.Text || p.can_submask != txtSubnet.Text || p.can_ip_pc != _ipInterface;
+ bool ip_sucesso = !ip_mudou;
+
+ p.can_interface = _interface;
+ p.can_ip_pc = txtIP.Text;
+ p.can_gateway = txtGateway.Text;
+ p.can_submask = txtSubnet.Text;
+
+ if (!ip_sucesso)
+ ip_sucesso = await EthernetService.DefinirIpFixo(_interface, txtIP.Text, txtSubnet.Text, txtGateway.Text, false);
+
+ bool sucesso = ip_sucesso && VariaveisEquipamento.Parametros.SalvarParametros();
+ if (sucesso)
+ MessageBox.Show("Parametros de IP salvos com sucesso!");
+ else
+ MessageBox.Show("Erro ao definir parametros de IP!");
+ }
+
+ private void cmbInterface_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ string _interface = cmbInterface.Text.Split('(')[0].Trim();
+ txtIP.Text = EthernetService.ObterIpAtual(_interface);
+ txtGateway.Text = EthernetService.ObterIpGateway(_interface);
+ txtSubnet.Text = EthernetService.ObterSubnetMaskAtual(_interface);
+ }
+
+ private async void btnEncontrarDispositivo_Click(object sender, EventArgs e)
+ {
+ btnEncontrarDispositivo.Enabled = false;
+
+ try
+ {
+ LogAT("Buscando USR-CAN115 na rede...");
+
+ var dispositivos = await _usrCanService.EncontrarDispositivosAsync();
+
+ if (dispositivos.Count == 0)
+ {
+ LogAT("Nenhum dispositivo encontrado via broadcast.");
+
+ LogAT("Broadcast não encontrou. Tentando scan TCP na faixa local...");
+ var candidatosTcp = await _usrCanService.ScanTcpLocalAsync(8235);
+
+ MessageBox.Show(
+ "Nenhum USR-CAN115 foi encontrado. Verifique cabo, alimentação, interface de rede e se o módulo está ligado.",
+ "CAN Ethernet",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Warning);
+
+ return;
+ }
+
+ var dev = dispositivos.First();
+ _ipModuloAtual = dev.Ip; // IP real onde o módulo está respondendo agora
+ txtModIP.Text = dev.Ip;
+
+ if (!string.IsNullOrWhiteSpace(dev.Model))
+ txtModelo.Text = dev.Model;
+
+ if (!string.IsNullOrWhiteSpace(dev.Mac))
+ txtEnderecoMAC.Text = dev.Mac;
+
+ if (!string.IsNullOrWhiteSpace(dev.Firmware))
+ txtVersaoFirmware.Text = dev.Firmware;
+
+ LogAT($"Dispositivo encontrado: IP={dev.Ip}, Modelo={dev.Model}, MAC={dev.Mac}");
+
+ MessageBox.Show(
+ $"Dispositivo encontrado em {dev.Ip}",
+ "CAN Ethernet",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ LogAT($"Erro ao buscar dispositivo: {ex.Message}");
+
+ MessageBox.Show(
+ ex.Message,
+ "Erro ao buscar CAN Ethernet",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ finally
+ {
+ btnEncontrarDispositivo.Enabled = true;
+ }
+ }
+
+ private async void btnRequisitarDados_Click(object sender, EventArgs e)
+ {
+ btnRequisitarDados.Enabled = false;
+
+ try
+ {
+ string ip = txtModIP.Text.Trim();
+
+ if (string.IsNullOrWhiteSpace(ip))
+ {
+ MessageBox.Show(
+ "Informe ou encontre primeiro o IP do USR-CAN115.",
+ "CAN Ethernet",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Warning);
+ return;
+ }
+
+ LogAT($"Requisitando parâmetros do USR-CAN115 em {ip}...");
+
+ var config = await _usrCanService.LerParametrosAsync(txtIP.Text, ip);
+ if (config.Raw.Count == 0)
+ throw new Exception("Nenhum parâmetro foi recebido do USR-CAN115. Verifique se o envio AT está usando broadcast UDP 48899 pela interface correta.");
+
+ PreencherTela(config);
+
+ LogAT("Parâmetros carregados com sucesso.");
+
+ _ipModuloAtual = ip;
+ }
+ catch (Exception ex)
+ {
+ LogAT($"Erro ao requisitar parâmetros: {ex.Message}");
+
+ MessageBox.Show(
+ ex.Message,
+ "Erro ao requisitar parâmetros",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ finally
+ {
+ btnRequisitarDados.Enabled = true;
+ }
+ }
+
+ private void PreencherTela(UsrCan115Config c)
+ {
+ txtModelo.Text = c.Model ?? "";
+ txtVersaoFirmware.Text = c.Firmware ?? "";
+ txtEnderecoMAC.Text = c.Mac ?? "";
+ txtEnderecoSN.Text = c.SerialNumber ?? "";
+
+ if (!string.IsNullOrWhiteSpace(c.FrameType))
+ SelecionarComboPorText(cmbTipoFrame, c.FrameType);
+
+ txtCANID.Text = string.IsNullOrWhiteSpace(c.CanIdHex) ? "0" : c.CanIdHex;
+
+ if (c.CanBaudRate > 0)
+ SelecionarComboPorValue(cmbBaudRate, c.CanBaudRate.ToString());
+
+ txtModIP.Text = c.Ip ?? "";
+ txtModSubnet.Text = c.Subnet ?? "";
+ txtModGateway.Text = c.Gateway ?? "";
+ txtModDNS.Text = c.Dns ?? "";
+
+ if (!string.IsNullOrWhiteSpace(c.ConversionMode))
+ SelecionarComboPorText(cmdModoConversao, c.ConversionMode);
+
+ if (!string.IsNullOrWhiteSpace(c.ConversionDirection))
+ SelecionarComboPorText(txtDirecaoConversao, c.ConversionDirection);
+
+ rdbTCPClient.Checked = c.SocketMode == "TCPC";
+ rdbTCPServer.Checked = c.SocketMode == "TCPS";
+ rdbUDPClient.Checked = c.SocketMode == "UDPC";
+ rdbUDPServer.Checked = c.SocketMode == "UDPS";
+
+ txtServerIP.Text = c.ServerIp ?? "";
+ txtQtdConexoes.Text = c.MaxConnections > 0 ? c.MaxConnections.ToString() : "";
+
+ txtPortaLocal.Text = c.LocalPort > 0 ? c.LocalPort.ToString() : "";
+ txtPortaRemota.Text = c.RemotePort > 0 ? c.RemotePort.ToString() : "";
+
+ cmbModoNormal.Checked = c.CanMode == "Normal";
+ rdbModoOnlyListen.Checked = c.CanMode == "Only Listen";
+ rdbModoLoopback.Checked = c.CanMode == "Loopback";
+ }
+
+
+ private void btnAplicarPerfilAgrobot_Click(object sender, EventArgs e)
+ {
+ SelecionarComboPorValue(cmbTipoFrame, "0");
+ txtCANID.Text = "0";
+
+ SelecionarComboPorValue(cmbBaudRate, "250");
+
+ txtModIP.Text = "192.168.0.7";
+ txtModGateway.Text = "192.168.0.1";
+ txtModSubnet.Text = "255.255.255.0";
+ txtModDNS.Text = "208.67.222.222";
+
+ SelecionarComboPorValue(cmdModoConversao, "PROTOL");
+ SelecionarComboPorValue(txtDirecaoConversao, "BOTHWAY");
+
+ rdbTCPClient.Checked = false;
+ rdbTCPServer.Checked = true;
+ rdbUDPClient.Checked = false;
+ rdbUDPServer.Checked = false;
+
+ txtQtdConexoes.Text = "2";
+ txtServerIP.Text = txtModIP.Text;
+ txtPortaLocal.Text = "8235";
+ txtPortaRemota.Text = "8234";
+
+ cmbModoNormal.Checked = true;
+ rdbModoOnlyListen.Checked = false;
+ rdbModoLoopback.Checked = false;
+
+ LogAT("Perfil Agrobot aplicado na tela. Revise e clique em Gravar Parâmetros para enviar ao módulo.");
+ }
+
+
+ private UsrCan115Config ObterConfigDaTela()
+ {
+ var c = new UsrCan115Config();
+
+ c.Model = txtModelo.Text.Trim();
+ c.Firmware = txtVersaoFirmware.Text.Trim();
+ c.Mac = txtEnderecoMAC.Text.Trim();
+ c.SerialNumber = txtEnderecoSN.Text.Trim();
+
+ c.FrameType = ObterComboValue(cmbTipoFrame); // "0" ou "1"
+ c.CanIdHex = txtCANID.Text.Trim();
+ c.CanBaudRate = int.TryParse(ObterComboValue(cmbBaudRate), out int br) ? br : 250;
+
+ c.IpMode = "STATIC";
+ c.Ip = txtModIP.Text.Trim();
+ c.Gateway = txtModGateway.Text.Trim();
+ c.Subnet = txtModSubnet.Text.Trim();
+ c.Dns = txtModDNS.Text.Trim();
+
+ c.ConversionMode = ObterComboValue(cmdModoConversao); // TRANS / MARK / PROTOL
+ c.ConversionDirection = ObterComboValue(txtDirecaoConversao); // BOTHWAY / CANTONET / NETTOCAN
+
+ c.SocketMode =
+ rdbTCPClient.Checked ? "TCPC" :
+ rdbTCPServer.Checked ? "TCPS" :
+ rdbUDPClient.Checked ? "UDPC" :
+ rdbUDPServer.Checked ? "UDPS" :
+ "TCPS";
+
+ c.ServerIp = txtServerIP.Text.Trim();
+
+ c.LocalPort = int.TryParse(txtPortaLocal.Text.Trim(), out int localPort) ? localPort : 8235;
+ c.RemotePort = int.TryParse(txtPortaRemota.Text.Trim(), out int remotePort) ? remotePort : 8234;
+ c.MaxConnections = int.TryParse(txtQtdConexoes.Text.Trim(), out int maxConn) ? maxConn : 2;
+
+ c.CanMode =
+ cmbModoNormal.Checked ? "NORMAL" :
+ rdbModoOnlyListen.Checked ? "LISTEN" :
+ rdbModoLoopback.Checked ? "LOOPBACK" :
+ "NORMAL";
+
+ return c;
+ }
+
+ private bool ValidarConfigParaGravar(UsrCan115Config c)
+ {
+ if (string.IsNullOrWhiteSpace(c.Ip))
+ {
+ MessageBox.Show("Informe o IP estático do módulo.", "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
+ }
+
+ if (string.IsNullOrWhiteSpace(c.Subnet))
+ {
+ MessageBox.Show("Informe a máscara de subnet do módulo.", "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
+ }
+
+ if (c.LocalPort <= 0 || c.LocalPort > 65535)
+ {
+ MessageBox.Show("Porta local inválida.", "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
+ }
+
+ if (c.SocketMode == "TCPC" || c.SocketMode == "UDPC")
+ {
+ if (string.IsNullOrWhiteSpace(c.ServerIp))
+ {
+ MessageBox.Show("Em modo Client, informe o Server IP.", "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
+ }
+
+ if (c.RemotePort <= 0 || c.RemotePort > 65535)
+ {
+ MessageBox.Show("Porta remota inválida.", "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private async void btnGravarParametros_Click(object sender, EventArgs e)
+ {
+ btnGravarParametros.Enabled = false;
+
+ try
+ {
+ string ipPc = txtIP.Text.Trim();
+ string ipModuloAtual = _ipModuloAtual;
+
+ if (string.IsNullOrWhiteSpace(ipModuloAtual))
+ {
+ MessageBox.Show("Encontre ou requisite os dados do módulo antes de gravar.",
+ "CAN Ethernet", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ var config = ObterConfigDaTela(); // aqui config.Ip pode ser o IP novo, ex: 192.168.0.40
+
+ if (!ValidarConfigParaGravar(config))
+ return;
+
+ var resp = MessageBox.Show(
+ "Deseja gravar os parâmetros no USR-CAN115?\n\n" +
+ "Atenção: se alterar o IP do módulo para outra faixa, talvez seja necessário mudar o IP da interface do PC depois.",
+ "Gravar parâmetros",
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Question);
+
+ if (resp != DialogResult.Yes)
+ return;
+
+ LogAT("Gravando parâmetros no USR-CAN115...");
+
+ var result = await _usrCanService.GravarParametrosAsync(ipPc, ipModuloAtual, config);
+
+ LogAT(result.Mensagem);
+
+ if (result.Sucesso)
+ {
+ var p = VariaveisEquipamento.Parametros;
+ p.can_ip_modulo = txtModIP.Text;
+ p.can_porta = Convert.ToInt32(txtPortaLocal.Text);
+ bool sucesso = VariaveisEquipamento.Parametros.SalvarParametros();
+
+ MessageBox.Show(result.Mensagem, "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show(result.Mensagem, "CAN Ethernet",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogAT($"Erro ao gravar parâmetros: {ex.Message}");
+
+ MessageBox.Show(
+ ex.Message,
+ "Erro ao gravar parâmetros",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ finally
+ {
+ btnGravarParametros.Enabled = true;
+ }
+ }
+
+
+ private async void btnReiniciarModulo_Click(object sender, EventArgs e)
+ {
+ btnReiniciarModulo.Enabled = false;
+
+ try
+ {
+ string ipPc = txtIP.Text.Trim();
+ string ipModuloAtual = !string.IsNullOrWhiteSpace(_ipModuloAtual)
+ ? _ipModuloAtual
+ : txtModIP.Text.Trim();
+
+ if (string.IsNullOrWhiteSpace(ipPc) || string.IsNullOrWhiteSpace(ipModuloAtual))
+ {
+ MessageBox.Show("Informe o IP do PC e encontre o módulo antes de reiniciar.",
+ "CAN Ethernet", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ var resp = MessageBox.Show(
+ "Deseja reiniciar o USR-CAN115 agora?",
+ "Reiniciar módulo",
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Question);
+
+ if (resp != DialogResult.Yes)
+ return;
+
+ LogAT("Reiniciando USR-CAN115...");
+
+ bool ok = await _usrCanService.ReiniciarModuloAsync(ipPc, ipModuloAtual);
+
+ LogAT(ok
+ ? "Comando de reinício aceito pelo módulo."
+ : "Comando enviado. O módulo pode ter reiniciado mesmo sem resposta OK.");
+
+ MessageBox.Show(
+ "Comando de reinício enviado. Aguarde alguns segundos e clique em Encontrar Dispositivo novamente.",
+ "CAN Ethernet",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ LogAT($"Erro ao reiniciar módulo: {ex.Message}");
+
+ MessageBox.Show(ex.Message,
+ "Erro ao reiniciar módulo",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ finally
+ {
+ btnReiniciarModulo.Enabled = true;
+ }
+ }
+
+ }
+
+ public class ComboItem
+ {
+ public string Text { get; set; }
+ public string Value { get; set; }
+
+ public ComboItem(string text, string value)
+ {
+ Text = text;
+ Value = value;
+ }
+
+ public override string ToString()
+ {
+ return Text;
+ }
+ }
+
+}
diff --git a/AgroBase/AgroBase/Forms/frmCanEthernetConfig.resx b/AgroBase/AgroBase/Forms/frmCanEthernetConfig.resx
new file mode 100644
index 000000000..1af7de150
--- /dev/null
+++ b/AgroBase/AgroBase/Forms/frmCanEthernetConfig.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AgroBase/AgroBase/Forms/frmPrincipal.Designer.cs b/AgroBase/AgroBase/Forms/frmPrincipal.Designer.cs
index e8294831f..fa8db3474 100644
--- a/AgroBase/AgroBase/Forms/frmPrincipal.Designer.cs
+++ b/AgroBase/AgroBase/Forms/frmPrincipal.Designer.cs
@@ -94,6 +94,7 @@ namespace AgroBase
this.btnForcarAtualizacao = new System.Windows.Forms.Button();
this.clbRotinas = new System.Windows.Forms.CheckedListBox();
this.btnAtualizarRotinas = new System.Windows.Forms.Button();
+ this.btnUsrCan115 = new System.Windows.Forms.Button();
this.gpbAcoes.SuspendLayout();
this.erroStrip.SuspendLayout();
this.pnlLateral.SuspendLayout();
@@ -490,6 +491,7 @@ namespace AgroBase
// pnlAtalhos
//
this.pnlAtalhos.AutoScroll = true;
+ this.pnlAtalhos.Controls.Add(this.btnUsrCan115);
this.pnlAtalhos.Controls.Add(this.btnSimuladorMapeamentoVisual);
this.pnlAtalhos.Controls.Add(this.btnVisualWorker);
this.pnlAtalhos.Controls.Add(this.btnTreinamentoIA);
@@ -829,6 +831,17 @@ namespace AgroBase
this.btnAtualizarRotinas.UseVisualStyleBackColor = true;
this.btnAtualizarRotinas.Click += new System.EventHandler(this.btnAtualizarRotinas_Click);
//
+ // btnUsrCan115
+ //
+ this.btnUsrCan115.Location = new System.Drawing.Point(5, 511);
+ this.btnUsrCan115.Margin = new System.Windows.Forms.Padding(2);
+ this.btnUsrCan115.Name = "btnUsrCan115";
+ this.btnUsrCan115.Size = new System.Drawing.Size(84, 20);
+ this.btnUsrCan115.TabIndex = 35;
+ this.btnUsrCan115.Text = "USR-CAN115";
+ this.btnUsrCan115.UseVisualStyleBackColor = true;
+ this.btnUsrCan115.Click += new System.EventHandler(this.btnUsrCan115_Click);
+ //
// frmPrincipal
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -945,6 +958,7 @@ namespace AgroBase
private System.Windows.Forms.Button btnVisualWorker;
private System.Windows.Forms.Button btnSimuladorMapeamentoVisual;
public System.Windows.Forms.ComboBox cmbModoOperacao;
+ private System.Windows.Forms.Button btnUsrCan115;
}
}
diff --git a/AgroBase/AgroBase/Forms/frmPrincipal.cs b/AgroBase/AgroBase/Forms/frmPrincipal.cs
index 58e4ec878..b1ca77109 100644
--- a/AgroBase/AgroBase/Forms/frmPrincipal.cs
+++ b/AgroBase/AgroBase/Forms/frmPrincipal.cs
@@ -463,6 +463,12 @@ namespace AgroBase
frm.Show();
}
+ private void btnUsrCan115_Click(object sender, EventArgs e)
+ {
+ frmCanEthernetConfig frm = new frmCanEthernetConfig();
+ frm.Show();
+ }
+
#endregion
private void lblStripOperacaoLiberada_Click(object sender, EventArgs e)
diff --git a/AgroBase/AgroBase/Models/UsrCan115Model.cs b/AgroBase/AgroBase/Models/UsrCan115Model.cs
new file mode 100644
index 000000000..7294c01f0
--- /dev/null
+++ b/AgroBase/AgroBase/Models/UsrCan115Model.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AgroBase.Models
+{
+ internal class UsrCan115Model
+ {
+ }
+
+ public class UsrCan115DeviceInfo
+ {
+ public string Ip { get; set; }
+ public string Model { get; set; }
+ public string Mac { get; set; }
+ public string Firmware { get; set; }
+ public string RawResponse { get; set; }
+ }
+
+ public class InterfaceBroadcastInfo
+ {
+ public IPAddress LocalIp { get; set; }
+ public IPAddress BroadcastIp { get; set; }
+ public string Nome { get; set; }
+ }
+
+ public class UsrCan115WriteResult
+ {
+ public bool Sucesso { get; set; }
+ public int OkCount { get; set; }
+ public int ErrCount { get; set; }
+ public string Raw { get; set; }
+ public string Mensagem { get; set; }
+ }
+
+ public class UsrCan115Config
+ {
+ public string Model { get; set; }
+ public string Firmware { get; set; }
+ public string Mac { get; set; }
+ public string SerialNumber { get; set; }
+ public string ProductType { get; set; }
+
+ public int CanBaudRate { get; set; }
+ public string FrameType { get; set; }
+ public string CanIdHex { get; set; }
+ public string CanMode { get; set; }
+
+ public string IpMode { get; set; }
+ public string Ip { get; set; }
+ public string Subnet { get; set; }
+ public string Gateway { get; set; }
+ public string Dns { get; set; }
+
+ public string ConversionMode { get; set; }
+ public string ConversionDirection { get; set; }
+
+ public string SocketMode { get; set; }
+ public string ServerIp { get; set; }
+ public int LocalPort { get; set; }
+ public int RemotePort { get; set; }
+ public int MaxConnections { get; set; }
+
+ public string ShortLink { get; set; }
+ public string UdpFilter { get; set; }
+ public string TcpOverLimit { get; set; }
+ public int ReconnectTime { get; set; }
+
+ public string HeartbeatEnabled { get; set; }
+ public int HeartbeatTime { get; set; }
+ public string HeartbeatData { get; set; }
+
+ public string RegisterEnabled { get; set; }
+ public string RegisterSendMode { get; set; }
+ public string RegisterData { get; set; }
+
+ public string CanPack { get; set; }
+ public string ClearBuffer { get; set; }
+ public int RestartTime { get; set; }
+
+ public Dictionary Raw { get; set; } = new Dictionary();
+ }
+
+}
diff --git a/AgroBase/AgroBase/Models/Variaveis.cs b/AgroBase/AgroBase/Models/Variaveis.cs
index 72626ddd4..7ecacadf0 100644
--- a/AgroBase/AgroBase/Models/Variaveis.cs
+++ b/AgroBase/AgroBase/Models/Variaveis.cs
@@ -798,12 +798,18 @@ namespace AgroBase.Models
public string base_ip { get; set; }
public int base_porta_caminho { get; set; }
public int base_porta_ervas { get; set; }
- public string rover_interface { get; set; }
+ public string comunicacao_interface { get; set; }
public string rover_ip { get; set; }
public string rover_gateway { get; set; }
public string rover_submask { get; set; }
public string camera_caminhho_id { get; set; }
public List camera_ervas_id { get; set; }
+ public string can_interface { get; set; }
+ public string can_ip_pc { get; set; }
+ public string can_ip_modulo { get; set; }
+ public int can_porta { get; set; }
+ public string can_gateway { get; set; }
+ public string can_submask { get; set; }
public void AtualizarParametros()
{
@@ -821,11 +827,18 @@ namespace AgroBase.Models
base_porta_caminho = par.base_porta_caminho;
base_porta_ervas = par.base_porta_ervas;
- rover_interface = par.rover_interface;
+ comunicacao_interface = par.comunicacao_interface;
rover_ip = par.rover_ip;
rover_gateway = par.rover_gateway;
rover_submask = par.rover_submask;
-
+
+ can_interface = par.can_interface;
+ can_ip_pc = par.can_ip_pc;
+ can_ip_modulo = par.can_ip_modulo;
+ can_porta = par.can_porta;
+ can_gateway = par.can_gateway;
+ can_submask = par.can_submask;
+
camera_caminhho_id = par.camera_caminhho_id;
camera_ervas_id = par.camera_ervas_id;
diff --git a/AgroBase/AgroBase/Services/CANService.cs b/AgroBase/AgroBase/Services/CANService.cs
index 27c00fe25..00b14b497 100644
--- a/AgroBase/AgroBase/Services/CANService.cs
+++ b/AgroBase/AgroBase/Services/CANService.cs
@@ -1,4 +1,5 @@
-using System;
+using AgroBase.Models;
+using System;
using System.IO.Ports;
using static AgroBase.Models.Enums;
@@ -20,8 +21,8 @@ namespace AgroBase.Services
private static CanServiceEthernet CanEthernet = new CanServiceEthernet
{
- IpAddress = "192.168.0.7",
- Port = 8235,
+ IpAddress = VariaveisEquipamento.Parametros.can_ip_modulo,
+ Port = VariaveisEquipamento.Parametros.can_porta,
TransportMode = CanEthernetTransportMode.Tcp
};
diff --git a/AgroBase/AgroBase/Services/SerialService.cs b/AgroBase/AgroBase/Services/SerialService.cs
index adb9b9f39..27387fb61 100644
--- a/AgroBase/AgroBase/Services/SerialService.cs
+++ b/AgroBase/AgroBase/Services/SerialService.cs
@@ -38,7 +38,7 @@ namespace AgroBase.Services
new DispositivoDetalhesModel()
{
Dispositivo = T_Code.Npc,
- Endereco = EthernetService.ObterIpAtual(VariaveisEquipamento.Parametros.rover_interface),
+ Endereco = EthernetService.ObterIpAtual(VariaveisEquipamento.Parametros.comunicacao_interface),
Versao = Variaveis.Versao,
Mod_ID = ""
}
diff --git a/AgroBase/AgroBase/Services/UsrCan115Service.cs b/AgroBase/AgroBase/Services/UsrCan115Service.cs
new file mode 100644
index 000000000..c79a6a0ca
--- /dev/null
+++ b/AgroBase/AgroBase/Services/UsrCan115Service.cs
@@ -0,0 +1,867 @@
+using AgroBase.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Net.Sockets;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using System.Collections.Concurrent;
+
+namespace AgroBase.Services
+{
+ public class UsrCan115Service
+ {
+ private const int SearchPort = 48899;
+ private readonly Action _log;
+
+ public UsrCan115Service(Action log = null)
+ {
+ _log = log;
+ }
+
+ private void Log(string msg)
+ {
+ _log?.Invoke(msg);
+ }
+
+ private IEnumerable ObterInterfacesIpv4ComBroadcast()
+ {
+ foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (ni.OperationalStatus != OperationalStatus.Up)
+ continue;
+
+ if (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback)
+ continue;
+
+ var props = ni.GetIPProperties();
+
+ foreach (var unicast in props.UnicastAddresses)
+ {
+ if (unicast.Address.AddressFamily != AddressFamily.InterNetwork)
+ continue;
+
+ if (unicast.IPv4Mask == null)
+ continue;
+
+ yield return new InterfaceBroadcastInfo
+ {
+ LocalIp = unicast.Address,
+ BroadcastIp = CalcularBroadcast(unicast.Address, unicast.IPv4Mask),
+ Nome = ni.Name
+ };
+ }
+ }
+ }
+
+ public async Task> EncontrarDispositivosAsync(int timeoutMs = 1500)
+ {
+ var encontrados = new List();
+
+ foreach (var item in ObterInterfacesIpv4ComBroadcast())
+ {
+ var r = await BuscarViaBroadcastAsync(item.LocalIp, item.BroadcastIp, timeoutMs);
+ encontrados.AddRange(r);
+ }
+
+ return encontrados
+ .GroupBy(x => string.IsNullOrWhiteSpace(x.Mac) ? x.Ip : x.Mac)
+ .Select(g => g.First())
+ .ToList();
+ }
+
+ private async Task> BuscarViaBroadcastAsync(IPAddress localIp, IPAddress broadcastIp, int timeoutMs)
+ {
+ var encontrados = new List();
+
+ using (var udp = new UdpClient(new IPEndPoint(localIp, 0)))
+ {
+ udp.EnableBroadcast = true;
+
+ string[] comandos =
+ {
+ "www.usr.cn"
+ };
+
+ var endpoint = new IPEndPoint(broadcastIp, SearchPort);
+
+ foreach (var cmd in comandos)
+ {
+ byte[] data = Encoding.ASCII.GetBytes(cmd);
+ await udp.SendAsync(data, data.Length, endpoint);
+
+ Log($"[TX UDP {localIp} -> {broadcastIp}:{SearchPort}] {cmd.Replace("\r", "\\r").Replace("\n", "\\n")}");
+ await Task.Delay(30);
+ }
+
+ var inicio = DateTime.UtcNow;
+
+ while ((DateTime.UtcNow - inicio).TotalMilliseconds < timeoutMs)
+ {
+ try
+ {
+ var receiveTask = udp.ReceiveAsync();
+ var delayTask = Task.Delay(150);
+
+ var completed = await Task.WhenAny(receiveTask, delayTask);
+ if (completed != receiveTask)
+ continue;
+
+ var result = receiveTask.Result;
+ string raw = Encoding.ASCII.GetString(result.Buffer);
+
+ Log($"[RX UDP {result.RemoteEndPoint}] {raw.Replace("\r", "\\r").Replace("\n", "\\n")}");
+
+ var info = ParseSearchResponse(result.RemoteEndPoint.Address.ToString(), raw);
+ if (info != null)
+ encontrados.Add(info);
+ }
+ catch (Exception ex)
+ {
+ Log($"[ERRO RX UDP] {ex.Message}");
+ break;
+ }
+ }
+ }
+
+ return encontrados;
+ }
+
+ private UsrCan115DeviceInfo ParseSearchResponse(string remoteIp, string raw)
+ {
+ if (string.IsNullOrWhiteSpace(raw))
+ return null;
+
+ string clean = raw.Trim();
+
+ var info = new UsrCan115DeviceInfo
+ {
+ Ip = remoteIp,
+ RawResponse = raw
+ };
+
+ // Formato principal da busca UDP:
+ // 192.168.0.7,USR-CAN115,D4AD20B7AFCA,V1.0.09.000000.0000
+ var parts = clean.Split(',');
+
+ if (parts.Length >= 4 &&
+ parts[1].Trim().Equals("USR-CAN115", StringComparison.OrdinalIgnoreCase))
+ {
+ info.Ip = parts[0].Trim();
+ info.Model = parts[1].Trim();
+ info.Mac = parts[2].Trim();
+ info.Firmware = parts[3].Trim();
+ return info;
+ }
+
+ // Formato AT:
+ // +MODEL:USR-CAN115
+ if (clean.Contains("+MODEL:"))
+ info.Model = ExtrairAposPrefixo(clean, "+MODEL:");
+
+ if (clean.Contains("+MAC:"))
+ info.Mac = ExtrairAposPrefixo(clean, "+MAC:");
+
+ if (clean.Contains("+VER:"))
+ info.Firmware = ExtrairAposPrefixo(clean, "+VER:");
+
+ if (clean.Contains("USR-CAN115") && string.IsNullOrWhiteSpace(info.Model))
+ info.Model = "USR-CAN115";
+
+ // Só aceita como candidato se tiver algum sinal real do USR-CAN115
+ if (!string.IsNullOrWhiteSpace(info.Model) ||
+ clean.Contains("USR-CAN115") ||
+ clean.Contains("+SEARCH:"))
+ {
+ return info;
+ }
+
+ return null;
+ }
+
+ private string ExtrairAposPrefixo(string raw, string prefixo)
+ {
+ var linhas = raw.Replace("\r", "\n").Split('\n');
+
+ foreach (var linha in linhas)
+ {
+ var l = linha.Trim();
+ if (l.StartsWith(prefixo, StringComparison.OrdinalIgnoreCase))
+ return l.Substring(prefixo.Length).Trim();
+ }
+
+ return null;
+ }
+
+ private IEnumerable ObterBroadcastsLocais()
+ {
+ foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (ni.OperationalStatus != OperationalStatus.Up)
+ continue;
+
+ if (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback)
+ continue;
+
+ var props = ni.GetIPProperties();
+
+ foreach (var unicast in props.UnicastAddresses)
+ {
+ if (unicast.Address.AddressFamily != AddressFamily.InterNetwork)
+ continue;
+
+ if (unicast.IPv4Mask == null)
+ continue;
+
+ yield return CalcularBroadcast(unicast.Address, unicast.IPv4Mask);
+ }
+ }
+ }
+
+ private IPAddress CalcularBroadcast(IPAddress ip, IPAddress mask)
+ {
+ var ipBytes = ip.GetAddressBytes();
+ var maskBytes = mask.GetAddressBytes();
+
+ var broadcastBytes = new byte[4];
+
+ for (int i = 0; i < 4; i++)
+ broadcastBytes[i] = (byte)(ipBytes[i] | ~maskBytes[i]);
+
+ return new IPAddress(broadcastBytes);
+ }
+
+ public async Task> ScanTcpLocalAsync(int porta, int timeoutMs = 150)
+ {
+ var encontrados = new ConcurrentBag();
+ var redes = ObterInterfacesIpv4ComBroadcast().ToList();
+
+ var tarefas = new List();
+
+ foreach (var rede in redes)
+ {
+ var ipBytes = rede.LocalIp.GetAddressBytes();
+ string prefixo = $"{ipBytes[0]}.{ipBytes[1]}.{ipBytes[2]}";
+
+ for (int i = 1; i <= 254; i++)
+ {
+ string ip = $"{prefixo}.{i}";
+
+ tarefas.Add(Task.Run(async () =>
+ {
+ if (await TestarTcpAsync(ip, porta, timeoutMs))
+ {
+ encontrados.Add(new UsrCan115DeviceInfo
+ {
+ Ip = ip,
+ RawResponse = $"TCP {porta} aberto"
+ });
+
+ Log($"[TCP OK] {ip}:{porta}");
+ }
+ }));
+ }
+ }
+
+ await Task.WhenAll(tarefas);
+
+ return encontrados
+ .GroupBy(x => x.Ip)
+ .Select(g => g.First())
+ .ToList();
+ }
+
+ public async Task TestarTcpAsync(string ip, int porta, int timeoutMs = 300)
+ {
+ try
+ {
+ using (var client = new TcpClient())
+ {
+ var connectTask = client.ConnectAsync(ip, porta);
+ var timeoutTask = Task.Delay(timeoutMs);
+
+ var completed = await Task.WhenAny(connectTask, timeoutTask);
+
+ return completed == connectTask && client.Connected;
+ }
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+
+
+ private static readonly string[] QueryCommands =
+ {
+ "AT+MODEL?",
+ "AT+VER?",
+ "AT+MAC?",
+ "AT+SN?",
+ "AT+CAN?",
+ "AT+CANBAUD?",
+ "AT+WANN?",
+ "AT+DNS?",
+ "AT+TMODE?",
+ "AT+TRDIR?",
+ "AT+MSG?",
+ "AT+MARK?",
+ "AT+CANLT?",
+ "AT+SOCK?",
+ "AT+SOCKPORT?",
+ "AT+SOCKSL?",
+ "AT+SHORTO?",
+ "AT+UDPFLT?",
+ "AT+MAXSK?",
+ "AT+TCPSE?",
+ "AT+RCTIM?",
+ "AT+HEARTSND?",
+ "AT+HEARTTM?",
+ "AT+HEARTDT?",
+ "AT+REGEN?",
+ "AT+REGSND?",
+ "AT+REGDT?",
+ "AT+CANMODE?",
+ "AT+CANPACK?",
+ "AT+CLBUF?",
+ "AT+RSTIM?",
+ "AT+SEARCH?"
+ };
+
+ public async Task LerParametrosAsync(string ipRemetente, string ipDestino)
+ {
+ var config = new UsrCan115Config();
+
+ IPAddress localIp = IPAddress.Parse(ipRemetente);
+ IPAddress broadcastIp = CalcularBroadcast(localIp, IPAddress.Parse("255.255.255.0"));
+
+ string raw = await EnviarRajadaQueryParamsAsync(localIp, broadcastIp, ipDestino);
+
+ if (string.IsNullOrWhiteSpace(raw))
+ return config;
+
+ ParseRawCompletoParaConfig(raw, config);
+ AplicarRawNoConfig(config);
+
+ return config;
+ }
+
+ private async Task EnviarRajadaQueryParamsAsync(IPAddress localIp, IPAddress broadcastIp, string ipDestino)
+ {
+ using (var udp = new UdpClient(new IPEndPoint(localIp, 0)))
+ {
+ udp.EnableBroadcast = true;
+
+ var endpoint = new IPEndPoint(broadcastIp, SearchPort);
+
+ var comandos = new List();
+ comandos.Add("www.usr.cn");
+
+ foreach (var cmd in QueryCommands)
+ comandos.Add(cmd + "\r");
+
+ foreach (var cmd in comandos)
+ {
+ byte[] data = Encoding.ASCII.GetBytes(cmd);
+ await udp.SendAsync(data, data.Length, endpoint);
+
+ Log($"[TX UDP RAJADA {localIp} -> {broadcastIp}:{SearchPort}] {cmd.Replace("\r", "\\r").Replace("\n", "\\n")}");
+
+ await Task.Delay(20);
+ }
+
+ var inicio = DateTime.UtcNow;
+ var sb = new StringBuilder();
+
+ while ((DateTime.UtcNow - inicio).TotalMilliseconds < 3000)
+ {
+ try
+ {
+ var receiveTask = udp.ReceiveAsync();
+ var delayTask = Task.Delay(150);
+
+ var completed = await Task.WhenAny(receiveTask, delayTask);
+
+ if (completed != receiveTask)
+ continue;
+
+ var result = receiveTask.Result;
+ string ipOrigem = result.RemoteEndPoint.Address.ToString();
+
+ if (ipOrigem != ipDestino)
+ continue;
+
+ string raw = Encoding.ASCII.GetString(result.Buffer);
+ sb.Append(raw);
+
+ Log($"[RX UDP RAJADA {result.RemoteEndPoint}] {raw.Replace("\r", "\\r").Replace("\n", "\\n")}");
+ }
+ catch
+ {
+ break;
+ }
+ }
+
+ return sb.ToString();
+ }
+ }
+
+ private void ParseRawCompletoParaConfig(string raw, UsrCan115Config config)
+ {
+ if (string.IsNullOrWhiteSpace(raw))
+ return;
+
+ // Também trata a primeira resposta da busca:
+ // 192.168.0.7,USR-CAN115,D4AD20B7AFCA,V1.0.09.000000.0000
+ var linhas = raw
+ .Replace("\r", "\n")
+ .Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
+ .Select(x => x.Trim())
+ .Where(x => !string.IsNullOrWhiteSpace(x))
+ .ToList();
+
+ foreach (var linha in linhas)
+ {
+ if (linha.Equals("OK", StringComparison.OrdinalIgnoreCase))
+ continue;
+
+ if (linha.StartsWith("+"))
+ {
+ int idx = linha.IndexOf(':');
+ if (idx > 1)
+ {
+ string chave = linha.Substring(1, idx - 1).Trim();
+ string valor = linha.Substring(idx + 1).Trim();
+
+ config.Raw[chave] = valor;
+ }
+
+ continue;
+ }
+
+ // Resposta CSV da busca:
+ var parts = linha.Split(',');
+ if (parts.Length >= 4 &&
+ parts[1].Trim().Equals("USR-CAN115", StringComparison.OrdinalIgnoreCase))
+ {
+ config.Ip = parts[0].Trim();
+ config.Model = parts[1].Trim();
+ config.Mac = parts[2].Trim();
+ config.Firmware = parts[3].Trim();
+
+ config.Raw["MODEL"] = config.Model;
+ config.Raw["MAC"] = config.Mac;
+ config.Raw["VER"] = config.Firmware;
+ }
+ }
+ }
+
+ private void AplicarRawNoConfig(UsrCan115Config c)
+ {
+ string Get(string key)
+ {
+ return c.Raw.TryGetValue(key, out var value) ? value : null;
+ }
+
+ c.Model = Get("MODEL");
+ c.Firmware = Get("VER");
+ c.Mac = Get("MAC");
+ c.SerialNumber = Get("SN");
+
+ // +CAN:250,0,NDTF
+ var can = Get("CAN");
+ if (!string.IsNullOrWhiteSpace(can))
+ {
+ var p = can.Split(',');
+ if (p.Length >= 1 && int.TryParse(p[0], out int br))
+ c.CanBaudRate = br;
+
+ if (p.Length >= 2)
+ c.FrameType = p[1] == "0" ? "Standard Frame" : "Extended Frame";
+ }
+
+ // +WANN:STATIC,192.168.0.7,255.255.255.0,192.168.0.1
+ var wann = Get("WANN");
+ if (!string.IsNullOrWhiteSpace(wann))
+ {
+ var p = wann.Split(',');
+ if (p.Length >= 1) c.IpMode = p[0];
+ if (p.Length >= 2) c.Ip = p[1];
+ if (p.Length >= 3) c.Subnet = p[2];
+ if (p.Length >= 4) c.Gateway = p[3];
+ }
+
+ c.Dns = Get("DNS");
+
+ // +TMODE:PROTOL
+ c.ConversionMode = MapConversionMode(Get("TMODE"));
+
+ // +TRDIR:BOTHWAY
+ c.ConversionDirection = MapConversionDirection(Get("TRDIR"));
+
+ // +SOCK:TCPS,192.168.0.7,8235
+ var sock = Get("SOCK");
+ if (!string.IsNullOrWhiteSpace(sock))
+ {
+ var p = sock.Split(',');
+ if (p.Length >= 1) c.SocketMode = p[0];
+ if (p.Length >= 2) c.ServerIp = p[1];
+
+ if (p.Length >= 3 && int.TryParse(p[2], out int portaSock))
+ {
+ // Em TCPS, essa costuma ser a porta local.
+ // Em TCPC, essa costuma ser a porta remota.
+ if (c.SocketMode == "TCPS" || c.SocketMode == "UDPS")
+ c.LocalPort = portaSock;
+ else
+ c.RemotePort = portaSock;
+ }
+ }
+
+ // +SOCKPORT:8234,8235
+ var sockPort = Get("SOCKPORT");
+ if (!string.IsNullOrWhiteSpace(sockPort))
+ {
+ var p = sockPort.Split(',');
+ if (p.Length >= 1 && int.TryParse(p[0], out int remote))
+ c.RemotePort = remote;
+
+ if (p.Length >= 2 && int.TryParse(p[1], out int local))
+ c.LocalPort = local;
+ }
+
+ if (int.TryParse(Get("MAXSK"), out int maxsk))
+ c.MaxConnections = maxsk;
+
+ c.ShortLink = Get("SOCKSL");
+ c.UdpFilter = Get("UDPFLT");
+ c.TcpOverLimit = Get("TCPSE");
+
+ if (int.TryParse(Get("RCTIM"), out int rctim))
+ c.ReconnectTime = rctim;
+
+ c.HeartbeatEnabled = Get("HEARTSND");
+
+ if (int.TryParse(Get("HEARTTM"), out int hearttm))
+ c.HeartbeatTime = hearttm;
+
+ c.HeartbeatData = Get("HEARTDT");
+
+ c.RegisterEnabled = Get("REGEN");
+ c.RegisterSendMode = Get("REGSND");
+ c.RegisterData = Get("REGDT");
+
+ c.CanMode = MapCanMode(Get("CANMODE"));
+ c.CanPack = Get("CANPACK");
+ c.ClearBuffer = Get("CLBUF");
+
+ if (int.TryParse(Get("RSTIM"), out int rstim))
+ c.RestartTime = rstim;
+ }
+
+ private string MapConversionMode(string value)
+ {
+ switch ((value ?? "").ToUpperInvariant())
+ {
+ case "TRANS":
+ return "Transparent Conversion";
+ case "MARK":
+ return "Transparent Band ID Conversion";
+ case "PROTOL":
+ return "Standard Protocol Conversion";
+ default:
+ return value;
+ }
+ }
+
+ private string MapConversionDirection(string value)
+ {
+ switch ((value ?? "").ToUpperInvariant())
+ {
+ case "BOTHWAY":
+ return "Both way";
+ case "CANTONET":
+ return "CAN to Network";
+ case "NETTOCAN":
+ return "Network to CAN";
+ default:
+ return value;
+ }
+ }
+
+ private string MapCanMode(string value)
+ {
+ switch ((value ?? "").ToUpperInvariant())
+ {
+ case "NORMAL":
+ return "Normal";
+ case "LISTEN":
+ return "Only Listen";
+ case "LOOPBACK":
+ return "Loopback";
+ default:
+ return value;
+ }
+ }
+
+
+
+ public async Task GravarParametrosAsync(string ipRemetente, string ipDestinoAtual, UsrCan115Config config)
+ {
+ IPAddress localIp = IPAddress.Parse(ipRemetente);
+ IPAddress broadcastIp = CalcularBroadcast(localIp, IPAddress.Parse("255.255.255.0"));
+
+ var comandos = MontarComandosSet(config);
+
+ string raw = await EnviarRajadaSetAsync(
+ localIp,
+ broadcastIp,
+ ipDestinoAtual,
+ config.Ip,
+ comandos);
+
+ int qtdOk = ContarOcorrencias(raw, "OK");
+ int qtdErr = ContarOcorrencias(raw, "ERR");
+
+ var result = new UsrCan115WriteResult
+ {
+ Raw = raw,
+ OkCount = qtdOk,
+ ErrCount = qtdErr
+ };
+
+ if (string.IsNullOrWhiteSpace(raw))
+ {
+ result.Sucesso = false;
+ result.Mensagem = "Nenhuma resposta recebida durante gravação.";
+ Log("[ERRO] " + result.Mensagem);
+ return result;
+ }
+
+ Log($"[INFO] Respostas OK: {qtdOk}, ERR: {qtdErr}, comandos enviados: {comandos.Count}");
+
+ // O módulo pode retornar ERR em comando opcional e ainda gravar os parâmetros principais.
+ result.Sucesso = qtdOk > 0 && qtdErr <= 2;
+
+ result.Mensagem = result.Sucesso
+ ? $"Parâmetros enviados. OK={qtdOk}, ERR={qtdErr}. Reinicie o módulo para aplicar."
+ : $"Falha ao gravar parâmetros. OK={qtdOk}, ERR={qtdErr}.";
+
+ return result;
+ }
+
+ private int ContarOcorrencias(string raw, string termo)
+ {
+ if (string.IsNullOrWhiteSpace(raw) || string.IsNullOrWhiteSpace(termo))
+ return 0;
+
+ int count = 0;
+ int index = 0;
+
+ while ((index = raw.IndexOf(termo, index, StringComparison.OrdinalIgnoreCase)) >= 0)
+ {
+ count++;
+ index += termo.Length;
+ }
+
+ return count;
+ }
+
+ private List MontarComandosSet(UsrCan115Config c)
+ {
+ var comandos = new List();
+
+ // CAN:
+ // O GET retorna +CAN:250,0,NDTF.
+ // Então gravamos no mesmo padrão.
+ string frameType = string.IsNullOrWhiteSpace(c.FrameType) ? "0" : c.FrameType;
+ string baud = c.CanBaudRate > 0 ? c.CanBaudRate.ToString() : "250";
+ comandos.Add($"AT+CAN={baud},{frameType},NDTF");
+
+ // Rede:
+ // +WANN:STATIC,192.168.0.7,255.255.255.0,192.168.0.1
+ string ipMode = string.IsNullOrWhiteSpace(c.IpMode) ? "STATIC" : c.IpMode;
+ comandos.Add($"AT+WANN={ipMode},{c.Ip},{c.Subnet},{c.Gateway}");
+
+ if (!string.IsNullOrWhiteSpace(c.Dns))
+ comandos.Add($"AT+DNS={c.Dns}");
+
+ // Conversão:
+ comandos.Add($"AT+TMODE={c.ConversionMode}");
+ comandos.Add($"AT+TRDIR={c.ConversionDirection}");
+
+ // Socket:
+ // Exemplo lido:
+ // +SOCK:TCPS,192.168.0.7,8235
+ //
+ // Para TCPS/UDPS, o terceiro campo é a porta local.
+ // Para TCPC/UDPC, o terceiro campo é a porta remota.
+ int portaSock = (c.SocketMode == "TCPS" || c.SocketMode == "UDPS")
+ ? c.LocalPort
+ : c.RemotePort;
+
+ string serverIp = string.IsNullOrWhiteSpace(c.ServerIp)
+ ? c.Ip
+ : c.ServerIp;
+
+ comandos.Add($"AT+SOCK={c.SocketMode},{serverIp},{portaSock}");
+
+ // O módulo retorna +SOCKPORT:8234,8235.
+ // Pela leitura que fizemos: RemotePort,LocalPort.
+ comandos.Add($"AT+SOCKPORT={c.RemotePort},{c.LocalPort}");
+
+ // Opções de socket que usamos como padrão.
+ comandos.Add("AT+SOCKSL=OFF");
+ comandos.Add("AT+SHORTO=3");
+ comandos.Add("AT+UDPFLT=OFF");
+ comandos.Add($"AT+MAXSK={Math.Max(1, c.MaxConnections)}");
+ comandos.Add("AT+TCPSE=KICK");
+ comandos.Add("AT+RCTIM=0");
+
+ // Heartbeat e register desligados para não poluir o canal CAN.
+ comandos.Add("AT+HEARTSND=OFF");
+ comandos.Add("AT+REGEN=OFF");
+
+ // Modo CAN.
+ comandos.Add($"AT+CANMODE={c.CanMode}");
+
+ // Mantemos estes como o perfil atual retornado pelo módulo.
+ comandos.Add("AT+CANPACK=100,10");
+ comandos.Add("AT+CLBUF=OFF");
+ comandos.Add("AT+RSTIM=3600");
+
+ return comandos;
+ }
+
+ private async Task EnviarRajadaSetAsync(IPAddress localIp, IPAddress broadcastIp, string ipDestinoAtual, string ipDestinoNovo, List comandos)
+ {
+ using (var udp = new UdpClient(new IPEndPoint(localIp, 0)))
+ {
+ udp.EnableBroadcast = true;
+
+ var endpoint = new IPEndPoint(broadcastIp, SearchPort);
+
+ // Acorda o modo config.
+ await EnviarTextoUdpAsync(udp, endpoint, "www.usr.cn");
+ Log($"[TX UDP SET {localIp} -> {broadcastIp}:{SearchPort}] www.usr.cn");
+
+ await Task.Delay(30);
+
+ foreach (var comando in comandos)
+ {
+ string cmd = comando.EndsWith("\r") ? comando : comando + "\r";
+
+ await EnviarTextoUdpAsync(udp, endpoint, cmd);
+
+ Log($"[TX UDP SET {localIp} -> {broadcastIp}:{SearchPort}] {cmd.Replace("\r", "\\r").Replace("\n", "\\n")}");
+
+ await Task.Delay(35);
+ }
+
+ var inicio = DateTime.UtcNow;
+ var sb = new StringBuilder();
+
+ while ((DateTime.UtcNow - inicio).TotalMilliseconds < 3500)
+ {
+ try
+ {
+ var receiveTask = udp.ReceiveAsync();
+ var delayTask = Task.Delay(150);
+
+ var completed = await Task.WhenAny(receiveTask, delayTask);
+ if (completed != receiveTask)
+ continue;
+
+ var result = receiveTask.Result;
+ string ipOrigem = result.RemoteEndPoint.Address.ToString();
+ string raw = Encoding.ASCII.GetString(result.Buffer);
+
+ Log($"[RX UDP SET {result.RemoteEndPoint}] {raw.Replace("\r", "\\r").Replace("\n", "\\n")}");
+
+ bool origemValida =
+ ipOrigem == ipDestinoAtual ||
+ ipOrigem == ipDestinoNovo;
+
+ if (!origemValida)
+ continue;
+
+ sb.Append(raw);
+ }
+ catch
+ {
+ break;
+ }
+ }
+
+ return sb.ToString();
+ }
+ }
+
+ private async Task EnviarTextoUdpAsync(UdpClient udp, IPEndPoint endpoint, string texto)
+ {
+ byte[] data = Encoding.ASCII.GetBytes(texto);
+ await udp.SendAsync(data, data.Length, endpoint);
+ }
+
+
+ public async Task ReiniciarModuloAsync(string ipRemetente, string ipDestinoAtual)
+ {
+ IPAddress localIp = IPAddress.Parse(ipRemetente);
+ IPAddress broadcastIp = CalcularBroadcast(localIp, IPAddress.Parse("255.255.255.0"));
+
+ using (var udp = new UdpClient(new IPEndPoint(localIp, 0)))
+ {
+ udp.EnableBroadcast = true;
+
+ var endpoint = new IPEndPoint(broadcastIp, SearchPort);
+
+ await EnviarTextoUdpAsync(udp, endpoint, "www.usr.cn");
+ Log($"[TX UDP RESTART {localIp} -> {broadcastIp}:{SearchPort}] www.usr.cn");
+
+ await Task.Delay(30);
+
+ string cmd = "AT+Z\r";
+ await EnviarTextoUdpAsync(udp, endpoint, cmd);
+ Log($"[TX UDP RESTART {localIp} -> {broadcastIp}:{SearchPort}] AT+Z\\r");
+
+ var inicio = DateTime.UtcNow;
+ bool recebeuOk = false;
+
+ while ((DateTime.UtcNow - inicio).TotalMilliseconds < 1200)
+ {
+ try
+ {
+ var receiveTask = udp.ReceiveAsync();
+ var delayTask = Task.Delay(150);
+
+ var completed = await Task.WhenAny(receiveTask, delayTask);
+ if (completed != receiveTask)
+ continue;
+
+ var result = receiveTask.Result;
+ string ipOrigem = result.RemoteEndPoint.Address.ToString();
+ string raw = Encoding.ASCII.GetString(result.Buffer);
+
+ Log($"[RX UDP RESTART {result.RemoteEndPoint}] {raw.Replace("\r", "\\r").Replace("\n", "\\n")}");
+
+ if (ipOrigem == ipDestinoAtual && raw.Contains("OK"))
+ recebeuOk = true;
+ }
+ catch
+ {
+ break;
+ }
+ }
+
+ // Mesmo sem OK, pode ter reiniciado. O OK é bônus.
+ await Task.Delay(2500);
+
+ return recebeuOk;
+ }
+ }
+
+ }
+}