diff --git a/AgroBase/.vs/AgroBase/FileContentIndex/0e09bb0e-a015-4f97-bfac-925e2e581a67.vsidx b/AgroBase/.vs/AgroBase/FileContentIndex/0e09bb0e-a015-4f97-bfac-925e2e581a67.vsidx
new file mode 100644
index 000000000..b69e1a14a
Binary files /dev/null and b/AgroBase/.vs/AgroBase/FileContentIndex/0e09bb0e-a015-4f97-bfac-925e2e581a67.vsidx differ
diff --git a/AgroBase/.vs/AgroBase/FileContentIndex/237273f7-2192-49f9-ac07-351d9366628b.vsidx b/AgroBase/.vs/AgroBase/FileContentIndex/237273f7-2192-49f9-ac07-351d9366628b.vsidx
new file mode 100644
index 000000000..2f578bb9c
Binary files /dev/null and b/AgroBase/.vs/AgroBase/FileContentIndex/237273f7-2192-49f9-ac07-351d9366628b.vsidx differ
diff --git a/AgroBase/.vs/AgroBase/FileContentIndex/55abe44a-a676-46fe-9855-c1189b59d8d7.vsidx b/AgroBase/.vs/AgroBase/FileContentIndex/55abe44a-a676-46fe-9855-c1189b59d8d7.vsidx
deleted file mode 100644
index 3906f7cb5..000000000
Binary files a/AgroBase/.vs/AgroBase/FileContentIndex/55abe44a-a676-46fe-9855-c1189b59d8d7.vsidx and /dev/null differ
diff --git a/AgroBase/.vs/AgroBase/FileContentIndex/a6cc1429-9a7b-491c-b69b-f447dfa651b3.vsidx b/AgroBase/.vs/AgroBase/FileContentIndex/a6cc1429-9a7b-491c-b69b-f447dfa651b3.vsidx
deleted file mode 100644
index c6a1e19b8..000000000
Binary files a/AgroBase/.vs/AgroBase/FileContentIndex/a6cc1429-9a7b-491c-b69b-f447dfa651b3.vsidx and /dev/null differ
diff --git a/AgroBase/.vs/AgroBase/v17/.suo b/AgroBase/.vs/AgroBase/v17/.suo
index 275054cc5..ca8d828dd 100644
Binary files a/AgroBase/.vs/AgroBase/v17/.suo and b/AgroBase/.vs/AgroBase/v17/.suo differ
diff --git a/AgroBase/AgroBase/AgroBase.csproj b/AgroBase/AgroBase/AgroBase.csproj
index 98c799f3f..92eba2bba 100644
--- a/AgroBase/AgroBase/AgroBase.csproj
+++ b/AgroBase/AgroBase/AgroBase.csproj
@@ -247,6 +247,12 @@
frmBLD.cs
+
+ Form
+
+
+ frmEthernet.cs
+
Form
@@ -460,6 +466,7 @@
+
@@ -663,6 +670,9 @@
frmBLD.cs
+
+ frmEthernet.cs
+
frmGPS.cs
diff --git a/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.Designer.cs b/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.Designer.cs
index 136aa4b54..2078ba821 100644
--- a/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.Designer.cs
+++ b/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.Designer.cs
@@ -30,6 +30,8 @@ namespace AgroBase.Forms.Direcional
private void InitializeComponent()
{
this.gpbSentido = new System.Windows.Forms.GroupBox();
+ this.cmbTipoMovimento = new System.Windows.Forms.ComboBox();
+ this.lblTipoMovimento = new System.Windows.Forms.Label();
this.btnSalvarSentido = new System.Windows.Forms.Button();
this.gpbDF = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
@@ -67,8 +69,8 @@ namespace AgroBase.Forms.Direcional
this.cmbETEsquerda = new System.Windows.Forms.ComboBox();
this.lblETEsquerda = new System.Windows.Forms.Label();
this.lblETDireita = new System.Windows.Forms.Label();
- this.cmbTipoMovimento = new System.Windows.Forms.ComboBox();
- this.lblTipoMovimento = new System.Windows.Forms.Label();
+ this.lblIP = new System.Windows.Forms.Label();
+ this.txtIP = new System.Windows.Forms.TextBox();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDFOffset)).BeginInit();
@@ -82,6 +84,8 @@ namespace AgroBase.Forms.Direcional
//
// gpbSentido
//
+ this.gpbSentido.Controls.Add(this.lblIP);
+ this.gpbSentido.Controls.Add(this.txtIP);
this.gpbSentido.Controls.Add(this.cmbTipoMovimento);
this.gpbSentido.Controls.Add(this.lblTipoMovimento);
this.gpbSentido.Controls.Add(this.btnSalvarSentido);
@@ -98,6 +102,25 @@ namespace AgroBase.Forms.Direcional
this.gpbSentido.TabStop = false;
this.gpbSentido.Text = "Sentido de giro";
//
+ // cmbTipoMovimento
+ //
+ this.cmbTipoMovimento.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.cmbTipoMovimento.FormattingEnabled = true;
+ this.cmbTipoMovimento.Location = new System.Drawing.Point(195, 18);
+ this.cmbTipoMovimento.Name = "cmbTipoMovimento";
+ this.cmbTipoMovimento.Size = new System.Drawing.Size(168, 21);
+ this.cmbTipoMovimento.TabIndex = 13;
+ this.cmbTipoMovimento.SelectedIndexChanged += new System.EventHandler(this.cmbTipoMovimento_SelectedIndexChanged);
+ //
+ // lblTipoMovimento
+ //
+ this.lblTipoMovimento.AutoSize = true;
+ this.lblTipoMovimento.Location = new System.Drawing.Point(15, 21);
+ this.lblTipoMovimento.Name = "lblTipoMovimento";
+ this.lblTipoMovimento.Size = new System.Drawing.Size(98, 13);
+ this.lblTipoMovimento.TabIndex = 12;
+ this.lblTipoMovimento.Text = "Tipo de Movimento";
+ //
// btnSalvarSentido
//
this.btnSalvarSentido.Location = new System.Drawing.Point(276, 339);
@@ -529,24 +552,24 @@ namespace AgroBase.Forms.Direcional
this.lblETDireita.TabIndex = 2;
this.lblETDireita.Text = "Direita";
//
- // cmbTipoMovimento
+ // lblIP
//
- this.cmbTipoMovimento.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmbTipoMovimento.FormattingEnabled = true;
- this.cmbTipoMovimento.Location = new System.Drawing.Point(195, 18);
- this.cmbTipoMovimento.Name = "cmbTipoMovimento";
- this.cmbTipoMovimento.Size = new System.Drawing.Size(168, 21);
- this.cmbTipoMovimento.TabIndex = 13;
- this.cmbTipoMovimento.SelectedIndexChanged += new System.EventHandler(this.cmbTipoMovimento_SelectedIndexChanged);
+ this.lblIP.AutoSize = true;
+ this.lblIP.Location = new System.Drawing.Point(10, 326);
+ this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+ this.lblIP.Name = "lblIP";
+ this.lblIP.Size = new System.Drawing.Size(17, 13);
+ this.lblIP.TabIndex = 143;
+ this.lblIP.Text = "IP";
//
- // lblTipoMovimento
+ // txtIP
//
- this.lblTipoMovimento.AutoSize = true;
- this.lblTipoMovimento.Location = new System.Drawing.Point(15, 21);
- this.lblTipoMovimento.Name = "lblTipoMovimento";
- this.lblTipoMovimento.Size = new System.Drawing.Size(98, 13);
- this.lblTipoMovimento.TabIndex = 12;
- this.lblTipoMovimento.Text = "Tipo de Movimento";
+ this.txtIP.Location = new System.Drawing.Point(13, 343);
+ this.txtIP.Margin = new System.Windows.Forms.Padding(2);
+ this.txtIP.Name = "txtIP";
+ this.txtIP.Size = new System.Drawing.Size(85, 20);
+ this.txtIP.TabIndex = 142;
+ this.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// frmDirConfig
//
@@ -620,5 +643,7 @@ namespace AgroBase.Forms.Direcional
private System.Windows.Forms.TextBox txtETEndereco;
private System.Windows.Forms.ComboBox cmbTipoMovimento;
private System.Windows.Forms.Label lblTipoMovimento;
+ private System.Windows.Forms.Label lblIP;
+ private System.Windows.Forms.TextBox txtIP;
}
}
\ No newline at end of file
diff --git a/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.cs b/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.cs
index d769fd0f6..1219fc612 100644
--- a/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.cs
+++ b/AgroBase/AgroBase/Forms/Direcional/frmDirConfig.cs
@@ -77,6 +77,8 @@ namespace AgroBase.Forms.Direcional
nudOffset.Value = Convert.ToInt32(Modulo.DirMotor.Angulo_Offset);
}
}
+
+ txtIP.Text = Disp.Dados.IP_Mks;
}
private void frmDirConfig_FormClosing(object sender, FormClosingEventArgs e)
@@ -119,6 +121,8 @@ namespace AgroBase.Forms.Direcional
}
}
+ Disp.Dados.IP_Mks = txtIP.Text;
+
Disp.SalvarParametros(Disp.Dados);
}
diff --git a/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.Designer.cs b/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.Designer.cs
index d351cfd09..210823210 100644
--- a/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.Designer.cs
+++ b/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.Designer.cs
@@ -74,6 +74,8 @@ namespace AgroBase.Forms.Movimentacao
this.nudNumPolos = new System.Windows.Forms.NumericUpDown();
this.lblRampa = new System.Windows.Forms.Label();
this.nudRampa = new System.Windows.Forms.NumericUpDown();
+ this.txtIP = new System.Windows.Forms.TextBox();
+ this.lblIP = new System.Windows.Forms.Label();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
this.gpbEF.SuspendLayout();
@@ -421,6 +423,8 @@ namespace AgroBase.Forms.Movimentacao
//
// groupBox1
//
+ this.groupBox1.Controls.Add(this.lblIP);
+ this.groupBox1.Controls.Add(this.txtIP);
this.groupBox1.Controls.Add(this.txtOffsetLeitura);
this.groupBox1.Controls.Add(this.lblOffsetLeitura);
this.groupBox1.Controls.Add(this.lblReducao);
@@ -614,6 +618,25 @@ namespace AgroBase.Forms.Movimentacao
this.nudRampa.TabIndex = 31;
this.nudRampa.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
+ // txtIP
+ //
+ this.txtIP.Location = new System.Drawing.Point(283, 37);
+ this.txtIP.Margin = new System.Windows.Forms.Padding(2);
+ this.txtIP.Name = "txtIP";
+ this.txtIP.Size = new System.Drawing.Size(85, 20);
+ this.txtIP.TabIndex = 12;
+ this.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ //
+ // lblIP
+ //
+ this.lblIP.AutoSize = true;
+ this.lblIP.Location = new System.Drawing.Point(280, 20);
+ this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+ this.lblIP.Name = "lblIP";
+ this.lblIP.Size = new System.Drawing.Size(17, 13);
+ this.lblIP.TabIndex = 141;
+ this.lblIP.Text = "IP";
+ //
// frmMovConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -696,5 +719,7 @@ namespace AgroBase.Forms.Movimentacao
private System.Windows.Forms.Label lblTipoMovimento;
private System.Windows.Forms.TextBox txtOffsetLeitura;
private System.Windows.Forms.Label lblOffsetLeitura;
+ private System.Windows.Forms.Label lblIP;
+ private System.Windows.Forms.TextBox txtIP;
}
}
\ No newline at end of file
diff --git a/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.cs b/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.cs
index 5633f92ff..5fe766872 100644
--- a/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.cs
+++ b/AgroBase/AgroBase/Forms/Movimentacao/frmMovConfig.cs
@@ -19,8 +19,6 @@ namespace AgroBase.Forms.Movimentacao
private void frmMovConfig_Load(object sender, EventArgs e)
{
- nudDiametroRoda.Value = Convert.ToInt32(VariaveisEquipamento.DiametroRoda * 1000.0);
-
if (Disp == null)
{
return;
@@ -67,14 +65,17 @@ namespace AgroBase.Forms.Movimentacao
nudNumPolos.Value = Modulo.MovMotor.NumeroPolos;
nudRampa.Value = Modulo.MovMotor.Rampa;
- nudRPMMax.Value = Modulo.MovMotor.RPM_Max;
- nudReducao.Value = Modulo.MovMotor.Reducao;
txtOffsetLeitura.Text = Modulo.MovMotor.OffsetLeitura.ToString();
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
txtEndereco.Text = Modulo.MovMotor.Endereco;
}
}
+
+ nudRPMMax.Value = (int)Disp.Dados.RPM_Max_MotorBLDC;
+ nudReducao.Value = (int)Disp.Dados.ReducaoMotorBLDC;
+ nudDiametroRoda.Value = (int)Disp.Dados.DiametroRoda * 1000;
+ txtIP.Text = Disp.Dados.IP_Bld;
}
private void frmMovConfig_FormClosing(object sender, FormClosingEventArgs e)
@@ -111,16 +112,18 @@ namespace AgroBase.Forms.Movimentacao
Modulo.MovMotor.NumeroPolos = Convert.ToInt32(nudNumPolos.Value);
Modulo.MovMotor.Rampa = Convert.ToInt32(nudRampa.Value);
- Modulo.MovMotor.RPM_Max = Convert.ToInt32(nudRPMMax.Value);
- Modulo.MovMotor.Reducao = Convert.ToInt32(nudReducao.Value);
Modulo.MovMotor.OffsetLeitura = Convert.ToDouble(txtOffsetLeitura.Text);
- Modulo.MovMotor.DiametroRoda = Convert.ToDouble(nudDiametroRoda.Value / 1000);
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
Modulo.MovMotor.Endereco = txtEndereco.Text;
}
}
+ Disp.Dados.RPM_Max_MotorBLDC = Convert.ToInt32(nudRPMMax.Value);
+ Disp.Dados.ReducaoMotorBLDC = Convert.ToInt32(nudReducao.Value);
+ Disp.Dados.DiametroRoda = Convert.ToDouble(nudDiametroRoda.Value / 1000);
+ Disp.Dados.IP_Bld = txtIP.Text;
+
Disp.SalvarParametros(Disp.Dados);
}
diff --git a/AgroBase/AgroBase/Forms/frmBLD.cs b/AgroBase/AgroBase/Forms/frmBLD.cs
index b32964aaa..0dd2f55e5 100644
--- a/AgroBase/AgroBase/Forms/frmBLD.cs
+++ b/AgroBase/AgroBase/Forms/frmBLD.cs
@@ -28,7 +28,7 @@ namespace AgroBase.Forms
btnAtualizar_Click(sender, e);
//LoopAtualizacao().ConfigureAwait(false);
- this.Text += " - " + BLD300RService._PortaBLD.PortName;
+ this.Text += " - "; // + BLD300RService._PortaBLD.PortName;
}
private async Task LoopAtualizacao()
diff --git a/AgroBase/AgroBase/Forms/frmEthernet.Designer.cs b/AgroBase/AgroBase/Forms/frmEthernet.Designer.cs
new file mode 100644
index 000000000..4ebfa9f51
--- /dev/null
+++ b/AgroBase/AgroBase/Forms/frmEthernet.Designer.cs
@@ -0,0 +1,172 @@
+namespace AgroBase.Forms
+{
+ partial class frmEthernet
+ {
+ ///
+ /// 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.lblGateway = new System.Windows.Forms.Label();
+ this.lblIpAtual = new System.Windows.Forms.Label();
+ this.txtGateway = new System.Windows.Forms.TextBox();
+ this.txtIpAtual = new System.Windows.Forms.TextBox();
+ this.btnDefinirIp = new System.Windows.Forms.Button();
+ this.chbIpFixo = new System.Windows.Forms.CheckBox();
+ this.cmbInterface = new System.Windows.Forms.ComboBox();
+ this.lblInterface = new System.Windows.Forms.Label();
+ this.txtSubmask = new System.Windows.Forms.TextBox();
+ this.lblSubmask = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // lblGateway
+ //
+ this.lblGateway.AutoSize = true;
+ this.lblGateway.Location = new System.Drawing.Point(12, 49);
+ this.lblGateway.Name = "lblGateway";
+ this.lblGateway.Size = new System.Drawing.Size(49, 13);
+ this.lblGateway.TabIndex = 0;
+ this.lblGateway.Text = "Gateway";
+ //
+ // lblIpAtual
+ //
+ this.lblIpAtual.AutoSize = true;
+ this.lblIpAtual.Location = new System.Drawing.Point(12, 127);
+ this.lblIpAtual.Name = "lblIpAtual";
+ this.lblIpAtual.Size = new System.Drawing.Size(44, 13);
+ this.lblIpAtual.TabIndex = 1;
+ this.lblIpAtual.Text = "IP Atual";
+ //
+ // txtGateway
+ //
+ this.txtGateway.Enabled = false;
+ this.txtGateway.Location = new System.Drawing.Point(15, 65);
+ this.txtGateway.Name = "txtGateway";
+ this.txtGateway.Size = new System.Drawing.Size(141, 20);
+ this.txtGateway.TabIndex = 2;
+ this.txtGateway.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ //
+ // txtIpAtual
+ //
+ this.txtIpAtual.Enabled = false;
+ this.txtIpAtual.Location = new System.Drawing.Point(15, 143);
+ this.txtIpAtual.Name = "txtIpAtual";
+ this.txtIpAtual.Size = new System.Drawing.Size(141, 20);
+ this.txtIpAtual.TabIndex = 4;
+ this.txtIpAtual.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ //
+ // btnDefinirIp
+ //
+ this.btnDefinirIp.Location = new System.Drawing.Point(15, 197);
+ this.btnDefinirIp.Name = "btnDefinirIp";
+ this.btnDefinirIp.Size = new System.Drawing.Size(141, 23);
+ this.btnDefinirIp.TabIndex = 6;
+ this.btnDefinirIp.Text = "Definir IP";
+ this.btnDefinirIp.UseVisualStyleBackColor = true;
+ this.btnDefinirIp.Click += new System.EventHandler(this.btnDefinirIp_Click);
+ //
+ // chbIpFixo
+ //
+ this.chbIpFixo.AutoSize = true;
+ this.chbIpFixo.Location = new System.Drawing.Point(15, 170);
+ this.chbIpFixo.Name = "chbIpFixo";
+ this.chbIpFixo.Size = new System.Drawing.Size(58, 17);
+ this.chbIpFixo.TabIndex = 5;
+ this.chbIpFixo.Text = "IP Fixo";
+ this.chbIpFixo.UseVisualStyleBackColor = true;
+ this.chbIpFixo.CheckedChanged += new System.EventHandler(this.chbIpFixo_CheckedChanged);
+ //
+ // cmbInterface
+ //
+ this.cmbInterface.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.cmbInterface.FormattingEnabled = true;
+ this.cmbInterface.Location = new System.Drawing.Point(15, 25);
+ this.cmbInterface.Name = "cmbInterface";
+ this.cmbInterface.Size = new System.Drawing.Size(141, 21);
+ this.cmbInterface.TabIndex = 1;
+ //
+ // lblInterface
+ //
+ this.lblInterface.AutoSize = true;
+ this.lblInterface.Location = new System.Drawing.Point(12, 9);
+ this.lblInterface.Name = "lblInterface";
+ this.lblInterface.Size = new System.Drawing.Size(49, 13);
+ this.lblInterface.TabIndex = 7;
+ this.lblInterface.Text = "Interface";
+ //
+ // txtSubmask
+ //
+ this.txtSubmask.Enabled = false;
+ this.txtSubmask.Location = new System.Drawing.Point(15, 104);
+ this.txtSubmask.Name = "txtSubmask";
+ this.txtSubmask.Size = new System.Drawing.Size(141, 20);
+ this.txtSubmask.TabIndex = 3;
+ this.txtSubmask.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+ //
+ // lblSubmask
+ //
+ this.lblSubmask.AutoSize = true;
+ this.lblSubmask.Location = new System.Drawing.Point(12, 88);
+ this.lblSubmask.Name = "lblSubmask";
+ this.lblSubmask.Size = new System.Drawing.Size(70, 13);
+ this.lblSubmask.TabIndex = 8;
+ this.lblSubmask.Text = "Subnet Mask";
+ //
+ // frmEthernet
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(267, 232);
+ this.Controls.Add(this.txtSubmask);
+ this.Controls.Add(this.lblSubmask);
+ this.Controls.Add(this.lblInterface);
+ this.Controls.Add(this.cmbInterface);
+ this.Controls.Add(this.chbIpFixo);
+ this.Controls.Add(this.btnDefinirIp);
+ this.Controls.Add(this.txtIpAtual);
+ this.Controls.Add(this.txtGateway);
+ this.Controls.Add(this.lblIpAtual);
+ this.Controls.Add(this.lblGateway);
+ this.Name = "frmEthernet";
+ this.Text = "Configurações de Rede";
+ this.Load += new System.EventHandler(this.frmEthernet_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Label lblGateway;
+ private System.Windows.Forms.Label lblIpAtual;
+ private System.Windows.Forms.TextBox txtGateway;
+ private System.Windows.Forms.TextBox txtIpAtual;
+ private System.Windows.Forms.Button btnDefinirIp;
+ private System.Windows.Forms.CheckBox chbIpFixo;
+ private System.Windows.Forms.ComboBox cmbInterface;
+ private System.Windows.Forms.Label lblInterface;
+ private System.Windows.Forms.TextBox txtSubmask;
+ private System.Windows.Forms.Label lblSubmask;
+ }
+}
\ No newline at end of file
diff --git a/AgroBase/AgroBase/Forms/frmEthernet.cs b/AgroBase/AgroBase/Forms/frmEthernet.cs
new file mode 100644
index 000000000..06a82374e
--- /dev/null
+++ b/AgroBase/AgroBase/Forms/frmEthernet.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AgroBase.Forms
+{
+ public partial class frmEthernet : Form
+ {
+ public frmEthernet()
+ {
+ InitializeComponent();
+ }
+
+ private void frmEthernet_Load(object sender, EventArgs e)
+ {
+ var interfaces = EthernetService.ObterNomesInterfaces();
+ cmbInterface.Items.AddRange(interfaces.ToArray());
+
+ if (interfaces.Any(x => x.Contains("Ativa")))
+ cmbInterface.SelectedIndex = interfaces.IndexOf(interfaces.First(x => x.Contains("Ativa")));
+
+ txtGateway.Text = EthernetService.ObterIpGateway();
+ txtIpAtual.Text = EthernetService.ObterIpAtual();
+ txtSubmask.Text = EthernetService.ObterSubnetMaskAtual();
+ chbIpFixo.Checked = EthernetService.ObterTipoConfiguracaoIP().Contains("Fixo");
+ }
+
+ private void btnDefinirIp_Click(object sender, EventArgs e)
+ {
+ string ipNovo = txtIpAtual.Text;
+ string gateway = txtGateway.Text;
+ string subnetMask = txtSubmask.Text;
+
+ // Aqui substituímos "Ethernet" pelo nome correto da interface que o PC está usando
+ if (chbIpFixo.Checked)
+ {
+ EthernetService.DefinirIpFixo(cmbInterface.Text, ipNovo, subnetMask, gateway);
+ }
+ else
+ {
+ EthernetService.DefinirIpDinamico(cmbInterface.Text);
+ }
+ MessageBox.Show("Configuração de IP atualizada.");
+ }
+
+ private void chbIpFixo_CheckedChanged(object sender, EventArgs e)
+ {
+ txtGateway.Enabled = chbIpFixo.Checked;
+ txtIpAtual.Enabled = chbIpFixo.Checked;
+ txtSubmask.Enabled = chbIpFixo.Checked;
+ }
+ }
+}
diff --git a/AgroBase/AgroBase/Forms/frmEthernet.resx b/AgroBase/AgroBase/Forms/frmEthernet.resx
new file mode 100644
index 000000000..1af7de150
--- /dev/null
+++ b/AgroBase/AgroBase/Forms/frmEthernet.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 2db1c554a..56f7429dd 100644
--- a/AgroBase/AgroBase/Forms/frmPrincipal.Designer.cs
+++ b/AgroBase/AgroBase/Forms/frmPrincipal.Designer.cs
@@ -96,6 +96,7 @@ namespace AgroBase
this.lblProgressoAtualizacao = new System.Windows.Forms.Label();
this.pgbAtualizacaoArquivos = new System.Windows.Forms.ProgressBar();
this.btnForcarAtualizacao = new System.Windows.Forms.Button();
+ this.btnEthernet = new System.Windows.Forms.Button();
this.gpbAcoes.SuspendLayout();
this.erroStrip.SuspendLayout();
this.pnlLateral.SuspendLayout();
@@ -610,6 +611,7 @@ namespace AgroBase
// pnlAtalhos
//
this.pnlAtalhos.AutoScroll = true;
+ this.pnlAtalhos.Controls.Add(this.btnEthernet);
this.pnlAtalhos.Controls.Add(this.btnMKS);
this.pnlAtalhos.Controls.Add(this.btnBLD300R);
this.pnlAtalhos.Controls.Add(this.btnWT901C);
@@ -865,6 +867,17 @@ namespace AgroBase
this.btnForcarAtualizacao.UseVisualStyleBackColor = true;
this.btnForcarAtualizacao.Click += new System.EventHandler(this.btnForcarAtualizacao_Click);
//
+ // btnEthernet
+ //
+ this.btnEthernet.Location = new System.Drawing.Point(5, 391);
+ this.btnEthernet.Margin = new System.Windows.Forms.Padding(2);
+ this.btnEthernet.Name = "btnEthernet";
+ this.btnEthernet.Size = new System.Drawing.Size(84, 20);
+ this.btnEthernet.TabIndex = 30;
+ this.btnEthernet.Text = "Ethernet";
+ this.btnEthernet.UseVisualStyleBackColor = true;
+ this.btnEthernet.Click += new System.EventHandler(this.btnEthernet_Click);
+ //
// frmPrincipal
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -984,6 +997,7 @@ namespace AgroBase
public System.Windows.Forms.Label lblProgressoAtualizacao;
private System.Windows.Forms.ProgressBar pgbAtualizacaoArquivos;
private System.Windows.Forms.Button btnForcarAtualizacao;
+ private System.Windows.Forms.Button btnEthernet;
}
}
diff --git a/AgroBase/AgroBase/Forms/frmPrincipal.cs b/AgroBase/AgroBase/Forms/frmPrincipal.cs
index 443bcb131..6068438ed 100644
--- a/AgroBase/AgroBase/Forms/frmPrincipal.cs
+++ b/AgroBase/AgroBase/Forms/frmPrincipal.cs
@@ -454,10 +454,17 @@ namespace AgroBase
frm.Show();
}
+ private void btnEthernet_Click(object sender, EventArgs e)
+ {
+ frmEthernet frm = new frmEthernet();
+ frm.Show();
+ }
+
+
#endregion
-
+
}
}
diff --git a/AgroBase/AgroBase/Models/Modules/MovimentacaoUnificadoModel.cs b/AgroBase/AgroBase/Models/Modules/MovimentacaoUnificadoModel.cs
index 38986fa80..9826d81bf 100644
--- a/AgroBase/AgroBase/Models/Modules/MovimentacaoUnificadoModel.cs
+++ b/AgroBase/AgroBase/Models/Modules/MovimentacaoUnificadoModel.cs
@@ -10,7 +10,6 @@ namespace AgroBase.Models.Modules
{
public class MovimentacaoUnificadaModel : DispositivoBaseModel
{
- private bool _conectado = false;
public bool Conectado
{
get
@@ -19,19 +18,28 @@ namespace AgroBase.Models.Modules
}
set
{
- _conectado = value;
+
}
}
public static int _TaxaAmostragem { get; set; } = 1000;
- public List Modulos { get; set; } = new List();
-
- public static Direcao UltimaDirecao { get; set; } = Direcao.Parado;
+
public double DistanciaPercorridaOperacao { get; set; } = 0;
public int TempoEmAtividade { get; set; } = 0;
public double DistanciaPercorridaTotal { get; set; } = 0;
public double DistanciaPercorridaParcial { get; set; } = 0;
+ public double DiametroRoda { get; set; } = 0.3556;
+ public double ReducaoMotorBLDC { get; set; } = 5;
+ public double RPM_Max_MotorBLDC { get; set; } = 500;
+ public string IP_Bld { get; set; } = "192.168.100.110";
+ public string IP_Mks { get; set; } = "192.168.100.111";
+
+
+ public List Modulos { get; set; } = new List();
+
+ public static Direcao UltimaDirecao { get; set; } = Direcao.Parado;
+
public (bool, List) StatusModulosBLD(Direcao Lado)
{
string Prefixo = Lado == Direcao.Esquerda ? "E" : Lado == Direcao.Direita ? "D" : "";
@@ -659,15 +667,12 @@ namespace AgroBase.Models.Modules
{
get
{
- return RPM_SP / Reducao;
+ return RPM_SP / Convert.ToInt32(Variaveis.OperacaoEmAndamento.DispMvd.Dados.ReducaoMotorBLDC);
}
}
public Sentido Sentido_SP { get; set; } = Sentido.Parado;
public int NumeroPolos { get; set; } = 10;
public int Rampa { get; set; } = 0;
- public int RPM_Max { get; set; } = 500;
- public int Reducao { get; set; } = 5;
- public double DiametroRoda { get; set; } = 0.3556;
public double OffsetLeitura { get; set; } = 1.0;
@@ -825,7 +830,7 @@ namespace AgroBase.Models.Modules
Endereco + SerialService.SplitParams +
NumeroPolos + SerialService.SplitParams +
Rampa + SerialService.SplitParams +
- RPM_Max + SerialService.SplitParams +
+ Variaveis.OperacaoEmAndamento.DispMvd.Dados.RPM_Max_MotorBLDC + SerialService.SplitParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes);
return Protocolo;
diff --git a/AgroBase/AgroBase/Models/Variaveis.cs b/AgroBase/AgroBase/Models/Variaveis.cs
index 15e95a751..1053e22b1 100644
--- a/AgroBase/AgroBase/Models/Variaveis.cs
+++ b/AgroBase/AgroBase/Models/Variaveis.cs
@@ -60,6 +60,7 @@ namespace AgroBase.Models
{
public static int CameraSolo { get; } = 6522;
public static int CameraCaminho { get; } = 6544;
+ public static int Ethernet { get; } = 502;
}
public static class VariaveisEquipamento
@@ -83,7 +84,7 @@ namespace AgroBase.Models
{
double RpmMax =
Variaveis.OperacaoEmAndamento.DispMvd != null ?
- Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.RPM_Max) / RelacaoRPM :
+ Variaveis.OperacaoEmAndamento.DispMvd.Dados.RPM_Max_MotorBLDC / RelacaoRPM :
100;
return (int)RpmMax;
}
@@ -94,7 +95,7 @@ namespace AgroBase.Models
{
double RelacaoRPM =
Variaveis.OperacaoEmAndamento.DispMvd != null ?
- Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.Reducao) :
+ Variaveis.OperacaoEmAndamento.DispMvd.Dados.ReducaoMotorBLDC :
1;
return RelacaoRPM;
}
@@ -105,7 +106,7 @@ namespace AgroBase.Models
{
double diametro =
Variaveis.OperacaoEmAndamento.DispMvd != null ?
- Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.DiametroRoda) :
+ Variaveis.OperacaoEmAndamento.DispMvd.Dados.DiametroRoda :
0.3556;
return diametro;
}
diff --git a/AgroBase/AgroBase/Services/BLD300RService.cs b/AgroBase/AgroBase/Services/BLD300RService.cs
index 73f225346..85f83e238 100644
--- a/AgroBase/AgroBase/Services/BLD300RService.cs
+++ b/AgroBase/AgroBase/Services/BLD300RService.cs
@@ -1,7 +1,6 @@
using AgroBase.Models;
using System;
using System.Collections.Generic;
-using System.IO.Ports;
using System.Linq;
using System.Threading.Tasks;
using static AgroBase.Models.Enums;
@@ -11,41 +10,15 @@ namespace AgroBase.Services
{
public class BLD300RService
{
+ private static EthernetService _ethernetService;
public static bool Iniciado
{
get
{
- if (!SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Bld) && DadosLeitura.All(x => !x.Iniciado))
- {
- return false;
- }
- if (_PortaBLD != null && !_PortaBLD.IsOpen)
- {
- if (!SerialPort.GetPortNames().Any(x => x == _PortaBLD.PortName))
- {
- _PortaBLD = null;
- foreach (var d in SerialService.DispositivosMapeados.Where(x => x.Dispositivo == T_Code.Bld))
- {
- SerialService.DispositivosMapeados.Remove(d);
- }
- return false;
- }
- try
- {
- _PortaBLD.Open();
- }
- catch (Exception ex)
- {
- RegisrarErrosComunicacao(0, $"Erro ao abrir porta {_PortaBLD.PortName}. Erro={ex.Message}");
- //_PortaBLD = null;
- AtualizarPortaCOM(new SerialPort() { PortName = _PortaBLD.PortName, BaudRate = _PortaBLD.BaudRate });
- }
- }
- return _PortaBLD != null && _PortaBLD.IsOpen && DadosLeitura.Any(x => x.Iniciado);
+ return _ethernetService != null && _ethernetService.IsConnected && SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Bld) && DadosLeitura.Any(x => x.Iniciado);
}
}
public static int TaxaAmostragem { get; set; } = 1000;
- public static SerialPort _PortaBLD = new SerialPort();
public static List DadosLeitura = new List();
@@ -213,19 +186,56 @@ namespace AgroBase.Services
private static System.Timers.Timer tmrReceberDados = new System.Timers.Timer() { Interval = TaxaAmostragem, Enabled = false };
private static bool EnvioLiberado { get; set; } = true;
+ public static void IniciarRotinas()
+ {
+ //Task.Run(() => LoopEnvioComandos()); // Inicia o loop de comandos em segundo plano
+ //Task.Run(() => ReceberDados()); // Inicia a recepção de dados em segundo plano
+ if (!tmrReceberDados.Enabled)
+ {
+ tmrReceberDados.Elapsed += TmrReceberDados_Elapsed; ;
+ tmrReceberDados.Start();
+ }
+ if (!tmrLoopComandos.Enabled)
+ {
+ tmrLoopComandos.Elapsed += TmrLoopComandos_Elapsed;
+ tmrLoopComandos.Start();
+ }
+ }
- public static async Task VerificaPortaBLD(SerialPort porta)
+ // Inicializa o serviço Ethernet com IP e porta específicos
+ public static async Task InicializarEthernetService(string ipAddress, int port)
+ {
+ _ethernetService = new EthernetService(ipAddress, port);
+ return await _ethernetService.ConnectAsync();
+ }
+
+ public static async Task VerificaPortaBLD()
{
EnvioLiberado = false;
- if (!Iniciado)
+ if (_ethernetService == null)
{
- porta.Close();
- porta.BaudRate = 9600;
-
- AtualizarPortaCOM(porta);
+ bool connect = await InicializarEthernetService(Variaveis.OperacaoEmAndamento.DispMvd.Dados.IP_Bld, VariaveisPortas.Ethernet);
+ if (!connect)
+ {
+ Console.WriteLine("Falha ao inicializar o serviço Ethernet.");
+ EnvioLiberado = true;
+ return false;
+ }
}
-
+
+ if (_ethernetService._isReconnecting)
+ {
+ return false;
+ }
+
+ if (!Iniciado && !await _ethernetService.CheckConnectionAsync())
+ {
+ Console.WriteLine("Falha ao conectar ao dispositivo via Ethernet.");
+ EnvioLiberado = true;
+ return false;
+ }
+
var Parametro = Parametros.First(x => x.Chave == "Versao");
List Mod_IDs = new List();
@@ -249,11 +259,13 @@ namespace AgroBase.Services
var comando = ModbusService.ComandoGetParametro(Addr, Parametro);
- if (!EnviarComando(_PortaBLD, comando))
+ if (!await EnviarComando(_ethernetService, comando))
{
break;
}
- var resposta = await SerialService.LerDadosDaPortaSerialAsync(_PortaBLD, 7, 1000);
+
+ // Recebe a resposta via Ethernet
+ var resposta = await _ethernetService.ReceiveDataAsync(7);
DecifrarResposta(resposta, Parametro, Addr);
if (DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado))
@@ -267,44 +279,64 @@ namespace AgroBase.Services
DefinirDispositivo(Mod_IDs);
}
- if (!Iniciado)
- {
- _PortaBLD.Close();
- _PortaBLD = null;
- }
-
EnvioLiberado = true;
return Iniciado;
}
- public static void AtualizarPortaCOM(SerialPort Porta)
+ private static async Task EnviarComando(EthernetService ethernetService, byte[] comando)
{
- _PortaBLD = new SerialPort();
- _PortaBLD.PortName = Porta.PortName;
- _PortaBLD.BaudRate = Porta.BaudRate;
-
- _PortaBLD.Open();
- }
-
- private static void ReconectarPortaCOM()
- {
- RegisrarErrosComunicacao(0, $"Reiniciando conexão com a porta {_PortaBLD.PortName}...");
try
{
- _PortaBLD.Close();
+ return await ethernetService.SendDataAsync(comando);
}
- catch (Exception ex)
+ catch (Exception ex)
{
- RegisrarErrosComunicacao(0, $"Erro ao reiniciar conexão. Erro={ex.Message}");
+ Console.WriteLine($"Erro ao enviar comando: {ex.Message}");
+ return false;
}
+ }
- if (Iniciado)
+ public static async Task EnviarComandoControle(BLDComandoModel Comando)
+ {
+ try
{
- RegisrarErrosComunicacao(0, $"Reconexão com a porta {_PortaBLD.PortName} reestabelecida");
+ byte[] comando = Comando.Get
+ ? ModbusService.ComandoGetParametro(Comando.Endereco, Comando.Parametro)
+ : ModbusService.ComandoSetParametro(Comando.Endereco, Comando.Parametro, Comando.Valor);
+
+ if (comando != null && comando.Length > 0)
+ {
+ // Envia o comando via Ethernet
+ Comando.ErroEnvio = !await EnviarComando(_ethernetService, comando);
+ Comando.Enviado = true;
+
+ // Recebe a resposta via Ethernet, independentemente de precisar processá-la ou não
+ byte[] resposta = await _ethernetService.ReceiveDataAsync(7, 1000); // Timeout ajustável, aqui 1 segundo
+
+ if (Comando.AguardaResposta)
+ {
+ // Processa a resposta, pois é esperada
+ bool Respondido = DecifrarResposta(resposta, Comando.Parametro, Comando.Endereco);
+ if (!Respondido)
+ {
+ RegisrarErrosComunicacao(Comando.Endereco, $"Timeout ou erro ao receber resposta. GET={Comando.Get}, Parametro={Comando.Parametro.Chave}, Valor={Comando.Valor}");
+ Comando.Enviado = false;
+ Comando.Momento = DateTime.Now.AddMilliseconds(500); // Retenta após um pequeno intervalo
+ }
+ }
+ else
+ {
+ // Descarte da resposta, pois não era esperada
+ Console.WriteLine($"Resposta descartada para comando que não aguardava resposta.");
+ }
+ }
}
- else
+ catch (Exception ex)
{
- RegisrarErrosComunicacao(0, $"Erro ao reestabelecer conexão com a porta {_PortaBLD.PortName}");
+ // Log de erro
+ RegisrarErrosComunicacao(Comando.Endereco, $"Erro ao enviar comando: {ex.Message}");
+ Comando.Enviado = false;
+ Comando.Momento = DateTime.Now.AddMilliseconds(500);
}
}
@@ -327,7 +359,7 @@ namespace AgroBase.Services
var leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
{
- PortaCOM = _PortaBLD.PortName,
+ PortaCOM = _ethernetService != null ? _ethernetService._ipAddress : "N/A",
Dispositivo = T_Code.Bld,
Erro = leitura.CodigoAlarme > 0,
Versao = leitura.Versao.ToString(),
@@ -338,22 +370,94 @@ namespace AgroBase.Services
}
}
- public static void IniciarRotinas()
+ private static bool DecifrarResposta(byte[] resposta, ModbusParametrosModel Parametro, byte Addr)
{
- //Task.Run(() => LoopEnvioComandos()); // Inicia o loop de comandos em segundo plano
- //Task.Run(() => ReceberDados()); // Inicia a recepção de dados em segundo plano
- if (!tmrReceberDados.Enabled)
+ try
{
- tmrReceberDados.Elapsed += TmrReceberDados_Elapsed; ;
- tmrReceberDados.Start();
+ if (resposta == null || resposta.Length == 0)
+ {
+ return false;
+ }
+
+ var Leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
+ if (Leitura == null)
+ {
+ Leitura = new BLD300RModel()
+ {
+ Endereco = Addr,
+ UltimoComandoRecebido = DateTime.MinValue,
+ parametros = new List()
+ {
+ new BLDParametrosRequisitar()
+ {
+ Registro = Parametro.Registro,
+ Escala = Parametro.Escala,
+ Valor = null
+ }
+ }
+ };
+ DadosLeitura.Add(Leitura);
+ }
+
+ if (resposta.Length > 3)
+ {
+ if (Parametros.Any(x => 0x03 == resposta[1]))
+ {
+ int num_registros = resposta[2];
+ byte[] bytes_resposta = resposta.Skip(3).Take(num_registros).ToArray();
+
+ Parametro.Valor = bytes_resposta;
+ Leitura.UltimoComandoRecebido = DateTime.Now;
+ return true;
+ }
+ else if (Parametros.Any(x => 0x06 == resposta[1]))
+ {
+ Parametro.Valor = resposta.Skip(4).Take(2).ToArray();
+ Leitura.UltimoComandoRecebido = DateTime.Now;
+ return true;
+ }
+ }
+ RegisrarErrosComunicacao(Addr, $"Resposta inválida. {BitConverter.ToString(resposta)}");
+ return false;
}
- if (!tmrLoopComandos.Enabled)
+ catch (Exception ex)
{
- tmrLoopComandos.Elapsed += TmrLoopComandos_Elapsed;
- tmrLoopComandos.Start();
+ RegisrarErrosComunicacao(Addr, $"Erro ao decifrar resposta. {BitConverter.ToString(resposta)}");
+ return false;
}
}
+ private static void RegisrarErrosComunicacao(byte addr, string mensagem)
+ {
+ try
+ {
+ var Caminho = Variaveis.CaminhoLogsDispositivos;
+ if (!Directory.Exists(Caminho))
+ {
+ Directory.CreateDirectory(Caminho);
+ }
+
+ var Arquivo = T_Code.Bld.ToString() + "_err.txt";
+ Caminho += "/" + Arquivo;
+
+ mensagem = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff") + " - Endereço " + addr + " (" + _ethernetService._ipAddress + "): " + mensagem + Environment.NewLine;
+
+ if (!File.Exists(Caminho))
+ {
+ File.WriteAllText(Caminho, mensagem);
+ }
+ else
+ {
+ File.AppendAllText(Caminho, mensagem);
+ }
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao salvar log de erro BLD");
+ }
+ }
+
+
private static async void TmrLoopComandos_Elapsed(object sender, EventArgs e)
{
((System.Timers.Timer)sender).Stop();
@@ -366,32 +470,6 @@ namespace AgroBase.Services
((System.Timers.Timer)sender).Start();
}
- private static bool EnviarComando(SerialPort _Porta, byte[] Comando)
- {
- lock (FilaLock)
- {
- try
- {
- if (_Porta != null)
- {
- if (!_Porta.IsOpen)
- {
- _Porta.Open();
- }
- if (_Porta.IsOpen)
- {
- return SerialService.EnviarDadosPortaSerial(_Porta, Comando, 0, Comando.Length);
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- return false;
- }
- }
-
private static void TmrReceberDados_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
((System.Timers.Timer)sender).Stop();
@@ -411,8 +489,6 @@ namespace AgroBase.Services
TaxaAmostragem = 3000;
- ReconectarPortaCOM();
-
((System.Timers.Timer)sender).Start();
return;
}
@@ -470,83 +546,6 @@ namespace AgroBase.Services
((System.Timers.Timer)sender).Start();
}
- private static bool DecifrarResposta(byte[] resposta, ModbusParametrosModel Parametro, byte Addr)
- {
- try
- {
- var Leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
- if (Leitura == null)
- {
- Leitura = new BLD300RModel()
- {
- Endereco = Addr,
- UltimoComandoRecebido = DateTime.MinValue,
- parametros = new List()
- {
- new BLDParametrosRequisitar()
- {
- Registro = Parametro.Registro,
- Escala = Parametro.Escala,
- Valor = null
- }
- }
- };
- DadosLeitura.Add(Leitura);
- }
- var ParametroLeitura = Leitura.parametros.FirstOrDefault(x => x.Registro == Parametro.Registro);
- if (ParametroLeitura == null)
- {
- ParametroLeitura = new BLDParametrosRequisitar()
- {
- Registro = Parametro.Registro,
- Escala = Parametro.Escala,
- Valor = null
- };
- Leitura.parametros.Add(ParametroLeitura);
- }
-
- if (resposta.Length > 3)
- {
- if (Parametros.Any(x => 0x03 == resposta[1]))
- {
- int num_registros = resposta[2];
- byte[] bytes_resposta = resposta.Skip(3).Take(num_registros).ToArray(); // Ajustando para pegar 2 bytes por registro
-
- Parametro.Valor = bytes_resposta;
-
- Parametro.UltimaRequisicao = DateTime.MaxValue;
-
- ParametroLeitura.Valor = Parametro.Valor;
- Leitura.UltimoComandoRecebido = DateTime.Now;
- return true;
- }
- else if (Parametros.Any(x => 0x06 == resposta[1]))
- {
- Parametro.Valor = resposta.Skip(4).Take(2).ToArray();
-
- ParametroLeitura.Valor = Parametro.Valor;
- Leitura.UltimoComandoRecebido = DateTime.Now;
- return true;
- }
- else
- {
- RegisrarErrosComunicacao(Addr, $"Resposta inválida ou código de função incorreto. {BitConverter.ToString(resposta)}");
- }
-
- return false;
- }
-
- RegisrarErrosComunicacao(Addr, $"Resposta inválida. {BitConverter.ToString(resposta)}");
- return false;
- }
- catch (Exception ex)
- {
- RegisrarErrosComunicacao(Addr, $"Erro ao decifrar resposta. {BitConverter.ToString(resposta)}");
- return false;
- }
- }
-
-
private static void ConfigurarDriver(byte Addr)
{
@@ -585,7 +584,7 @@ namespace AgroBase.Services
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "RPM_Max"),
- Valor = Modulo.MovMotor.RPM_Max
+ Valor = (int)Variaveis.OperacaoEmAndamento.DispMvd.Dados.RPM_Max_MotorBLDC
});
AdicionarComandoNaFila(new BLDComandoModel()
{
@@ -608,51 +607,6 @@ namespace AgroBase.Services
DadosLeitura.Where(x => x.Endereco == Addr).First().Configurado = true;
}
- public static async Task EnviarComandoControle(BLDComandoModel Comando)
- {
- try
- {
- byte[] comando = null;
-
- if (Comando.Get)
- {
- comando = ModbusService.ComandoGetParametro(Comando.Endereco, Comando.Parametro);
- }
- else
- {
- comando = ModbusService.ComandoSetParametro(Comando.Endereco, Comando.Parametro, Comando.Valor);
- }
-
- if (comando != null && comando.Length > 0)
- {
- //Console.WriteLine("Enviando comando para o endereço: " + Comando.Endereco);
- Comando.ErroEnvio = !EnviarComando(_PortaBLD, comando);
-
- Comando.Enviado = true;
-
- if (Comando.AguardaResposta && !Comando.ErroEnvio)
- {
- byte[] resposta = await SerialService.LerDadosDaPortaSerialAsync(_PortaBLD, 7, Comando.TimeoutResposta);
- bool Respondido = DecifrarResposta(resposta, Comando.Parametro, Comando.Endereco);
- if (!Respondido)
- {
- RegisrarErrosComunicacao(Comando.Endereco, $"Timeout ao receber resposta. GET={Comando.Get}, Parametro={Comando.Parametro.Chave}, Valor={Comando.Valor}");
- Comando.Enviado = false;
- Comando.Momento = DateTime.Now.AddMilliseconds(500);
- //ReconectarPortaCOM();
- }
- }
- }
- }
- catch (IOException ex)
- {
- RegisrarErrosComunicacao(Comando.Endereco, $"Erro ao enviar comando. GET={Comando.Get}, Parametro={Comando.Parametro.Chave}, Valor={Comando.Valor}, Erro={ex.Message}");
- Comando.Enviado = false;
- Comando.Momento = DateTime.Now.AddMilliseconds(500);
- ReconectarPortaCOM();
- }
- }
-
public static void AdicionarComandoNaFila(BLDComandoModel Comando)
{
lock (FilaLock)
@@ -668,6 +622,16 @@ namespace AgroBase.Services
{
EnvioLiberado = false;
+ // Verifica se a conexão foi perdida e tenta reconectar
+ if (_ethernetService != null && !_ethernetService.IsConnected)
+ {
+ if (!await _ethernetService.ReconnectAsync())
+ {
+ EnvioLiberado = true;
+ return;
+ }
+ }
+
try
{
await ProcessarFilaPrioridade();
@@ -717,41 +681,6 @@ namespace AgroBase.Services
}
}
- private static void RegisrarErrosComunicacao(byte addr, string mensagem)
- {
- if (_PortaBLD == null)
- {
- return;
- }
-
- try
- {
- var Caminho = Variaveis.CaminhoLogsDispositivos;
- if (!Directory.Exists(Caminho))
- {
- Directory.CreateDirectory(Caminho);
- }
-
- var Arquivo = T_Code.Bld.ToString() + "_err.txt";
- Caminho += "/" + Arquivo;
-
- mensagem = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff") + " - Porta " + _PortaBLD.PortName + " - " + addr + ": " + mensagem + Environment.NewLine;
-
- if (!File.Exists(Caminho))
- {
- File.WriteAllText(Caminho, mensagem);
- }
- else
- {
- File.AppendAllText(Caminho, mensagem);
- }
- }
- catch
- {
- Console.WriteLine("Erro ao salvar log de erro BLD");
- }
- }
-
public class BLDParametrosRequisitar
{
public byte Registro { get; set; }
diff --git a/AgroBase/AgroBase/Services/EthernetService.cs b/AgroBase/AgroBase/Services/EthernetService.cs
new file mode 100644
index 000000000..3d15d73ad
--- /dev/null
+++ b/AgroBase/AgroBase/Services/EthernetService.cs
@@ -0,0 +1,369 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+public class EthernetService
+{
+ public readonly string _ipAddress;
+ private readonly int _port;
+ private TcpClient _client;
+ private NetworkStream _networkStream;
+
+ public bool IsConnected
+ {
+ get
+ {
+ try
+ {
+ // Verifica se o cliente foi inicializado e está conectado
+ return _client != null && _client.Client != null && _client.Client.Connected;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+ }
+
+ public EthernetService(string ipAddress, int port)
+ {
+ _ipAddress = ipAddress;
+ _port = port;
+ }
+
+ // Método para estabelecer conexão TCP com o conversor Ethernet-RS485
+ public async Task ConnectAsync(int timeoutMilliseconds = 1000)
+ {
+ try
+ {
+ _client = new TcpClient();
+
+ using (var cts = new CancellationTokenSource(timeoutMilliseconds))
+ {
+ var connectTaskCompletionSource = new TaskCompletionSource();
+
+ var connectTask = _client.ConnectAsync(_ipAddress, _port).ContinueWith(t =>
+ {
+ if (t.IsCompleted)
+ {
+ connectTaskCompletionSource.TrySetResult(true);
+ }
+ else if (t.IsFaulted)
+ {
+ connectTaskCompletionSource.TrySetException(t.Exception?.InnerException ?? t.Exception);
+ }
+ else
+ {
+ connectTaskCompletionSource.TrySetResult(false);
+ }
+ }, TaskScheduler.Default);
+
+ var completedTask = await Task.WhenAny(connectTaskCompletionSource.Task, Task.Delay(timeoutMilliseconds, cts.Token));
+
+ if (completedTask == connectTaskCompletionSource.Task && await connectTaskCompletionSource.Task)
+ {
+ if (_client.Connected)
+ {
+ _networkStream = _client.GetStream();
+ return true;
+ }
+ }
+
+ // Timeout foi atingido; limpa a conexão
+ Console.WriteLine("Conexão cancelada devido ao timeout.");
+ _client.Dispose();
+ return false;
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ Console.WriteLine("Conexão cancelada pela operação.");
+ return false;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Erro ao conectar: {ex.Message}");
+ _client?.Close();
+ return false;
+ }
+ }
+
+
+ // Método para desconectar e liberar recursos
+ public void Disconnect()
+ {
+ try
+ {
+ _networkStream?.Close();
+ _client?.Close();
+ _networkStream = null;
+ _client = null;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Erro ao desconectar: {ex.Message}");
+ }
+ }
+
+ // Método para enviar dados ao dispositivo via Ethernet
+ public async Task SendDataAsync(byte[] data)
+ {
+ if (IsConnected && _networkStream.CanWrite)
+ {
+ try
+ {
+ await _networkStream.WriteAsync(data, 0, data.Length);
+ await _networkStream.FlushAsync();
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Erro ao enviar dados: {ex.Message}");
+ }
+ }
+ else
+ {
+ Console.WriteLine("Não conectado ao dispositivo.");
+ }
+ return false;
+ }
+
+ // Método para receber dados do dispositivo via Ethernet
+ public async Task ReceiveDataAsync(int expectedLength, int timeoutMilliseconds = 1000)
+ {
+ var buffer = new byte[expectedLength];
+
+ try
+ {
+ var readTask = _networkStream.ReadAsync(buffer, 0, expectedLength); // Tarefa de leitura sem o token
+
+ // Cria uma tarefa de delay que representa o timeout
+ if (await Task.WhenAny(readTask, Task.Delay(timeoutMilliseconds)) == readTask)
+ {
+ // Se readTask completa antes do timeout
+ var bytesRead = await readTask;
+ Array.Resize(ref buffer, bytesRead); // Ajusta o tamanho do buffer para os bytes lidos
+ return buffer;
+ }
+ else
+ {
+ // Se o timeout for atingido, retorna nulo ou exibe uma mensagem
+ Console.WriteLine("Timeout ao receber dados via Ethernet.");
+ return null;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Erro ao receber dados: {ex.Message}");
+ return null;
+ }
+ }
+
+ // Método para verificar a conexão (pode ser usado para um "heartbeat")
+ public async Task CheckConnectionAsync()
+ {
+ if (!IsConnected)
+ {
+ Console.WriteLine("Conexão perdida. Tentando reconectar...");
+ return await ConnectAsync();
+ }
+ return true;
+ }
+
+
+ public bool _isReconnecting = false;
+ private int _reconnectAttempts = 0;
+ private const int MaxReconnectAttempts = 5;
+ private const int ReconnectInterval = 2000; // Intervalo de 2000 ms = 2 segundos
+ // Método para gerenciar a reconexão
+ public async Task ReconnectAsync()
+ {
+ if (_isReconnecting) return false; // Evita tentativas duplicadas
+
+ _isReconnecting = true;
+ try
+ {
+ while (_reconnectAttempts < MaxReconnectAttempts && !IsConnected)
+ {
+ Console.WriteLine($"Tentando reconectar ao IP {_ipAddress}... Tentativa {_reconnectAttempts + 1}");
+ bool connected = await ConnectAsync(5000);
+
+ if (connected)
+ {
+ Console.WriteLine("Reconexão bem-sucedida.");
+ _reconnectAttempts = 0;
+ return true;
+ }
+ else
+ {
+ _reconnectAttempts++;
+ await Task.Delay(ReconnectInterval);
+ }
+ }
+
+ if (!IsConnected)
+ {
+ Console.WriteLine("Número máximo de tentativas de reconexão atingido.");
+ await Task.Delay(5000);
+ _reconnectAttempts = 0;
+ }
+ return IsConnected;
+ }
+ finally
+ {
+ _isReconnecting = false; // Libera para novas tentativas futuras
+ }
+ }
+
+
+
+
+
+ public static List ObterNomesInterfaces()
+ {
+ var listaInterfaces = new List();
+ var interfaces = NetworkInterface.GetAllNetworkInterfaces();
+
+ foreach (var nic in interfaces)
+ {
+ string status = nic.OperationalStatus == OperationalStatus.Up ? "Ativa" : "Inativa";
+ listaInterfaces.Add($"{nic.Name} ({status})");
+ }
+
+ return listaInterfaces;
+ }
+
+ // Obtém o IP do gateway padrão (roteador) da rede ativa
+ public static string ObterIpGateway()
+ {
+ foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (networkInterface.OperationalStatus == OperationalStatus.Up)
+ {
+ foreach (GatewayIPAddressInformation gateway in networkInterface.GetIPProperties().GatewayAddresses)
+ {
+ if (gateway.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
+ {
+ return gateway.Address.ToString();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ // Obtém o IP atual do PC na rede ativa
+ public static string ObterIpAtual()
+ {
+ foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (networkInterface.OperationalStatus == OperationalStatus.Up)
+ {
+ foreach (UnicastIPAddressInformation ip in networkInterface.GetIPProperties().UnicastAddresses)
+ {
+ if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
+ {
+ return ip.Address.ToString();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static string ObterSubnetMaskAtual()
+ {
+ foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (networkInterface.OperationalStatus == OperationalStatus.Up)
+ {
+ foreach (UnicastIPAddressInformation ip in networkInterface.GetIPProperties().UnicastAddresses)
+ {
+ if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
+ {
+ return ip.IPv4Mask.ToString(); // Retorna a máscara de sub-rede como string
+ }
+ }
+ }
+ }
+ return null; // Retorna null se não encontrar uma máscara de sub-rede
+ }
+
+ public static string ObterTipoConfiguracaoIP()
+ {
+ foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (networkInterface.OperationalStatus == OperationalStatus.Up)
+ {
+ var ipProperties = networkInterface.GetIPProperties();
+ if (ipProperties.GatewayAddresses.Count > 0) // Confirma que há um gateway configurado
+ {
+ // Verifica se o DHCP está habilitado para IPv4
+ if (ipProperties.GetIPv4Properties().IsDhcpEnabled)
+ {
+ return "Dinâmico (DHCP)";
+ }
+ else
+ {
+ return "IP Fixo (Estático)";
+ }
+ }
+ }
+ }
+ return "Nenhuma interface de rede ativa encontrada";
+ }
+
+ public static void DefinirIpDinamico(string interfaceName)
+ {
+ // Define o IP para DHCP
+ string comandoIp = $"interface ip set address \"{interfaceName}\" dhcp";
+ // Define o DNS para DHCP
+ string comandoDns = $"interface ip set dns \"{interfaceName}\" dhcp";
+
+ ExecutarComandoNetsh(comandoIp);
+ ExecutarComandoNetsh(comandoDns);
+ }
+
+ public static void DefinirIpFixo(string nomeInterface, string ipAddress, string subnetMask, string gateway)
+ {
+ try
+ {
+ // Define o IP fixo na interface de rede
+ string comandoIp = $"interface ip set address name=\"{nomeInterface}\" static {ipAddress} {subnetMask} {gateway}";
+ ExecutarComandoNetsh(comandoIp);
+
+ // Configura o DNS para automático (caso desejado)
+ string comandoDns = $"interface ip set dns name=\"{nomeInterface}\" source=static addr=8.8.8.8 register=primary";
+ ExecutarComandoNetsh(comandoDns);
+
+ MessageBox.Show("IP fixo definido com sucesso!", "Configuração de IP", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Erro ao definir IP fixo: {ex.Message}", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private static string ExecutarComandoNetsh(string comando)
+ {
+ Process process = new Process();
+ process.StartInfo.FileName = "netsh";
+ process.StartInfo.Arguments = comando;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.UseShellExecute = false;
+ process.StartInfo.CreateNoWindow = true;
+ process.Start();
+
+ string output = process.StandardOutput.ReadToEnd();
+ process.WaitForExit();
+ return output;
+ }
+
+}
diff --git a/AgroBase/AgroBase/Services/MKS057DService.cs b/AgroBase/AgroBase/Services/MKS057DService.cs
index c78b7bebe..4d01db808 100644
--- a/AgroBase/AgroBase/Services/MKS057DService.cs
+++ b/AgroBase/AgroBase/Services/MKS057DService.cs
@@ -3,8 +3,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
-using System.IO.Ports;
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enums;
@@ -13,139 +13,29 @@ namespace AgroBase.Services
{
public class MKS057DService
{
+ private static EthernetService _ethernetService;
public static bool Iniciado
{
get
{
- if (!SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks) && DadosLeitura.All(x => !x.Iniciado))
- {
- return false;
- }
- lock (_PortaLock)
- {
- if (_PortaMKS != null && !_PortaMKS.IsOpen)
- {
- if (!SerialPort.GetPortNames().Any(x => x == _PortaMKS.PortName))
- {
- _PortaMKS = null;
- foreach (var d in SerialService.DispositivosMapeados.Where(x => x.Dispositivo == T_Code.Mks))
- {
- SerialService.DispositivosMapeados.Remove(d);
- }
- return false;
- }
- try
- {
- _PortaMKS.Open();
- }
- catch (Exception ex)
- {
- RegisrarErrosComunicacao(0, $"Erro ao abrir porta {_PortaMKS.PortName}. Erro={ex.Message}");
- //_PortaMKS = null;
- AtualizarPortaCOM(new SerialPort() { PortName = _PortaMKS.PortName, BaudRate = _PortaMKS.BaudRate });
- }
- }
- return _PortaMKS != null && _PortaMKS.IsOpen && DadosLeitura.Any(x => x.Iniciado);
- }
+ return _ethernetService != null && _ethernetService.IsConnected && SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks) && DadosLeitura.Any(x => x.Iniciado);
}
}
public static int TaxaAmostragem { get; set; } = 1000;
- public static SerialPort _PortaMKS = new SerialPort();
private static System.Timers.Timer tmrLoopComandos = new System.Timers.Timer() { Interval = 100, Enabled = false };
private static System.Timers.Timer tmrReceberDados = new System.Timers.Timer() { Interval = TaxaAmostragem, Enabled = false };
- public static readonly object _PortaLock = new object();
-
- public static async Task VerificaPortaMKS(SerialPort porta)
+ private static List FilaComandos = new List();
+ private static readonly object FilaLock = new object();
+ private static bool EnvioLiberado { get; set; } = true;
+ public static List DadosLeitura = new List();
+ public static bool FilaEmEspera = false;
+ public static bool Respondido = false;
+ public static byte AddrRef = 0x00;
+ public static bool Referenciando
{
- EnvioLiberado = false;
-
- if (!Iniciado)
+ get
{
- porta.Close();
- porta.BaudRate = 38400;
-
- AtualizarPortaCOM(porta);
- }
-
- List Mod_IDs = new List();
-
- foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.DirMotor.MKS_Inicializado))
- {
- byte Addr = Convert.ToByte(Modulo.DirMotor.Endereco, 16);
-
- DataSended = Convert.ToByte("43");
-
- await SendRelevantData(Addr, QueryCommand[DataSended]);
-
- bool respondido = false;
- DateTime inicio = DateTime.Now;
- while (!respondido && inicio.AddMilliseconds(1000) > DateTime.Now)
- {
- await Task.Delay(100);
- respondido = DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado);
- }
-
- if (respondido)
- {
- Mod_IDs.Add(Modulo.Modulo_ID);
- }
- }
-
- if (Mod_IDs.Any())
- {
- DefinirDispositivo(Mod_IDs);
- }
-
- if (!Iniciado)
- {
- lock (_PortaLock)
- {
- _PortaMKS.Close();
- _PortaMKS = null;
- }
- }
-
- EnvioLiberado = true;
- return Iniciado;
- }
-
- public static void AtualizarPortaCOM(SerialPort Porta)
- {
- lock (_PortaLock)
- {
- _PortaMKS = new SerialPort();
- _PortaMKS.PortName = Porta.PortName;
- _PortaMKS.BaudRate = Porta.BaudRate;
-
- _PortaMKS.DataReceived -= port_DataReceived;
- _PortaMKS.DataReceived += port_DataReceived;
-
- _PortaMKS.Open();
- }
- }
-
- private static void DefinirDispositivo(List Mod_IDs)
- {
- foreach (var Mod_ID in Mod_IDs)
- {
- var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == Mod_ID);
- byte Addr = Convert.ToByte(Modulo.DirMotor.Endereco.Replace("0x", ""), 16);
-
- if (!SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks && x.Mod_ID == Mod_ID))
- {
- var Leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
- if (Leitura != null)
- {
- SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
- {
- PortaCOM = _PortaMKS.PortName,
- Dispositivo = T_Code.Mks,
- Erro = (Leitura.Mensagem ?? "") != "",
- Versao = (Leitura.FV ?? "").ToString(),
- Mod_ID = Mod_ID,
- });
- }
- }
+ return AddrRef > 0x00;
}
}
@@ -165,6 +55,147 @@ namespace AgroBase.Services
}
}
+ // Inicializa o serviço Ethernet com IP e porta específicos
+ public static async Task InicializarEthernetService(string ipAddress, int port)
+ {
+ _ethernetService = new EthernetService(ipAddress, port);
+ return await _ethernetService.ConnectAsync();
+ }
+
+ public static async Task VerificaPortaMKS()
+ {
+ EnvioLiberado = false;
+
+ if (_ethernetService == null)
+ {
+ bool connect = await InicializarEthernetService(Variaveis.OperacaoEmAndamento.DispMvd.Dados.IP_Mks, VariaveisPortas.Ethernet);
+ if (!connect)
+ {
+ Console.WriteLine("Falha ao inicializar o serviço Ethernet.");
+ EnvioLiberado = true;
+ return false;
+ }
+ }
+
+ if (_ethernetService._isReconnecting)
+ {
+ return false;
+ }
+
+ if (!Iniciado && !await _ethernetService.CheckConnectionAsync())
+ {
+ Console.WriteLine("Falha ao conectar ao dispositivo via Ethernet.");
+ EnvioLiberado = true;
+ return false;
+ }
+
+ List Mod_IDs = new List();
+
+ // Verifica e inicializa cada módulo conectado
+ foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.DirMotor.MKS_Inicializado))
+ {
+ byte Addr = Convert.ToByte(Modulo.DirMotor.Endereco, 16);
+ DataSended = Convert.ToByte("43");
+
+ // Envia comando relevante para verificar o dispositivo
+ bool envioBemSucedido = await SendRelevantData(Addr, QueryCommand[DataSended]);
+ if (!envioBemSucedido)
+ {
+ Console.WriteLine($"Falha ao enviar dados para o dispositivo de endereço {Addr}.");
+ continue;
+ }
+
+ // Aguarda resposta do dispositivo com controle de timeout
+ bool respondido = false;
+ using (var cts = new CancellationTokenSource(1000)) // Timeout de 1000 ms
+ {
+ try
+ {
+ while (!respondido && !cts.Token.IsCancellationRequested)
+ {
+ await Task.Delay(100, cts.Token);
+ respondido = DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado);
+ }
+ }
+ catch (TaskCanceledException)
+ {
+ Console.WriteLine($"Timeout ao aguardar resposta do dispositivo com endereço {Addr}.");
+ }
+ }
+
+ if (respondido)
+ {
+ Mod_IDs.Add(Modulo.Modulo_ID);
+ }
+ }
+
+ // Define os dispositivos inicializados na lista de dispositivos mapeados
+ if (Mod_IDs.Any())
+ {
+ DefinirDispositivo(Mod_IDs);
+ }
+
+ EnvioLiberado = true;
+ return Iniciado;
+ }
+
+ private static void RegisrarErrosComunicacao(byte addr, string mensagem)
+ {
+ try
+ {
+ var Caminho = Variaveis.CaminhoLogsDispositivos;
+ if (!Directory.Exists(Caminho))
+ {
+ Directory.CreateDirectory(Caminho);
+ }
+
+ var Arquivo = T_Code.Mks.ToString() + "_err.txt";
+ Caminho += "/" + Arquivo;
+
+ mensagem = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff") + " - Endereço " + addr + " (" + _ethernetService._ipAddress + "): " + mensagem + Environment.NewLine;
+
+ if (!File.Exists(Caminho))
+ {
+ File.WriteAllText(Caminho, mensagem);
+ }
+ else
+ {
+ File.AppendAllText(Caminho, mensagem);
+ }
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao salvar log de erro MKS");
+ }
+ }
+
+ private static void DefinirDispositivo(List Mod_IDs)
+ {
+ foreach (var Mod_ID in Mod_IDs)
+ {
+ var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == Mod_ID);
+ byte Addr = Convert.ToByte(Modulo.DirMotor.Endereco.Replace("0x", ""), 16);
+
+ if (!SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks && x.Mod_ID == Mod_ID))
+ {
+ var Leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
+ if (Leitura != null)
+ {
+ SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
+ {
+ PortaCOM = _ethernetService != null ? _ethernetService._ipAddress : "N/A",
+ Dispositivo = T_Code.Mks,
+ Erro = (Leitura.Mensagem ?? "") != "",
+ Versao = (Leitura.FV ?? "").ToString(),
+ Mod_ID = Mod_ID,
+ });
+ }
+ }
+ }
+ }
+
+
+
private static void TmrReceberDados_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
((System.Timers.Timer)sender).Stop();
@@ -178,8 +209,6 @@ namespace AgroBase.Services
TaxaAmostragem = 3000;
- ReconectarPortaCOM();
-
((System.Timers.Timer)sender).Start();
return;
}
@@ -239,6 +268,16 @@ namespace AgroBase.Services
{
EnvioLiberado = false;
+ // Verifica se a conexão foi perdida e tenta reconectar
+ if (_ethernetService != null && !_ethernetService.IsConnected)
+ {
+ if (!await _ethernetService.ReconnectAsync())
+ {
+ EnvioLiberado = true;
+ return;
+ }
+ }
+
try
{
await ProcessarFilaPrioridade();
@@ -288,66 +327,8 @@ namespace AgroBase.Services
}
}
- private static void RegisrarErrosComunicacao(byte addr, string mensagem)
- {
- try
- {
- var Caminho = Variaveis.CaminhoLogsDispositivos;
- if (!Directory.Exists(Caminho))
- {
- Directory.CreateDirectory(Caminho);
- }
-
- var Arquivo = T_Code.Mks.ToString() + "_err.txt";
- Caminho += "/" + Arquivo;
-
- mensagem = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff") + " - Porta " + (_PortaMKS?.PortName ?? "COM") + " - " + addr + ": " + mensagem + Environment.NewLine;
-
- if (!File.Exists(Caminho))
- {
- File.WriteAllText(Caminho, mensagem);
- }
- else
- {
- File.AppendAllText(Caminho, mensagem);
- }
- }
- catch
- {
- Console.WriteLine("Erro ao salvar log de erro MKS");
- }
- }
-
- private static void ReconectarPortaCOM()
- {
- lock (_PortaLock)
- {
- if (_PortaMKS == null)
- {
- return;
- }
- RegisrarErrosComunicacao(0, $"Reiniciando conexão com a porta {_PortaMKS.PortName}...");
- try
- {
- _PortaMKS.Close();
- }
- catch (Exception ex)
- {
- RegisrarErrosComunicacao(0, $"Erro ao reiniciar conexão. Erro={ex.Message}");
- }
-
- if (Iniciado)
- {
- RegisrarErrosComunicacao(0, $"Reconexão com a porta {_PortaMKS.PortName} reestabelecida");
- }
- else
- {
- RegisrarErrosComunicacao(0, $"Erro ao reestabelecer conexão com a porta {_PortaMKS.PortName}");
- }
- }
- }
-
-
+
+
//static byte Addr;
static byte DataSended;
@@ -483,21 +464,7 @@ namespace AgroBase.Services
#endregion
- private static List FilaComandos = new List();
- private static readonly object FilaLock = new object();
- private static bool EnvioLiberado { get; set; } = true;
-
- public static List DadosLeitura = new List();
- public static bool FilaEmEspera = false;
- public static bool Respondido = false;
- public static byte AddrRef = 0x00;
- public static bool Referenciando
- {
- get
- {
- return AddrRef > 0x00;
- }
- }
+
@@ -557,6 +524,7 @@ namespace AgroBase.Services
{
byte Addr = Comando.Endereco;
+ // Configura parâmetros de controle localmente antes de enviar o comando
if (!Comando.Get)
{
if (!_Angulo.ContainsKey(Addr))
@@ -580,26 +548,52 @@ namespace AgroBase.Services
DataSended = Comando.Comando;
- await SendRelevantData(Addr, QueryCommand[DataSended]);
+ // Envia o comando via Ethernet
+ bool sucessoEnvio = await SendRelevantData(Addr, QueryCommand[DataSended]);
+ Comando.Enviado = sucessoEnvio;
+
+ if (!sucessoEnvio)
+ {
+ RegisrarErrosComunicacao(Addr, "Erro ao enviar dados via Ethernet");
+ return;
+ }
+
+ await ProcessarDadosRecebidosAsync();
- Comando.Enviado = true;
Respondido = !Comando.AguardaResposta;
- DateTime Inicio = DateTime.Now;
- while (Comando.AguardaResposta && !Respondido && Inicio.AddMilliseconds(Comando.TimeoutResposta) > DateTime.Now)
+ // Se o comando não aguarda resposta, finaliza aqui
+ if (Respondido)
{
- await Task.Delay(100);
+ return;
}
- if (!Respondido)
+ // Configura o token de cancelamento para controlar o timeout de resposta
+ var cts = new CancellationTokenSource();
+ cts.CancelAfter(Comando.TimeoutResposta);
+
+ try
{
- RegisrarErrosComunicacao(Addr, $"Timeout ao receber resposta. GET={Comando.Get}, Parametro={Comando.Comando}");
+ while (!Respondido && !cts.Token.IsCancellationRequested)
+ {
+ await Task.Delay(100, cts.Token);
+ }
+
+ if (!Respondido)
+ {
+ RegisrarErrosComunicacao(Addr, $"Timeout ao receber resposta. GET={Comando.Get}, Parametro={Comando.Comando}");
+ Comando.Enviado = false;
+ Comando.Momento = DateTime.Now.AddMilliseconds(500);
+ }
+ }
+ catch (TaskCanceledException)
+ {
+ RegisrarErrosComunicacao(Addr, "Timeout atingido durante a espera pela resposta do comando");
Comando.Enviado = false;
- Comando.Momento = DateTime.Now.AddMilliseconds(500);
- //ReconectarPortaCOM();
}
}
+
public static void AdicionaComandosGoHomeFila(byte Endereco)
{
// Configura o GoHome
@@ -678,1010 +672,61 @@ namespace AgroBase.Services
#region METODOS PRINCIPAIS
- private static void WriteByteToSerialPort(byte[] data, byte start, byte length)
+ private static async Task WriteByteToEthernetAsync(byte[] data, byte start, byte length)
{
byte Addr = data[1];
- lock (_PortaLock)
+ if (_ethernetService == null || !_ethernetService.IsConnected)
{
- if (_PortaMKS == null)
+ RegisrarErrosComunicacao(Addr, "Conexão Ethernet não está definida ou não está conectada");
+ return false;
+ }
+
+ try
+ {
+ bool sucesso = await _ethernetService.SendDataAsync(data.Skip(start).Take(length).ToArray());
+ if (sucesso)
{
- RegisrarErrosComunicacao(Addr, "Porta serial não está definida");
- }
- else if (_PortaMKS.IsOpen)
- {
- try
- {
- SerialService.EnviarDadosPortaSerial(_PortaMKS, data, start, length);
- txDisplay();
- }
- catch
- {
- RegisrarErrosComunicacao(Addr, "Erro ao enviar dados para a porta serial");
- }
+ txDisplay(data);
}
else
{
- RegisrarErrosComunicacao(Addr, "Porta serial não está aberta");
+ RegisrarErrosComunicacao(Addr, "Erro ao enviar dados via Ethernet");
}
+ return sucesso;
+ }
+ catch
+ {
+ RegisrarErrosComunicacao(Addr, "Erro ao enviar dados para o dispositivo via Ethernet");
+ return false;
}
}
- private static void port_DataReceived(object sender, SerialDataReceivedEventArgs e) // Evento de recebimento de dados da porta serial
+ private static async Task ProcessarDadosRecebidosAsync()
{
- ProcessarDadosRecebidos();
- }
-
- private static void ProcessarDadosRecebidos()
- {
- lock (_PortaLock)
+ if (_ethernetService != null && _ethernetService.IsConnected)
{
- if (_PortaMKS.IsOpen)
+ SerialBuffer_RX = new byte[11];
+ var resposta = await _ethernetService.ReceiveDataAsync(SerialBuffer_RX.Length);
+
+ if (resposta != null && resposta.Length > 0 && resposta.Length <= SerialBuffer_RX.Length)
{
- SerialBuffer_RX = new byte[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // SerialBuffer_RX[0] Cabeçalho do quadro [1] Endereço do escravo [2] Número da instrução
- Data_Number = _PortaMKS.BytesToRead; // Número de bytes recebidos
- if (_PortaMKS.BytesToRead > 0 && _PortaMKS.BytesToRead <= SerialBuffer_RX.Length)
- {
- for (int a = 0; a <= Data_Number - 1; a++)
- {
- SerialBuffer_RX[a] = (byte)_PortaMKS.ReadByte(); // Lê um byte do buffer de entrada SerialPort
- }
- Text_display();
- }
+ SerialBuffer_RX = resposta; // Armazena a resposta recebida
+ Data_Number = resposta.Length;
+ Text_display();
}
}
- }
-
- private static async Task SendRelevantData(byte Addr, int data) // Verifica o tipo de dados e envia
- {
- ushort SpeedText;
- ushort SpeedText2;
- byte SpeedText3;
- ushort SubdivisionText;
- uint PulseText;
- long RelAxisText;
- long AbsAxisText;
- byte UartAddrText;
- ushort KpText;
- ushort KiText;
- ushort KdText;
- ushort ACCText;
- ushort MaxTText;
- ushort Start_ACCText, Stop_ACCText;
- ushort CurrentText;
- byte HomeTrig = 0x00, HomeDir = 0x00, EndLimit = 0x00;
- byte Mode_0 = 0x00, Set_0 = 0x00, Speed_0 = 0x00, Dir_0 = 0x00;
-
- if (Addr <= 0xff && Addr >= 0x00)
- {
- if (DataSended < 6 || DataSended == 37 || DataSended == 39 || DataSended == 40 || DataSended == 43 || DataSended == 46)
- //(0 valor do codificador de posição 1 número acumulado de pulsos de entrada 2 erro de ângulo de posição 3 estado de habilitação da placa de acionamento em malha fechada 4 estado de retorno automático único ao ligar 5 bit de bloqueio 37 estado de desbloqueio 39 valor do codificador de contagem acumulada 40 velocidade atual do motor 43 informação de versão 46 estado do status do porto IO)
- {
- if (DataSended == 46)
- {
- //-------------------Determinação do tipo de motor--------------------
- tCHK = 0xFA + Addr + 0x40;
- Buffer = new byte[] { 0xFA, Addr, 0x40, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- await Task.Delay(50);
- //---------------------------------------------------
- }
- tCHK = 0xFA + Addr + data;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
-
- if (DataSended > 5 && DataSended < 8) //(6 habilitar placa de acionamento 7 desabilitar placa de acionamento)
- {
- if (DataSended == 6)
- {
- tCHK = 0xFA + Addr + data + EN_ON;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, EN_ON, (byte)tCHK };
- //GB4_button_使能驱动板.Enabled = false;
- //GB4_button_关闭驱动板.Enabled = true;
- }
- else
- {
- tCHK = 0xFA + Addr + data + EN_OFF;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, EN_OFF, (byte)tCHK };
- //GB4_button_关闭驱动板.Enabled = false;
- //GB4_button_使能驱动板.Enabled = true;
- }
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- /*if (DataSended == 8) //(8 modo de controle de velocidade do motor - iniciar)
- {
- try
- {
- SpeedText = Convert.ToUInt16(GB4_3_comboBox_速度档位.Text, 10);
- Speed_1 = BitConverter.GetBytes(SpeedText);
- if (SpeedText <= 3000 && SpeedText >= 1)
- {
- if (GB4_3_radioButton_反转.Checked)
- {
- //Speed = Convert.ToByte(SpeedText | RWD);
- Speed_1[1] |= RWD;
- //Console.WriteLine(Speed);
- }
- else if (GB4_3_radioButton_正转.Checked)
- {
- //Speed = Convert.ToByte(SpeedText | FWD);
- Speed_1[1] |= FWD;
- //Console.WriteLine(Speed);
- }
- tCHK = 0xFA + Addr + data + Speed_1[1] + Speed_1[0] + Start_ACC[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_1[1], Speed_1[0], Start_ACC[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 7);
- }
- else
- MessageBox.Show(Text1_Speedgear, Text1_window);
- }
- catch
- {
- MessageBox.Show(Text1_General, Text2_window);
- }
- }*/
-
- if (DataSended == 9) //(9 modo de controle de velocidade do motor - parar)
- {
- tCHK = 0xFA + Addr + data + 0x00 + 0x00 + Stop_ACC[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, 0x00, 0x00, Stop_ACC[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 7);
- }
-
- if (DataSended == 10) //(10 iniciar execução automática ao ligar)
- {
- tCHK = 0xFA + Addr + data + Save_Speed;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Save_Speed, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- Console.WriteLine(value: Save_Speed);
- }
-
- if (DataSended == 11) //(11 parar execução automática ao ligar)
- {
- tCHK = 0xFA + Addr + data + Clear_Speed;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Clear_Speed, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- if (DataSended == 12) //(12 configuração de subdivisão - confirmar)
- {
- try
- {
- SubdivisionText = Convert.ToUInt16(_MStep, 10);
- //Console.WriteLine(SubdivisionText); //saída no console
- if (SubdivisionText < 256 && SubdivisionText >= 1)
- {
- Subdivision = Convert.ToByte(SubdivisionText);
- tCHK = 0xFA + Addr + data + Subdivision;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)Subdivision, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (SubdivisionText == 256)
- {
- tCHK = 0xFA + Addr + data + 0x00;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, 0x00, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- MessageBox.Show("O valor de MStep deve estar entre 1 e 256");
- }
- catch
- {
- Console.WriteLine("Erro ao configurar MStep");
- }
- }
-
- if (DataSended == 13) //(13 modo de controle de posição do motor - iniciar)
- {
- try
- {
- SpeedText2 = Convert.ToUInt16(_Velocidade[Addr], 10);
- Speed_2 = BitConverter.GetBytes(SpeedText2);
- if (_ModoControle == ModosControle.Pulsos) // Se o controle for através de pulsos
- {
- try
- {
- PulseText = Convert.ToUInt32(_Angulo[Addr], 10);
- Pulse = BitConverter.GetBytes(PulseText);
- if (SpeedText2 <= 3000 && SpeedText2 >= 1)
- {
- if (PulseText <= 4294967295 && PulseText >= 1)
- {
- if (_Sentido[Addr] == Sentido.Antihorario)
- {
- //Speed2 = Convert.ToByte(SpeedText2 | RWD);
- Speed_2[1] |= RWD;
- //Pulse = Convert.ToByte(PulseText);
- }
- else if (_Sentido[Addr] == Sentido.Horario)
- {
- //Speed2 = Convert.ToByte(SpeedText2 | FWD);
- Speed_2[1] |= FWD;
- //Pulse = Convert.ToByte(PulseText);
- }
- else
- {
- MessageBox.Show("Sentido de giro não selecionado");
- }
- tCHK = 0xFA + Addr + data + Speed_2[1] + Speed_2[0] + Start_ACC[0] + Pulse[3] + Pulse[2] + Pulse[1] + Pulse[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_2[1], Speed_2[0], Start_ACC[0], Pulse[3], Pulse[2], Pulse[1], Pulse[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 11);
- }
- else
- MessageBox.Show("O número de pulsos deve estar entre 1 e 4294967295");
- }
- else
- MessageBox.Show("A velocidade deve estar entre 1 e 3000");
- }
- catch
- {
- Console.WriteLine("Erro ao definir controle Pulses");
- }
- }
- else if (_ModoControle == ModosControle.AnguloRelativo)
- {
- DataSended = 44;
- data = 0xF4;
- try
- {
- Text_BUF = _Angulo[Addr];
- if (Text_BUF.Length > 1)
- {
- if (Text_BUF[0] == '0' && (Text_BUF[1] == 'x' || Text_BUF[1] == 'X'))
- {
- RelAxisText = Convert.ToInt32(_Angulo[Addr], 16);
- RelAxis = BitConverter.GetBytes(RelAxisText);
- }
- else
- {
- RelAxisText = Convert.ToInt32(_Angulo[Addr], 10);
- RelAxis = BitConverter.GetBytes(RelAxisText * 16384 / 360);
- }
- }
- else
- {
- RelAxisText = Convert.ToInt32(_Angulo[Addr], 10);
- RelAxis = BitConverter.GetBytes(RelAxisText * 16384 / 360);
- }
- if (SpeedText2 <= 3000 && SpeedText2 >= 1)
- {
- if (RelAxisText <= 2147483647 && RelAxisText >= -2147483647)
- {
- tCHK = 0xFA + Addr + data + Speed_2[1] + Speed_2[0] + Start_ACC[0] + RelAxis[3] + RelAxis[2] + RelAxis[1] + RelAxis[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_2[1], Speed_2[0], Start_ACC[0], RelAxis[3], RelAxis[2], RelAxis[1], RelAxis[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 11);
- }
- }
- else
- MessageBox.Show("Valor para controle inválido");
- }
- catch
- {
- Console.WriteLine("Erro ao definir controle RelAxis");
- }
- }
- else if (_ModoControle == ModosControle.AnguloAbsoluto)
- {
- DataSended = 45;
- data = 0xF5;
- try
- {
- Text_BUF = _Angulo[Addr];
- if (Text_BUF.Length > 1)
- {
- if (Text_BUF[0] == '0' && (Text_BUF[1] == 'x' || Text_BUF[1] == 'X'))
- {
- AbsAxisText = Convert.ToInt32(_Angulo[Addr], 16);
- AbsAxis = BitConverter.GetBytes(AbsAxisText);
- }
- else
- {
- AbsAxisText = Convert.ToInt32(_Angulo[Addr], 10);
- AbsAxis = BitConverter.GetBytes(AbsAxisText * 16384 / 360);
- }
- }
- else
- {
- AbsAxisText = Convert.ToInt32(_Angulo[Addr], 10);
- AbsAxis = BitConverter.GetBytes(AbsAxisText * 16384 / 360);
- }
- if (SpeedText2 <= 3000 && SpeedText2 >= 1)
- {
- if (AbsAxisText <= 2147483647 && AbsAxisText >= -2147483647)
- {
- tCHK = 0xFA + Addr + data + Speed_2[1] + Speed_2[0] + Start_ACC[0] + AbsAxis[3] + AbsAxis[2] + AbsAxis[1] + AbsAxis[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_2[1], Speed_2[0], Start_ACC[0], AbsAxis[3], AbsAxis[2], AbsAxis[1], AbsAxis[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 11);
- }
- }
- else
- MessageBox.Show("Valor para controle inválido");
- }
- catch
- {
- Console.WriteLine("Erro ao definir controle AbsAxis");
- }
- }
- }
- catch
- {
- Console.WriteLine("Erro ao controlar motor de passo");
- }
- }
-
- if (DataSended == 14) //(14 calibrar codificador)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- /*
- if (DataSended == 15) //(15 tipo de motor - confirmar xx)
- {
- Text_BUF = comboBox6.Text;
- if (Text_BUF == Mot_18)
- {
- tCHK = Addr + data + byte_data[1];
- Buffer = new byte[] { Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
- else if (Text_BUF == Mot_09)
- {
- tCHK = Addr + data + byte_data[0];
- Buffer = new byte[] { Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
- }
- */
-
- if (DataSended == 16) //(16 modo de operação - confirmar)
- {
- if (_ModoOperacao == ModosOperacao.CR_OPEN)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (_ModoOperacao == ModosOperacao.CR_CLOSE)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (_ModoOperacao == ModosOperacao.CR_vFOC)
- {
- tCHK = 0xFA + Addr + data + byte_data[2];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (_ModoOperacao == ModosOperacao.SR_OPEN)
- {
- tCHK = 0xFA + Addr + data + byte_data[3];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[3], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (_ModoOperacao == ModosOperacao.SR_CLOSE)
- {
- tCHK = 0xFA + Addr + data + byte_data[4];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[4], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (_ModoOperacao == ModosOperacao.SR_vFOC)
- {
- tCHK = 0xFA + Addr + data + byte_data[5];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[5], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 17) //(17 valor de corrente (mA) - confirmar)
- {
- //-------------------Determinação do tipo de motor--------------------
- tCHK = 0xFA + Addr + 0x40;
- Buffer = new byte[] { 0xFA, Addr, 0x40, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- await Task.Delay(50);
- //---------------------------------------------------
- try
- {
- CurrentText = Convert.ToUInt16(_CorrenteMaxima, 10);
- Current = BitConverter.GetBytes(CurrentText);
- if (CurrentText <= Max_Current && CurrentText >= 0)
- {
- tCHK = 0xFA + Addr + data + Current[1] + Current[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Current[1], Current[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 6);
- }
- else
- MessageBox.Show("Corrente máxima deve estar entre 0 e " + Max_Current);
- }
- catch
- {
- Console.WriteLine("Erro ao salvar valor da corrente máxima");
- }
- }
-
- /*if (DataSended == 18) //(18 configuração de habilitação - confirmar)
- {
- Text_BUF = GB3_comboBox_使能设置.Text;
- if (Text_BUF == EN_H)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (Text_BUF == EN_L)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (Text_BUF == EN_Hold)
- {
- tCHK = 0xFA + Addr + data + byte_data[2];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 19) //(19 direção do motor - confirmar)
- {
- Text_BUF = GB3_comboBox_电机方向.Text;
- if (Text_BUF == Dir_CW)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (Text_BUF == Dir_CCW)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 20) //(20 desligamento automático da tela - confirmar)
- {
- Text_BUF = GB3_comboBox_自动熄屏.Text;
- if (Text_BUF == Disable)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (Text_BUF == Enable)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }*/
-
- if (DataSended == 21) //(21 proteção contra travamento - confirmar)
- {
- if (_Protecao == Estado.Desligado)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (_Protecao == Estado.Ligado)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 22) //(22 interpolação de subdivisão - confirmar)
- {
- if (_InterpolacaoSubdivisao == Estado.Desligado)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (_InterpolacaoSubdivisao == Estado.Ligado)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 23) //(23 taxa de baud da porta serial - confirmar)
- {
- Text_BUF = _baudSlave;
- if (Text_BUF == UartBaud[0]) //9600
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == UartBaud[1]) //19200
- {
- tCHK = 0xFA + Addr + data + byte_data[2];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == UartBaud[2]) //25000
- {
- tCHK = 0xFA + Addr + data + byte_data[3];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[3], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == UartBaud[3]) //38400
- {
- tCHK = 0xFA + Addr + data + byte_data[4];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[4], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == UartBaud[4]) //57600
- {
- tCHK = 0xFA + Addr + data + byte_data[5];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[5], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == UartBaud[5]) //115200
- {
- tCHK = 0xFA + Addr + data + byte_data[6];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[6], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == UartBaud[6]) //256000
- {
- tCHK = 0xFA + Addr + data + byte_data[7];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[7], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 24) //(24 endereço de comunicação do motor - confirmar)
- {
- try
- {
- UartAddrText = Convert.ToByte(_addressSlave, 16);
- if (UartAddrText <= 0xff && UartAddrText >= 0x01)
- {
- tCHK = 0xFA + Addr + data + UartAddrText;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, UartAddrText, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- MessageBox.Show("Endereço deve estar entre 0x01 e 0xff");
- }
- catch
- {
- Console.WriteLine("Erro ao definir endereço");
- }
- }
-
-
- /*
- if (DataSended == 25) //(25 Confirmar posição Kp)
- {
- KpText = Convert.ToUInt16(comboBox16.Text, 10);
- Kp = BitConverter.GetBytes(KpText);
- if (KpText < 65535 && KpText >= 0)
- {
- tCHK = Addr + data + Kp[1] + Kp[0];
- Buffer = new byte[] { Addr, (byte)data, Kp[1], Kp[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- {
- MessageBox.Show(Text2_Geral, Text2_janela);
- }
- }
-
- if (DataSended == 26) //(26 Confirmar posição Ki)
- {
- KiText = Convert.ToUInt16(comboBox17.Text, 10);
- Ki = BitConverter.GetBytes(KiText);
- if (KiText < 65535 && KiText >= 0)
- {
- tCHK = Addr + data + Ki[1] + Ki[0];
- Buffer = new byte[] { Addr, (byte)data, Ki[1], Ki[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- {
- MessageBox.Show(Text2_Geral, Text2_janela);
- }
- }
-
- if (DataSended == 27) //(27 Confirmar posição Kd)
- {
- KdText = Convert.ToUInt16(comboBox18.Text, 10);
- Kd = BitConverter.GetBytes(KdText);
- if (KdText < 65535 && KdText >= 0)
- {
- tCHK = Addr + data + Kd[1] + Kd[0];
- Buffer = new byte[] { Addr, (byte)data, Kd[1], Kd[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- {
- MessageBox.Show(Text2_Geral, Text2_janela);
- }
- }*/
-
- if (DataSended == 28) //(28 Confirmar aceleração inicial)
- {
- try
- {
- Start_ACCText = Convert.ToUInt16(_RampaParada, 10);
- if (Start_ACCText <= 255 && Start_ACCText >= 0)
- {
- Start_ACC = BitConverter.GetBytes(Start_ACCText);
- try
- {
- Temp1++;
- }
- catch
- {
- Temp1 = 0;
- }
- }
- else
- {
- MessageBox.Show("O valor da rampa deve estar entre 0 e 255");
- }
- }
- catch
- {
- MessageBox.Show("Erro ao definir rampa de início");
- }
- }
-
- if (DataSended == 29) //(29 Confirmar aceleração de parada)
- {
- try
- {
- Stop_ACCText = Convert.ToUInt16(_RampaParada, 10);
- if (Stop_ACCText <= 255 && Stop_ACCText >= 0)
- {
- Stop_ACC = BitConverter.GetBytes(Stop_ACCText);
- try
- {
- Temp1++;
- }
- catch
- {
- Temp1 = 0;
- }
- }
- else
- {
- MessageBox.Show("O valor da rampa deve estar entre 0 e 255");
- }
- }
- catch
- {
- MessageBox.Show("Erro ao definir rampa de parada");
- }
- }
-
- /*
- if (DataSended == 30) //(30 Ativar modo de retorno à origem)
- {
- if (radioButton7.Checked)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (radioButton8.Checked)
- {
- tCHK = 0xFA + Addr + data + byte_data[2];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- {
- MessageBox.Show(Text2_Geral, Text2_janela);
- }
- }
- */
-
- if (DataSended == 31) //(31 Parâmetros de limite)
- {
- //-------------------Verificar tipo de motor--------------------
- tCHK = 0xFA + Addr + 0x40;
- Buffer = new byte[] { 0xFA, Addr, 0x40, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- await Task.Delay(50);
- //---------------------------------------------------
- try
- {
- //Nível de gatilho
- Text_BUF = "Baixo";
- if (Text_BUF == "Baixo")
- {
- HomeTrig = 0x00;
- }
- else if (Text_BUF == "Alto")
- {
- HomeTrig = 0x01;
- }
-
- //Direção de retorno à origem
- if (_Sentido[Addr] == Sentido.Antihorario)
- {
- HomeDir = 0x00;
- }
- else if (_Sentido[Addr] == Sentido.Horario)
- {
- HomeDir = 0x01;
- }
-
- //Habilitar retorno à origem
- if (_RetornoOrigem == Estado.Desligado)
- {
- EndLimit = 0x00;
- }
- else if (_RetornoOrigem == Estado.Ligado)
- {
- EndLimit = 0x01;
- }
-
- //Velocidade de retorno à origem
- SpeedText = Convert.ToUInt16(_Velocidade[Addr], 10);
- Speed_1 = BitConverter.GetBytes(SpeedText);
-
- if (FV1[2] == 0x03)
- {
- if (SpeedText <= 3000 && SpeedText >= 1)
- {
- tCHK = 0xFA + Addr + data + HomeTrig + HomeDir + Speed_1[1] + Speed_1[0] + EndLimit;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, HomeTrig, HomeDir, Speed_1[1], Speed_1[0], EndLimit, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 9);
- }
- else
- MessageBox.Show("Limite de velocidade de retorno deve estar entre 1 e 3000");
- }
- else
- {
- if (SpeedText <= 3000 && SpeedText >= 1)
- {
- tCHK = 0xFA + Addr + data + HomeTrig + HomeDir + Speed_1[1] + Speed_1[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, HomeTrig, HomeDir, Speed_1[1], Speed_1[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 8);
- }
- else
- MessageBox.Show("Limite de velocidade de retorno deve estar entre 1 e 3000");
- }
- //----
- }
- catch
- {
- MessageBox.Show("Erro ao definir limite");
- }
- }
-
- if (DataSended == 32) //(32 Limite de retorno à origem)
- {
- tCHK = 0xFA + Addr + data;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
-
- if (DataSended == 33) //(33 Retorno à origem direto)
- {
- tCHK = 0xFA + Addr + data;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
-
- /*
- if (DataSended == 34) //(34 Confirmar direção de retorno à origem)
- {
- if (radioButton10.Checked)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (radioButton9.Checked)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- {
- MessageBox.Show(Text2_Geral, Text2_janela);
- }
- }
- */
-
- if (DataSended == 35) //(35 Voltar ao ponto zero)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- if (DataSended == 36) //(36 Restaurar configurações de fábrica)
- {
- tCHK = 0xFA + Addr + data;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
-
- if (DataSended == 38) //(38 Parar modo de controle de posição do motor)
- {
- if (_ModoControle == ModosControle.Pulsos)
- {
-
- }
- else if (_ModoControle == ModosControle.AnguloRelativo)
- {
- data = 0xF4;
- }
- else if (_ModoControle == ModosControle.AnguloAbsoluto)
- {
- data = 0xF5;
- }
- tCHK = 0xFA + Addr + data + 0x00 + 0x00 + Stop_ACC[0] + 0x00 + 0x00 + 0x00 + 0x00;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, 0x00, 0x00, Stop_ACC[0], 0x00, 0x00, 0x00, 0x00, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 11);
- }
-
- /*if (DataSended == 41) //(41 Resposta do escravo)
- {
- Text_BUF = GB3_comboBox_从机应答.Text;
- if (Text_BUF == Desativar)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
-
- else if (Text_BUF == Ativar)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 42) //(42 Grupo de escravos)
- {
- try
- {
- UartAddrText = Convert.ToByte(GB3_comboBox_从机分组.Text, 16);
- if (UartAddrText <= 0xff && UartAddrText >= 0x01)
- {
- tCHK = 0xFA + Addr + data + UartAddrText;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, UartAddrText, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else
- MessageBox.Show(Text1_UartAddrError, Text1_janela);
- }
- catch
- {
- MessageBox.Show(Text1_Geral, Text2_janela);
- }
- }
-
- if (DataSended == 47) //(47 MODBUS)
- {
- Text_BUF = GB3_comboBox_MODBUS.Text;
- if (Text_BUF == Desativar)
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == Ativar)
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }
-
- if (DataSended == 48) //(48 Bloqueio de teclas)
- {
- Text_BUF = GB3_comboBox_按键锁定.Text;
- if (Text_BUF == "Desbloquear")
- {
- tCHK = 0xFA + Addr + data + byte_data[0];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- else if (Text_BUF == "Bloquear")
- {
- tCHK = 0xFA + Addr + data + byte_data[1];
- Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 5);
- }
- }*/
-
- if (DataSended == 49) //(49 Retorno único)
- {
- try
- {
- //Modo de retorno à origem
- if (_ModoRetornoOrigem == ModosRetornoOrigem.Desativado)
- {
- Mode_0 = 0x00;
- }
- else if (_ModoRetornoOrigem == ModosRetornoOrigem.ModoDirecao)
- {
- Mode_0 = 0x01;
- }
- else if (_ModoRetornoOrigem == ModosRetornoOrigem.ModoAproximacao)
- {
- Mode_0 = 0x02;
- }
-
- //Configurar zero
- Text_BUF = _TipoLimiteZero;
- if (Text_BUF == "Limpar")
- {
- Set_0 = 0x00;
- }
- else if (Text_BUF == "Definir")
- {
- Set_0 = 0x01;
- }
-
- //Direção de retorno à origem
- if (_Sentido[Addr] == Sentido.Antihorario)
- {
- Dir_0 = 0x00;
- }
- else if (_Sentido[Addr] == Sentido.Horario)
- {
- Dir_0 = 0x01;
- }
-
- //Velocidade de retorno à origem
- Speed_0 = Convert.ToByte(_Velocidade[Addr], 10);
-
- tCHK = 0xFA + Addr + data + Mode_0 + Set_0 + Speed_0 + Dir_0;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, Mode_0, Set_0, Speed_0, Dir_0, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 8);
- //----
- }
- catch
- {
- MessageBox.Show("Erro ao gravar parametros de limite");
- }
- }
-
- if (DataSended == 91) //(91 Go Home)
- {
- tCHK = 0xFA + Addr + data;
- Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
- WriteByteToSerialPort(Buffer, 0, 4);
- }
-
- }
else
- MessageBox.Show("Endereço selecionado é inválido");
+ {
+ Console.WriteLine("Ethernet não está conectada ou o serviço não está definido.");
+ }
}
private static void Text_display()
{
- rxDisplay(); //计算rCHK
+ rxDisplay();
byte addr = SerialBuffer_RX[1];
-
if (!EnderecoValido(addr))
{
RegisrarErrosComunicacao(addr, "Dados recebidos de um endereço inválido: [" + string.Join(" ", SerialBuffer_RX) + "]");
@@ -2320,34 +1365,980 @@ namespace AgroBase.Services
Respondido = true;
}
+ private static void txDisplay(byte[] data)
+ {
+ Console.Write("TX: ");
+ for (int i = 0; i < data.Length; i++)
+ {
+ Console.Write("{0:X2} ", data[i]);
+ }
+ Console.WriteLine("Length: {0}", data.Length);
+ }
+
private static void rxDisplay()
{
rCHK = 0x00;
- //Console.Write("RX: ");
for (int a = 0; a < Data_Number - 1; a++)
{
rCHK += SerialBuffer_RX[a];
- //Console.Write("{0:X2} ", SerialBuffer_RX[a]);
}
- //Console.WriteLine("{0:X2} rCHK: {1:X2} Length: {2}", SerialBuffer_RX[Data_Number > 0 ? Data_Number - 1 : Data_Number], (byte)rCHK, Data_Number);
}
- private static void txDisplay()
- {
- return;
- Console.Write("TX: ");
- for (int a = 0; a < Buffer.Length; a++)
+ private static async Task SendRelevantData(byte Addr, int data) // Verifica o tipo de dados e envia
+ {
+ ushort SpeedText;
+ ushort SpeedText2;
+ byte SpeedText3;
+ ushort SubdivisionText;
+ uint PulseText;
+ long RelAxisText;
+ long AbsAxisText;
+ byte UartAddrText;
+ ushort KpText;
+ ushort KiText;
+ ushort KdText;
+ ushort ACCText;
+ ushort MaxTText;
+ ushort Start_ACCText, Stop_ACCText;
+ ushort CurrentText;
+ byte HomeTrig = 0x00, HomeDir = 0x00, EndLimit = 0x00;
+ byte Mode_0 = 0x00, Set_0 = 0x00, Speed_0 = 0x00, Dir_0 = 0x00;
+
+ if (Addr <= 0xff && Addr >= 0x00)
{
- Console.Write("{0:X2} ", Buffer[a]);
+ if (DataSended < 6 || DataSended == 37 || DataSended == 39 || DataSended == 40 || DataSended == 43 || DataSended == 46)
+ //(0 valor do codificador de posição 1 número acumulado de pulsos de entrada 2 erro de ângulo de posição 3 estado de habilitação da placa de acionamento em malha fechada 4 estado de retorno automático único ao ligar 5 bit de bloqueio 37 estado de desbloqueio 39 valor do codificador de contagem acumulada 40 velocidade atual do motor 43 informação de versão 46 estado do status do porto IO)
+ {
+ if (DataSended == 46)
+ {
+ //-------------------Determinação do tipo de motor--------------------
+ tCHK = 0xFA + Addr + 0x40;
+ Buffer = new byte[] { 0xFA, Addr, 0x40, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ await Task.Delay(50);
+ //---------------------------------------------------
+ }
+ tCHK = 0xFA + Addr + data;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+
+ if (DataSended > 5 && DataSended < 8) //(6 habilitar placa de acionamento 7 desabilitar placa de acionamento)
+ {
+ if (DataSended == 6)
+ {
+ tCHK = 0xFA + Addr + data + EN_ON;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, EN_ON, (byte)tCHK };
+ //GB4_button_使能驱动板.Enabled = false;
+ //GB4_button_关闭驱动板.Enabled = true;
+ }
+ else
+ {
+ tCHK = 0xFA + Addr + data + EN_OFF;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, EN_OFF, (byte)tCHK };
+ //GB4_button_关闭驱动板.Enabled = false;
+ //GB4_button_使能驱动板.Enabled = true;
+ }
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ /*if (DataSended == 8) //(8 modo de controle de velocidade do motor - iniciar)
+ {
+ try
+ {
+ SpeedText = Convert.ToUInt16(GB4_3_comboBox_速度档位.Text, 10);
+ Speed_1 = BitConverter.GetBytes(SpeedText);
+ if (SpeedText <= 3000 && SpeedText >= 1)
+ {
+ if (GB4_3_radioButton_反转.Checked)
+ {
+ //Speed = Convert.ToByte(SpeedText | RWD);
+ Speed_1[1] |= RWD;
+ //Console.WriteLine(Speed);
+ }
+ else if (GB4_3_radioButton_正转.Checked)
+ {
+ //Speed = Convert.ToByte(SpeedText | FWD);
+ Speed_1[1] |= FWD;
+ //Console.WriteLine(Speed);
+ }
+ tCHK = 0xFA + Addr + data + Speed_1[1] + Speed_1[0] + Start_ACC[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_1[1], Speed_1[0], Start_ACC[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 7);
+ }
+ else
+ MessageBox.Show(Text1_Speedgear, Text1_window);
+ }
+ catch
+ {
+ MessageBox.Show(Text1_General, Text2_window);
+ }
+ }*/
+
+ if (DataSended == 9) //(9 modo de controle de velocidade do motor - parar)
+ {
+ tCHK = 0xFA + Addr + data + 0x00 + 0x00 + Stop_ACC[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, 0x00, 0x00, Stop_ACC[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 7);
+ }
+
+ if (DataSended == 10) //(10 iniciar execução automática ao ligar)
+ {
+ tCHK = 0xFA + Addr + data + Save_Speed;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Save_Speed, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ Console.WriteLine(value: Save_Speed);
+ }
+
+ if (DataSended == 11) //(11 parar execução automática ao ligar)
+ {
+ tCHK = 0xFA + Addr + data + Clear_Speed;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Clear_Speed, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ if (DataSended == 12) //(12 configuração de subdivisão - confirmar)
+ {
+ try
+ {
+ SubdivisionText = Convert.ToUInt16(_MStep, 10);
+ //Console.WriteLine(SubdivisionText); //saída no console
+ if (SubdivisionText < 256 && SubdivisionText >= 1)
+ {
+ Subdivision = Convert.ToByte(SubdivisionText);
+ tCHK = 0xFA + Addr + data + Subdivision;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)Subdivision, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (SubdivisionText == 256)
+ {
+ tCHK = 0xFA + Addr + data + 0x00;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, 0x00, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ MessageBox.Show("O valor de MStep deve estar entre 1 e 256");
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao configurar MStep");
+ }
+ }
+
+ if (DataSended == 13) //(13 modo de controle de posição do motor - iniciar)
+ {
+ try
+ {
+ SpeedText2 = Convert.ToUInt16(_Velocidade[Addr], 10);
+ Speed_2 = BitConverter.GetBytes(SpeedText2);
+ if (_ModoControle == ModosControle.Pulsos) // Se o controle for através de pulsos
+ {
+ try
+ {
+ PulseText = Convert.ToUInt32(_Angulo[Addr], 10);
+ Pulse = BitConverter.GetBytes(PulseText);
+ if (SpeedText2 <= 3000 && SpeedText2 >= 1)
+ {
+ if (PulseText <= 4294967295 && PulseText >= 1)
+ {
+ if (_Sentido[Addr] == Sentido.Antihorario)
+ {
+ //Speed2 = Convert.ToByte(SpeedText2 | RWD);
+ Speed_2[1] |= RWD;
+ //Pulse = Convert.ToByte(PulseText);
+ }
+ else if (_Sentido[Addr] == Sentido.Horario)
+ {
+ //Speed2 = Convert.ToByte(SpeedText2 | FWD);
+ Speed_2[1] |= FWD;
+ //Pulse = Convert.ToByte(PulseText);
+ }
+ else
+ {
+ MessageBox.Show("Sentido de giro não selecionado");
+ }
+ tCHK = 0xFA + Addr + data + Speed_2[1] + Speed_2[0] + Start_ACC[0] + Pulse[3] + Pulse[2] + Pulse[1] + Pulse[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_2[1], Speed_2[0], Start_ACC[0], Pulse[3], Pulse[2], Pulse[1], Pulse[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 11);
+ }
+ else
+ MessageBox.Show("O número de pulsos deve estar entre 1 e 4294967295");
+ }
+ else
+ MessageBox.Show("A velocidade deve estar entre 1 e 3000");
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao definir controle Pulses");
+ }
+ }
+ else if (_ModoControle == ModosControle.AnguloRelativo)
+ {
+ DataSended = 44;
+ data = 0xF4;
+ try
+ {
+ Text_BUF = _Angulo[Addr];
+ if (Text_BUF.Length > 1)
+ {
+ if (Text_BUF[0] == '0' && (Text_BUF[1] == 'x' || Text_BUF[1] == 'X'))
+ {
+ RelAxisText = Convert.ToInt32(_Angulo[Addr], 16);
+ RelAxis = BitConverter.GetBytes(RelAxisText);
+ }
+ else
+ {
+ RelAxisText = Convert.ToInt32(_Angulo[Addr], 10);
+ RelAxis = BitConverter.GetBytes(RelAxisText * 16384 / 360);
+ }
+ }
+ else
+ {
+ RelAxisText = Convert.ToInt32(_Angulo[Addr], 10);
+ RelAxis = BitConverter.GetBytes(RelAxisText * 16384 / 360);
+ }
+ if (SpeedText2 <= 3000 && SpeedText2 >= 1)
+ {
+ if (RelAxisText <= 2147483647 && RelAxisText >= -2147483647)
+ {
+ tCHK = 0xFA + Addr + data + Speed_2[1] + Speed_2[0] + Start_ACC[0] + RelAxis[3] + RelAxis[2] + RelAxis[1] + RelAxis[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_2[1], Speed_2[0], Start_ACC[0], RelAxis[3], RelAxis[2], RelAxis[1], RelAxis[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 11);
+ }
+ }
+ else
+ MessageBox.Show("Valor para controle inválido");
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao definir controle RelAxis");
+ }
+ }
+ else if (_ModoControle == ModosControle.AnguloAbsoluto)
+ {
+ DataSended = 45;
+ data = 0xF5;
+ try
+ {
+ Text_BUF = _Angulo[Addr];
+ if (Text_BUF.Length > 1)
+ {
+ if (Text_BUF[0] == '0' && (Text_BUF[1] == 'x' || Text_BUF[1] == 'X'))
+ {
+ AbsAxisText = Convert.ToInt32(_Angulo[Addr], 16);
+ AbsAxis = BitConverter.GetBytes(AbsAxisText);
+ }
+ else
+ {
+ AbsAxisText = Convert.ToInt32(_Angulo[Addr], 10);
+ AbsAxis = BitConverter.GetBytes(AbsAxisText * 16384 / 360);
+ }
+ }
+ else
+ {
+ AbsAxisText = Convert.ToInt32(_Angulo[Addr], 10);
+ AbsAxis = BitConverter.GetBytes(AbsAxisText * 16384 / 360);
+ }
+ if (SpeedText2 <= 3000 && SpeedText2 >= 1)
+ {
+ if (AbsAxisText <= 2147483647 && AbsAxisText >= -2147483647)
+ {
+ tCHK = 0xFA + Addr + data + Speed_2[1] + Speed_2[0] + Start_ACC[0] + AbsAxis[3] + AbsAxis[2] + AbsAxis[1] + AbsAxis[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Speed_2[1], Speed_2[0], Start_ACC[0], AbsAxis[3], AbsAxis[2], AbsAxis[1], AbsAxis[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 11);
+ }
+ }
+ else
+ MessageBox.Show("Valor para controle inválido");
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao definir controle AbsAxis");
+ }
+ }
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao controlar motor de passo");
+ }
+ }
+
+ if (DataSended == 14) //(14 calibrar codificador)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ /*
+ if (DataSended == 15) //(15 tipo de motor - confirmar xx)
+ {
+ Text_BUF = comboBox6.Text;
+ if (Text_BUF == Mot_18)
+ {
+ tCHK = Addr + data + byte_data[1];
+ Buffer = new byte[] { Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+ else if (Text_BUF == Mot_09)
+ {
+ tCHK = Addr + data + byte_data[0];
+ Buffer = new byte[] { Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+ }
+ */
+
+ if (DataSended == 16) //(16 modo de operação - confirmar)
+ {
+ if (_ModoOperacao == ModosOperacao.CR_OPEN)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (_ModoOperacao == ModosOperacao.CR_CLOSE)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (_ModoOperacao == ModosOperacao.CR_vFOC)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[2];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (_ModoOperacao == ModosOperacao.SR_OPEN)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[3];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[3], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (_ModoOperacao == ModosOperacao.SR_CLOSE)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[4];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[4], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (_ModoOperacao == ModosOperacao.SR_vFOC)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[5];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[5], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 17) //(17 valor de corrente (mA) - confirmar)
+ {
+ //-------------------Determinação do tipo de motor--------------------
+ tCHK = 0xFA + Addr + 0x40;
+ Buffer = new byte[] { 0xFA, Addr, 0x40, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ await Task.Delay(50);
+ //---------------------------------------------------
+ try
+ {
+ CurrentText = Convert.ToUInt16(_CorrenteMaxima, 10);
+ Current = BitConverter.GetBytes(CurrentText);
+ if (CurrentText <= Max_Current && CurrentText >= 0)
+ {
+ tCHK = 0xFA + Addr + data + Current[1] + Current[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Current[1], Current[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 6);
+ }
+ else
+ MessageBox.Show("Corrente máxima deve estar entre 0 e " + Max_Current);
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao salvar valor da corrente máxima");
+ }
+ }
+
+ /*if (DataSended == 18) //(18 configuração de habilitação - confirmar)
+ {
+ Text_BUF = GB3_comboBox_使能设置.Text;
+ if (Text_BUF == EN_H)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (Text_BUF == EN_L)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (Text_BUF == EN_Hold)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[2];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 19) //(19 direção do motor - confirmar)
+ {
+ Text_BUF = GB3_comboBox_电机方向.Text;
+ if (Text_BUF == Dir_CW)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (Text_BUF == Dir_CCW)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 20) //(20 desligamento automático da tela - confirmar)
+ {
+ Text_BUF = GB3_comboBox_自动熄屏.Text;
+ if (Text_BUF == Disable)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (Text_BUF == Enable)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }*/
+
+ if (DataSended == 21) //(21 proteção contra travamento - confirmar)
+ {
+ if (_Protecao == Estado.Desligado)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (_Protecao == Estado.Ligado)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 22) //(22 interpolação de subdivisão - confirmar)
+ {
+ if (_InterpolacaoSubdivisao == Estado.Desligado)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (_InterpolacaoSubdivisao == Estado.Ligado)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 23) //(23 taxa de baud da porta serial - confirmar)
+ {
+ Text_BUF = _baudSlave;
+ if (Text_BUF == UartBaud[0]) //9600
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == UartBaud[1]) //19200
+ {
+ tCHK = 0xFA + Addr + data + byte_data[2];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == UartBaud[2]) //25000
+ {
+ tCHK = 0xFA + Addr + data + byte_data[3];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[3], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == UartBaud[3]) //38400
+ {
+ tCHK = 0xFA + Addr + data + byte_data[4];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[4], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == UartBaud[4]) //57600
+ {
+ tCHK = 0xFA + Addr + data + byte_data[5];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[5], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == UartBaud[5]) //115200
+ {
+ tCHK = 0xFA + Addr + data + byte_data[6];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[6], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == UartBaud[6]) //256000
+ {
+ tCHK = 0xFA + Addr + data + byte_data[7];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[7], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 24) //(24 endereço de comunicação do motor - confirmar)
+ {
+ try
+ {
+ UartAddrText = Convert.ToByte(_addressSlave, 16);
+ if (UartAddrText <= 0xff && UartAddrText >= 0x01)
+ {
+ tCHK = 0xFA + Addr + data + UartAddrText;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, UartAddrText, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ MessageBox.Show("Endereço deve estar entre 0x01 e 0xff");
+ }
+ catch
+ {
+ Console.WriteLine("Erro ao definir endereço");
+ }
+ }
+
+
+ /*
+ if (DataSended == 25) //(25 Confirmar posição Kp)
+ {
+ KpText = Convert.ToUInt16(comboBox16.Text, 10);
+ Kp = BitConverter.GetBytes(KpText);
+ if (KpText < 65535 && KpText >= 0)
+ {
+ tCHK = Addr + data + Kp[1] + Kp[0];
+ Buffer = new byte[] { Addr, (byte)data, Kp[1], Kp[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ {
+ MessageBox.Show(Text2_Geral, Text2_janela);
+ }
+ }
+
+ if (DataSended == 26) //(26 Confirmar posição Ki)
+ {
+ KiText = Convert.ToUInt16(comboBox17.Text, 10);
+ Ki = BitConverter.GetBytes(KiText);
+ if (KiText < 65535 && KiText >= 0)
+ {
+ tCHK = Addr + data + Ki[1] + Ki[0];
+ Buffer = new byte[] { Addr, (byte)data, Ki[1], Ki[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ {
+ MessageBox.Show(Text2_Geral, Text2_janela);
+ }
+ }
+
+ if (DataSended == 27) //(27 Confirmar posição Kd)
+ {
+ KdText = Convert.ToUInt16(comboBox18.Text, 10);
+ Kd = BitConverter.GetBytes(KdText);
+ if (KdText < 65535 && KdText >= 0)
+ {
+ tCHK = Addr + data + Kd[1] + Kd[0];
+ Buffer = new byte[] { Addr, (byte)data, Kd[1], Kd[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ {
+ MessageBox.Show(Text2_Geral, Text2_janela);
+ }
+ }*/
+
+ if (DataSended == 28) //(28 Confirmar aceleração inicial)
+ {
+ try
+ {
+ Start_ACCText = Convert.ToUInt16(_RampaParada, 10);
+ if (Start_ACCText <= 255 && Start_ACCText >= 0)
+ {
+ Start_ACC = BitConverter.GetBytes(Start_ACCText);
+ try
+ {
+ Temp1++;
+ }
+ catch
+ {
+ Temp1 = 0;
+ }
+ }
+ else
+ {
+ MessageBox.Show("O valor da rampa deve estar entre 0 e 255");
+ }
+ }
+ catch
+ {
+ MessageBox.Show("Erro ao definir rampa de início");
+ }
+ }
+
+ if (DataSended == 29) //(29 Confirmar aceleração de parada)
+ {
+ try
+ {
+ Stop_ACCText = Convert.ToUInt16(_RampaParada, 10);
+ if (Stop_ACCText <= 255 && Stop_ACCText >= 0)
+ {
+ Stop_ACC = BitConverter.GetBytes(Stop_ACCText);
+ try
+ {
+ Temp1++;
+ }
+ catch
+ {
+ Temp1 = 0;
+ }
+ }
+ else
+ {
+ MessageBox.Show("O valor da rampa deve estar entre 0 e 255");
+ }
+ }
+ catch
+ {
+ MessageBox.Show("Erro ao definir rampa de parada");
+ }
+ }
+
+ /*
+ if (DataSended == 30) //(30 Ativar modo de retorno à origem)
+ {
+ if (radioButton7.Checked)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (radioButton8.Checked)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[2];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[2], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ {
+ MessageBox.Show(Text2_Geral, Text2_janela);
+ }
+ }
+ */
+
+ if (DataSended == 31) //(31 Parâmetros de limite)
+ {
+ //-------------------Verificar tipo de motor--------------------
+ tCHK = 0xFA + Addr + 0x40;
+ Buffer = new byte[] { 0xFA, Addr, 0x40, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ await Task.Delay(50);
+ //---------------------------------------------------
+ try
+ {
+ //Nível de gatilho
+ Text_BUF = "Baixo";
+ if (Text_BUF == "Baixo")
+ {
+ HomeTrig = 0x00;
+ }
+ else if (Text_BUF == "Alto")
+ {
+ HomeTrig = 0x01;
+ }
+
+ //Direção de retorno à origem
+ if (_Sentido[Addr] == Sentido.Antihorario)
+ {
+ HomeDir = 0x00;
+ }
+ else if (_Sentido[Addr] == Sentido.Horario)
+ {
+ HomeDir = 0x01;
+ }
+
+ //Habilitar retorno à origem
+ if (_RetornoOrigem == Estado.Desligado)
+ {
+ EndLimit = 0x00;
+ }
+ else if (_RetornoOrigem == Estado.Ligado)
+ {
+ EndLimit = 0x01;
+ }
+
+ //Velocidade de retorno à origem
+ SpeedText = Convert.ToUInt16(_Velocidade[Addr], 10);
+ Speed_1 = BitConverter.GetBytes(SpeedText);
+
+ if (FV1[2] == 0x03)
+ {
+ if (SpeedText <= 3000 && SpeedText >= 1)
+ {
+ tCHK = 0xFA + Addr + data + HomeTrig + HomeDir + Speed_1[1] + Speed_1[0] + EndLimit;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, HomeTrig, HomeDir, Speed_1[1], Speed_1[0], EndLimit, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 9);
+ }
+ else
+ MessageBox.Show("Limite de velocidade de retorno deve estar entre 1 e 3000");
+ }
+ else
+ {
+ if (SpeedText <= 3000 && SpeedText >= 1)
+ {
+ tCHK = 0xFA + Addr + data + HomeTrig + HomeDir + Speed_1[1] + Speed_1[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, HomeTrig, HomeDir, Speed_1[1], Speed_1[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 8);
+ }
+ else
+ MessageBox.Show("Limite de velocidade de retorno deve estar entre 1 e 3000");
+ }
+ //----
+ }
+ catch
+ {
+ MessageBox.Show("Erro ao definir limite");
+ }
+ }
+
+ if (DataSended == 32) //(32 Limite de retorno à origem)
+ {
+ tCHK = 0xFA + Addr + data;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+
+ if (DataSended == 33) //(33 Retorno à origem direto)
+ {
+ tCHK = 0xFA + Addr + data;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+
+ /*
+ if (DataSended == 34) //(34 Confirmar direção de retorno à origem)
+ {
+ if (radioButton10.Checked)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (radioButton9.Checked)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ {
+ MessageBox.Show(Text2_Geral, Text2_janela);
+ }
+ }
+ */
+
+ if (DataSended == 35) //(35 Voltar ao ponto zero)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ if (DataSended == 36) //(36 Restaurar configurações de fábrica)
+ {
+ tCHK = 0xFA + Addr + data;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+
+ if (DataSended == 38) //(38 Parar modo de controle de posição do motor)
+ {
+ if (_ModoControle == ModosControle.Pulsos)
+ {
+
+ }
+ else if (_ModoControle == ModosControle.AnguloRelativo)
+ {
+ data = 0xF4;
+ }
+ else if (_ModoControle == ModosControle.AnguloAbsoluto)
+ {
+ data = 0xF5;
+ }
+ tCHK = 0xFA + Addr + data + 0x00 + 0x00 + Stop_ACC[0] + 0x00 + 0x00 + 0x00 + 0x00;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, 0x00, 0x00, Stop_ACC[0], 0x00, 0x00, 0x00, 0x00, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 11);
+ }
+
+ /*if (DataSended == 41) //(41 Resposta do escravo)
+ {
+ Text_BUF = GB3_comboBox_从机应答.Text;
+ if (Text_BUF == Desativar)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+
+ else if (Text_BUF == Ativar)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 42) //(42 Grupo de escravos)
+ {
+ try
+ {
+ UartAddrText = Convert.ToByte(GB3_comboBox_从机分组.Text, 16);
+ if (UartAddrText <= 0xff && UartAddrText >= 0x01)
+ {
+ tCHK = 0xFA + Addr + data + UartAddrText;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, UartAddrText, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else
+ MessageBox.Show(Text1_UartAddrError, Text1_janela);
+ }
+ catch
+ {
+ MessageBox.Show(Text1_Geral, Text2_janela);
+ }
+ }
+
+ if (DataSended == 47) //(47 MODBUS)
+ {
+ Text_BUF = GB3_comboBox_MODBUS.Text;
+ if (Text_BUF == Desativar)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == Ativar)
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }
+
+ if (DataSended == 48) //(48 Bloqueio de teclas)
+ {
+ Text_BUF = GB3_comboBox_按键锁定.Text;
+ if (Text_BUF == "Desbloquear")
+ {
+ tCHK = 0xFA + Addr + data + byte_data[0];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[0], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ else if (Text_BUF == "Bloquear")
+ {
+ tCHK = 0xFA + Addr + data + byte_data[1];
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, byte_data[1], (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 5);
+ }
+ }*/
+
+ if (DataSended == 49) //(49 Retorno único)
+ {
+ try
+ {
+ //Modo de retorno à origem
+ if (_ModoRetornoOrigem == ModosRetornoOrigem.Desativado)
+ {
+ Mode_0 = 0x00;
+ }
+ else if (_ModoRetornoOrigem == ModosRetornoOrigem.ModoDirecao)
+ {
+ Mode_0 = 0x01;
+ }
+ else if (_ModoRetornoOrigem == ModosRetornoOrigem.ModoAproximacao)
+ {
+ Mode_0 = 0x02;
+ }
+
+ //Configurar zero
+ Text_BUF = _TipoLimiteZero;
+ if (Text_BUF == "Limpar")
+ {
+ Set_0 = 0x00;
+ }
+ else if (Text_BUF == "Definir")
+ {
+ Set_0 = 0x01;
+ }
+
+ //Direção de retorno à origem
+ if (_Sentido[Addr] == Sentido.Antihorario)
+ {
+ Dir_0 = 0x00;
+ }
+ else if (_Sentido[Addr] == Sentido.Horario)
+ {
+ Dir_0 = 0x01;
+ }
+
+ //Velocidade de retorno à origem
+ Speed_0 = Convert.ToByte(_Velocidade[Addr], 10);
+
+ tCHK = 0xFA + Addr + data + Mode_0 + Set_0 + Speed_0 + Dir_0;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, Mode_0, Set_0, Speed_0, Dir_0, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 8);
+ //----
+ }
+ catch
+ {
+ MessageBox.Show("Erro ao gravar parametros de limite");
+ return false;
+ }
+ }
+
+ if (DataSended == 91) //(91 Go Home)
+ {
+ tCHK = 0xFA + Addr + data;
+ Buffer = new byte[] { 0xFA, Addr, (byte)data, (byte)tCHK };
+ await WriteByteToEthernetAsync(Buffer, 0, 4);
+ }
+
}
- Console.WriteLine("Length: {0}", Buffer.Length);
+ else
+ {
+ MessageBox.Show("Endereço selecionado é inválido");
+ return false;
+ }
+
+ return true;
}
#endregion
-
+
}
-
+
}
\ No newline at end of file
diff --git a/AgroBase/AgroBase/Services/SerialService.cs b/AgroBase/AgroBase/Services/SerialService.cs
index cb94f57c8..aa69b46fd 100644
--- a/AgroBase/AgroBase/Services/SerialService.cs
+++ b/AgroBase/AgroBase/Services/SerialService.cs
@@ -380,6 +380,11 @@ namespace AgroBase.Services
return;
}
+ if (Variaveis.OperacaoEmAndamento.DispMvd != null)
+ {
+ await ProcurarDispositivosEthernet();
+ }
+
var DispositivosRemovidos = dispositivosMapeados.Where(x => x.PortaCOM != "USB" && !Portas.Contains(x.PortaCOM)).ToList();
foreach (var Dispositivo in DispositivosRemovidos)
{
@@ -398,20 +403,6 @@ namespace AgroBase.Services
{
await ProcuraDispositivoModbus(ModbusService._PortaModbus, false);
}
- lock (MKS057DService._PortaLock)
- {
- if (DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks) && MKS057DService._PortaMKS != null &&!PortasNaoMapeadas.Contains(MKS057DService._PortaMKS.PortName))
- {
- //await ProcuraDispositivoMKS(MKS057DService._PortaMKS);
- Task.Run(async () => {
- await ProcuraDispositivoMKS(MKS057DService._PortaMKS);
- });
- }
- }
- if (DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Bld) && !PortasNaoMapeadas.Contains(BLD300RService._PortaBLD.PortName))
- {
- await ProcuraDispositivoBLD(BLD300RService._PortaBLD);
- }
}
catch (Exception ex)
{
@@ -558,18 +549,6 @@ namespace AgroBase.Services
return true;
}
- bool DispBld = await ProcuraDispositivoBLD(porta);
- if (DispBld)
- {
- return true;
- }
-
- bool DispMks = await ProcuraDispositivoMKS(porta);
- if (DispMks)
- {
- return true;
- }
-
bool DispLoRa = await ProcuraDispositivoLoRa(porta);
if (DispLoRa)
{
@@ -712,51 +691,6 @@ namespace AgroBase.Services
return ModbusService.Iniciado;
}
- private static async Task ProcuraDispositivoBLD(SerialPort porta)
- {
- if (BLD300RService.Iniciado && porta.PortName != BLD300RService._PortaBLD.PortName)
- {
- return false;
- }
-
- if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Any(x => !x.Iniciado))
- {
- AtualizarConsole("Procurando dispositivos BLD");
- bool Encontrado = await BLD300RService.VerificaPortaBLD(porta);
- if (Encontrado)
- {
- AtualizarConsole("Dispositivo BLD encontrado");
- return Encontrado;
- }
- }
-
- return BLD300RService.Iniciado;
- }
-
- private static async Task ProcuraDispositivoMKS(SerialPort porta)
- {
- lock (MKS057DService._PortaLock)
- {
- if (MKS057DService.Iniciado && porta.PortName != MKS057DService._PortaMKS.PortName)
- {
- return false;
- }
- }
-
- if (!MKS057DService.Referenciando && (!MKS057DService.Iniciado || Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => !x.DirMotor.MKS_Inicializado)))
- {
- AtualizarConsole("Procurando dispositivos MKS");
- bool Encontrado = await MKS057DService.VerificaPortaMKS(porta);
- if (Encontrado)
- {
- AtualizarConsole("Dispositivo MKS encontrado");
- return Encontrado;
- }
- }
-
- return MKS057DService.Iniciado;
- }
-
private static async Task ProcuraDispositivoLoRa(SerialPort porta)
{
if (LoRaService.Iniciado && porta.PortName != LoRaService._PortaLoRa.PortName)
@@ -796,6 +730,63 @@ namespace AgroBase.Services
}
}
+ private static async Task ProcurarDispositivosEthernet()
+ {
+ if (!Variaveis.IsAgroMonitor)
+ {
+ bool ethernetEncontrado = false;
+
+ bool DispBld = await ProcuraDispositivoBLD();
+ if (DispBld)
+ {
+ ethernetEncontrado = true;
+ }
+
+ bool DispMks = await ProcuraDispositivoMKS();
+ if (DispMks)
+ {
+ ethernetEncontrado = true;
+ }
+
+ return ethernetEncontrado;
+ }
+
+ return false;
+ }
+
+ private static async Task ProcuraDispositivoBLD()
+ {
+ if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Any(x => !x.Iniciado))
+ {
+ AtualizarConsole("Procurando dispositivos BLD");
+ bool Encontrado = await BLD300RService.VerificaPortaBLD();
+ if (Encontrado)
+ {
+ AtualizarConsole("Dispositivo BLD encontrado");
+ return Encontrado;
+ }
+ }
+
+ return BLD300RService.Iniciado;
+ }
+
+ private static async Task ProcuraDispositivoMKS()
+ {
+ if (!MKS057DService.Referenciando && (!MKS057DService.Iniciado || MKS057DService.DadosLeitura.Any(x => !x.Iniciado)))
+ {
+ AtualizarConsole("Procurando dispositivos MKS");
+ bool Encontrado = await MKS057DService.VerificaPortaMKS();
+ if (Encontrado)
+ {
+ AtualizarConsole("Dispositivo MKS encontrado");
+ return Encontrado;
+ }
+ }
+
+ return MKS057DService.Iniciado;
+ }
+
+
private static bool VerificaRespostaGPS(SerialPort Porta, string Recebido = null)
{
if (string.IsNullOrEmpty(Recebido))
diff --git a/AgroBase/AgroBase/bin/Debug/AgroBase.pdb b/AgroBase/AgroBase/bin/Debug/AgroBase.pdb
index b5ae55ad6..861779c80 100644
Binary files a/AgroBase/AgroBase/bin/Debug/AgroBase.pdb and b/AgroBase/AgroBase/bin/Debug/AgroBase.pdb differ
diff --git a/AgroBase/AgroBase/bin/Debug/Logs/Bld_err.txt b/AgroBase/AgroBase/bin/Debug/Logs/Bld_err.txt
index 33f87dba9..c19be8715 100644
--- a/AgroBase/AgroBase/bin/Debug/Logs/Bld_err.txt
+++ b/AgroBase/AgroBase/bin/Debug/Logs/Bld_err.txt
@@ -58948,3 +58948,16 @@
11/11/2024 17:20:41:202 - Porta COM21 - 3: Resposta inválida.
11/11/2024 17:20:42:261 - Porta COM21 - 2: Resposta inválida.
11/11/2024 17:20:43:283 - Porta COM21 - 4: Resposta inválida.
+12/11/2024 12:53:05:925 - Endereço 1 (192.168.99.105): Resposta inválida. 68-65-79-0D-0A
+12/11/2024 12:53:32:988 - Endereço 3 (192.168.99.105): Resposta inválida. 74-65-73-74-65-0D-0A
+12/11/2024 12:53:53:776 - Endereço 2 (192.168.99.105): Resposta inválida. 30-31-20-30-35-20-32
+12/11/2024 12:53:57:224 - Endereço 4 (192.168.99.105): Resposta inválida. 32-0D-0A
+12/11/2024 12:54:48:750 - Endereço 1 (192.168.99.105): Resposta inválida. 6C-0D-0A
+12/11/2024 12:54:54:003 - Endereço 3 (192.168.99.105): Resposta inválida. 74-0D-0A
+12/11/2024 15:23:52:040 - Endereço 1 (192.168.99.103): Resposta inválida. 31-32-33-0D-0A
+12/11/2024 15:23:58:485 - Endereço 3 (192.168.99.103): Resposta inválida. 31-31-0D-0A
+12/11/2024 15:26:18:659 - Endereço 1 (192.168.99.103): Resposta inválida. 31-0D-0A
+12/11/2024 15:33:41:464 - Endereço 1 (192.168.99.103): Resposta inválida. 31-0D-0A
+12/11/2024 15:33:44:482 - Endereço 3 (192.168.99.103): Resposta inválida. 32-0D-0A
+12/11/2024 15:33:45:317 - Endereço 2 (192.168.99.103): Resposta inválida. 33-0D-0A
+12/11/2024 15:33:46:453 - Endereço 4 (192.168.99.103): Resposta inválida. 34-0D-0A
diff --git a/AgroBase/AgroBase/bin/Debug/Parametros/parametersMvd-1_0.par b/AgroBase/AgroBase/bin/Debug/Parametros/parametersMvd-1_0.par
index 2fcc9b449..f447af72b 100644
--- a/AgroBase/AgroBase/bin/Debug/Parametros/parametersMvd-1_0.par
+++ b/AgroBase/AgroBase/bin/Debug/Parametros/parametersMvd-1_0.par
@@ -1 +1 @@
-{"Conectado":true,"Modulos":[{"Modulo_ID":"ET","Disponivel":false,"RequisitarDados":false,"Conectado":true,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x01","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":2,"NumeroPolos":10,"Rampa":0,"RPM_Max":500,"Reducao":5,"DiametroRoda":0.37,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x01","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":true,"Inicializado":false,"MKS_Inicializado":true,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}},{"Modulo_ID":"EF","Disponivel":false,"RequisitarDados":false,"Conectado":true,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x03","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":2,"NumeroPolos":10,"Rampa":0,"RPM_Max":500,"Reducao":5,"DiametroRoda":0.37,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x03","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":true,"Inicializado":false,"MKS_Inicializado":true,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}},{"Modulo_ID":"DT","Disponivel":false,"RequisitarDados":false,"Conectado":true,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x02","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":1,"NumeroPolos":10,"Rampa":0,"RPM_Max":500,"Reducao":5,"DiametroRoda":0.37,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x02","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":true,"Inicializado":false,"MKS_Inicializado":true,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}},{"Modulo_ID":"DF","Disponivel":false,"RequisitarDados":false,"Conectado":true,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x04","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":1,"NumeroPolos":10,"Rampa":0,"RPM_Max":500,"Reducao":5,"DiametroRoda":0.37,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x04","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":true,"Inicializado":false,"MKS_Inicializado":true,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}}],"DistanciaPercorridaOperacao":0.0,"TempoEmAtividade":0,"DistanciaPercorridaTotal":0.0,"DistanciaPercorridaParcial":0.0}
\ No newline at end of file
+{"Conectado":false,"DistanciaPercorridaOperacao":0.0,"TempoEmAtividade":0,"DistanciaPercorridaTotal":0.0,"DistanciaPercorridaParcial":0.0,"DiametroRoda":0.0,"ReducaoMotorBLDC":5.0,"RPM_Max_MotorBLDC":500.0,"IP_Bld":"192.168.99.103","IP_Mks":"192.168.99.102","Modulos":[{"Modulo_ID":"ET","Disponivel":false,"RequisitarDados":false,"Conectado":false,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x01","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":2,"NumeroPolos":10,"Rampa":0,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x01","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":false,"Inicializado":false,"MKS_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}},{"Modulo_ID":"EF","Disponivel":false,"RequisitarDados":false,"Conectado":false,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x03","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":2,"NumeroPolos":10,"Rampa":0,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x03","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":true,"Inicializado":false,"MKS_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}},{"Modulo_ID":"DT","Disponivel":false,"RequisitarDados":false,"Conectado":false,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x02","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":1,"NumeroPolos":10,"Rampa":0,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x02","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":false,"Inicializado":false,"MKS_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":2,"Direita":1,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}},{"Modulo_ID":"DF","Disponivel":false,"RequisitarDados":false,"Conectado":false,"UltimoProtocoloRecebido":"9999-12-30T23:59:59.9999999","MovMotor":{"ID":"Mov","Endereco":"0x04","Ligado":false,"Freio":false,"CodigoAlarme":0,"RPM_SP":0,"RPM_SP_Controle":0,"RPM_SP_Leitura":0,"Sentido_SP":1,"NumeroPolos":10,"Rampa":0,"OffsetLeitura":0.75,"RPM_Roda":0.0,"Sentido":0,"Temperatura":0.0,"TemperaturaDriver":0.0,"Tensao":0.0,"Corrente_Max":0.0,"Corrente":0.0,"RPM_Motor":0.0,"VelocidadeInstantanea":0.0,"Comandar":true,"Alarme":false,"Inicializado":false,"BLD_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RodasTraseiras":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoArco":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"RotacionarNoEixo":{"Frente":2,"Tras":1,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoLateral":{"Frente":1,"Tras":2,"Esquerda":0,"Direita":0,"Parado":0},"Diagnostico":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0}},"Funcoes":[12,14,9,5,10],"LogGrafico":[],"Alarmes":[{"Tipo":411,"Valor":"NaN","Minimo":false,"Maximo":false,"ParaMinimo":false,"ParaMaximo":false}]},"DirMotor":{"ID":"Dir","Endereco":"0x04","Sentido_SP":0,"Angulo_SP":0.0,"Angulo_Offset":0.0,"Velocidade_Max":600.0,"Sentido":0,"Angulo":0.0,"Comandar":true,"Inicializado":false,"MKS_Inicializado":false,"ConfigSentidos":{"RodasDianteiras":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"RodasTraseiras":{"Frente":0,"Tras":0,"Esquerda":0,"Direita":0,"Parado":0},"MovimentoDiagonal":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"MovimentoArco":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"RotacionarNoEixo":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":1,"Parado":0},"MovimentoLateral":{"Frente":0,"Tras":0,"Esquerda":1,"Direita":2,"Parado":0},"Diagnostico":{"Frente":2,"Tras":1,"Esquerda":1,"Direita":2,"Parado":0}},"Funcoes":[13,9,14,41]}}]}
\ No newline at end of file
diff --git a/AgroBase/AgroBase/obj/Debug/AgroBase.Forms.frmEthernet.resources b/AgroBase/AgroBase/obj/Debug/AgroBase.Forms.frmEthernet.resources
new file mode 100644
index 000000000..6c05a9776
Binary files /dev/null and b/AgroBase/AgroBase/obj/Debug/AgroBase.Forms.frmEthernet.resources differ
diff --git a/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.CoreCompileInputs.cache b/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.CoreCompileInputs.cache
index b1e03f66b..be41ee23d 100644
--- a/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.CoreCompileInputs.cache
+++ b/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-5875a1a9c926bc3d1db863aa7762494af9ca53385f091eb1d7da78431a6d9acf
+a7e8182e7c96a094b52f42faa88f285de461d90df42b3912f1224e93f5128942
diff --git a/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.FileListAbsolute.txt b/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.FileListAbsolute.txt
index 55d27e256..6981b9aa0 100644
--- a/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.FileListAbsolute.txt
+++ b/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.FileListAbsolute.txt
@@ -480,3 +480,4 @@ C:\ZendionInc\agrobot_base\AgroBase\AgroBase\bin\Debug\MathNet.Numerics.dll
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\bin\Debug\MathNet.Numerics.xml
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\bin\Debug\OpenHardwareMonitorLib.dll
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.frmA05Config.resources
+C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.frmEthernet.resources
diff --git a/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.GenerateResource.cache b/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.GenerateResource.cache
index bff096e02..7c7b1d67d 100644
Binary files a/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.GenerateResource.cache and b/AgroBase/AgroBase/obj/Debug/AgroBase.csproj.GenerateResource.cache differ
diff --git a/AgroBase/AgroBase/obj/Debug/AgroBase.pdb b/AgroBase/AgroBase/obj/Debug/AgroBase.pdb
index b5ae55ad6..861779c80 100644
Binary files a/AgroBase/AgroBase/obj/Debug/AgroBase.pdb and b/AgroBase/AgroBase/obj/Debug/AgroBase.pdb differ
diff --git a/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferences.cache
index c2fa08af6..5fcda0498 100644
Binary files a/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ
diff --git a/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
index de0c84e8b..23e00c361 100644
Binary files a/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/AgroBase/AgroBase/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ