ajustes no controle direcional

This commit is contained in:
Diego Freitas 2025-03-26 10:04:52 -03:00
parent e4383254c1
commit 9338e6d39b
10 changed files with 55 additions and 35 deletions

Binary file not shown.

View File

@ -336,7 +336,7 @@ namespace AgroBase.Models.Modules
MKS057DService.AdicionarComandoNaFila(MKS057DService.MontarComandoRequisicaoIO(modAddr)); MKS057DService.AdicionarComandoNaFila(MKS057DService.MontarComandoRequisicaoIO(modAddr));
// Verifica se o angulo de set point do motor em questao e diferente do angulo atual, e se for, reenvia o comando para garantir que o motor esteja coerente com o set point // Verifica se o angulo de set point do motor em questao e diferente do angulo atual, e se for, reenvia o comando para garantir que o motor esteja coerente com o set point
if (!MKS057DService.Referenciando && (Modulo.DirMotor.UltimoComandoEnviado.AddMilliseconds(500) < DateTime.Now) && !Modulo.DirMotor.AtingiuAnguloSP) if (!MKS057DService.Referenciando && (Modulo.DirMotor.UltimoComandoEnviado.AddMilliseconds(MKS057DService.TaxaAmostragem) < DateTime.Now) && !Modulo.DirMotor.AtingiuAnguloSP)
{ {
var Controle = Variaveis.OperacaoEmAndamento.Controle.TiposControle?.FirstOrDefault(x => x.Tipo == T_Code.Dir); var Controle = Variaveis.OperacaoEmAndamento.Controle.TiposControle?.FirstOrDefault(x => x.Tipo == T_Code.Dir);
if (Controle != null) if (Controle != null)
@ -347,7 +347,7 @@ namespace AgroBase.Models.Modules
} }
} }
MKS057DService.TaxaAmostragem = MKS057DService.Referenciando ? 200 : 1000; MKS057DService.TaxaAmostragem = MKS057DService.Referenciando ? 200 : 500;
tmrRegistradorDIR.SetInterval(MKS057DService.TaxaAmostragem); tmrRegistradorDIR.SetInterval(MKS057DService.TaxaAmostragem);
} }

View File

@ -317,7 +317,7 @@ namespace AgroBase.Services
Endereco = Endereco, Endereco = Endereco,
AguardaResposta = true, AguardaResposta = true,
TamanhoResposta = 8, TamanhoResposta = 8,
TimeoutResposta = 200, TimeoutResposta = 300,
}; };
} }
@ -332,7 +332,7 @@ namespace AgroBase.Services
Endereco = Endereco, Endereco = Endereco,
AguardaResposta = true, AguardaResposta = true,
TamanhoResposta = 5, TamanhoResposta = 5,
TimeoutResposta = 200, TimeoutResposta = 300,
}; };
} }
@ -407,7 +407,7 @@ namespace AgroBase.Services
ModoControle = Controle, ModoControle = Controle,
AguardaResposta = true, AguardaResposta = true,
TamanhoResposta = 5, TamanhoResposta = 5,
TimeoutResposta = 200, TimeoutResposta = 300,
}; };
} }
@ -486,6 +486,7 @@ namespace AgroBase.Services
if (!resend) if (!resend)
{ {
await Task.Delay(50);
await EnviarComandoControle(Comando, true); await EnviarComandoControle(Comando, true);
} }
} }
@ -505,6 +506,7 @@ namespace AgroBase.Services
} }
finally finally
{ {
await Task.Delay(20);
FilaEmEspera = false; FilaEmEspera = false;
} }
} }
@ -596,7 +598,7 @@ namespace AgroBase.Services
private static bool DecifrarRespostaDriver(byte[] resposta) private static bool DecifrarRespostaDriver(byte[] resposta)
{ {
if (resposta == null || resposta.Length == 0) if (resposta == null || resposta.Length <= 3)
{ {
return false; return false;
} }
@ -641,7 +643,8 @@ namespace AgroBase.Services
leitura.NumeroPulsos_Hex += "0x"; leitura.NumeroPulsos_Hex += "0x";
for (int a = 3; a < 7; a++) for (int a = 3; a < 7; a++)
{ {
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper(); byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
leitura.NumeroPulsos_Hex += str.Length == 1 ? "0" + str : str; leitura.NumeroPulsos_Hex += str.Length == 1 ? "0" + str : str;
} }
} }
@ -652,7 +655,8 @@ namespace AgroBase.Services
word32 = "0"; word32 = "0";
for (int a = 3; a < 7; a++) for (int a = 3; a < 7; a++)
{ {
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper(); byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
word32 += str.Length == 1 ? "0" + str : str; word32 += str.Length == 1 ? "0" + str : str;
} }
data32 = Convert.ToInt32(word32, 16); data32 = Convert.ToInt32(word32, 16);
@ -695,7 +699,8 @@ namespace AgroBase.Services
leitura.RPM_Hex += "0x"; leitura.RPM_Hex += "0x";
for (int a = 3; a < 5; a++) for (int a = 3; a < 5; a++)
{ {
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper(); byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
leitura.RPM_Hex += str.Length == 1 ? "0" + str : str; leitura.RPM_Hex += str.Length == 1 ? "0" + str : str;
} }
} }
@ -705,7 +710,8 @@ namespace AgroBase.Services
word16 = "0"; word16 = "0";
for (int a = 3; a < 5; a++) for (int a = 3; a < 5; a++)
{ {
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper(); byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
word16 += str.Length == 1 ? "0" + str : str; word16 += str.Length == 1 ? "0" + str : str;
} }
data16 = Convert.ToInt16(word16, 16); data16 = Convert.ToInt16(word16, 16);

View File

@ -28,6 +28,10 @@ namespace AgroBase.Services
public static double CorrenteMax { get; set; } = 20.0; public static double CorrenteMax { get; set; } = 20.0;
public static bool ModoLeitura = false; public static bool ModoLeitura = false;
private static double FatorLeituraTensao = 0.01;
private static double FatorLeituraCorrente = 0.025;
private static double FatorLeituraPotencia = 0.00001;
public static Dictionary<string, byte> CodigosFuncoes = new Dictionary<string, byte>() public static Dictionary<string, byte> CodigosFuncoes = new Dictionary<string, byte>()
{ {
@ -118,11 +122,11 @@ namespace AgroBase.Services
DataHora = DateTime.Now, DataHora = DateTime.Now,
}; };
var tensao_raw = "0x" + resposta[3].ToString("X") + resposta[4].ToString("X"); var tensao_raw = "0x" + resposta[3].ToString("X") + resposta[4].ToString("X");
modelo.Tensao = Convert.ToInt32(tensao_raw, 16) * 0.02; // 0.01; modelo.Tensao = Convert.ToInt32(tensao_raw, 16) * FatorLeituraTensao;
var corrente_raw = "0x" + resposta[5].ToString("X") + resposta[6].ToString("X"); var corrente_raw = "0x" + resposta[5].ToString("X") + resposta[6].ToString("X");
modelo.Corrente = Convert.ToInt32(corrente_raw, 16) * 0.002; // 0.0015; modelo.Corrente = Convert.ToInt32(corrente_raw, 16) * FatorLeituraCorrente;
var potencia_raw = "0x" + resposta[7].ToString("X") + resposta[8].ToString("X") + resposta[9].ToString("X") + resposta[10].ToString("X"); var potencia_raw = "0x" + resposta[7].ToString("X") + resposta[8].ToString("X") + resposta[9].ToString("X") + resposta[10].ToString("X");
modelo.Potencia = Convert.ToInt32(potencia_raw, 16) * 0.0001; // 0.1; modelo.Potencia = Convert.ToInt32(potencia_raw, 16) * FatorLeituraPotencia;
var energia_raw = "0x" + resposta[11].ToString("X") + resposta[12].ToString("X") + resposta[13].ToString("X") + resposta[14].ToString("X"); var energia_raw = "0x" + resposta[11].ToString("X") + resposta[12].ToString("X") + resposta[13].ToString("X") + resposta[14].ToString("X");
modelo.Energia = Convert.ToInt32(energia_raw, 16) * 1.0; modelo.Energia = Convert.ToInt32(energia_raw, 16) * 1.0;
var almMax_raw = "0x" + resposta[15].ToString("X") + resposta[16].ToString("X"); var almMax_raw = "0x" + resposta[15].ToString("X") + resposta[16].ToString("X");

View File

@ -793,7 +793,7 @@ namespace AgroBase.Services
private static async Task<bool> ProcuraDispositivoBLD() private static async Task<bool> ProcuraDispositivoBLD()
{ {
if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Any(x => !x.Iniciado)) if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Count(x => x.Iniciado) < (Variaveis.OperacaoEmAndamento.DispMvd?.Dados?.Modulos?.Count() ?? 4))
{ {
AtualizarConsole("Procurando dispositivos BLD"); AtualizarConsole("Procurando dispositivos BLD");
bool Encontrado = await BLD300RService.VerificaPortaBLD(); bool Encontrado = await BLD300RService.VerificaPortaBLD();
@ -809,7 +809,7 @@ namespace AgroBase.Services
private static async Task<bool> ProcuraDispositivoOID() private static async Task<bool> ProcuraDispositivoOID()
{ {
if (!OIDService.Iniciado || OIDService.DadosLeitura.Any(x => !x.Iniciado)) if (!OIDService.Iniciado || OIDService.DadosLeitura.Count(x => x.Iniciado) < (Variaveis.OperacaoEmAndamento.DispMvd?.Dados?.Modulos?.Count() ?? 4))
{ {
AtualizarConsole("Procurando dispositivos OID"); AtualizarConsole("Procurando dispositivos OID");
bool Encontrado = await OIDService.VerificaPortaOID(); bool Encontrado = await OIDService.VerificaPortaOID();
@ -825,7 +825,7 @@ namespace AgroBase.Services
private static async Task<bool> ProcuraDispositivoMKS() private static async Task<bool> ProcuraDispositivoMKS()
{ {
if (!MKS057DService.Referenciando && (!MKS057DService.Iniciado || MKS057DService.DadosLeitura.Any(x => !x.Iniciado))) if (!MKS057DService.Referenciando && (!MKS057DService.Iniciado || MKS057DService.DadosLeitura.Count(x => x.Iniciado) < (Variaveis.OperacaoEmAndamento.DispMvd?.Dados?.Modulos?.Count() ?? 4)))
{ {
AtualizarConsole("Procurando dispositivos MKS"); AtualizarConsole("Procurando dispositivos MKS");
bool Encontrado = await MKS057DService.VerificaPortaMKS(); bool Encontrado = await MKS057DService.VerificaPortaMKS();

File diff suppressed because one or more lines are too long

View File

@ -37,6 +37,7 @@ class PinoModel {
} }
} }
else if (barramento == EXPANSOR_GPIO) { else if (barramento == EXPANSOR_GPIO) {
if (mcpInicializado) {
if (tipo == _INPUT) { if (tipo == _INPUT) {
mcp.pinMode(num, INPUT); mcp.pinMode(num, INPUT);
} else if (tipo == _OUTPUT) { } else if (tipo == _OUTPUT) {
@ -46,6 +47,7 @@ class PinoModel {
} }
} }
} }
}
void Desconectar() { void Desconectar() {
if (Definido()) { if (Definido()) {
@ -56,12 +58,14 @@ class PinoModel {
pinMode(num, INPUT); pinMode(num, INPUT);
} }
else if (barramento == EXPANSOR_GPIO) { else if (barramento == EXPANSOR_GPIO) {
if (mcpInicializado) {
mcp.pinMode(num, INPUT); mcp.pinMode(num, INPUT);
} }
} }
} }
}
int get(int leituras = 0) { int get(int leituras = 1) {
if (Definido()) { if (Definido()) {
if (barramento == CONTROLADOR) { if (barramento == CONTROLADOR) {
if (leitura == DIGITAL) { if (leitura == DIGITAL) {
@ -77,9 +81,12 @@ class PinoModel {
} }
} }
else if (barramento == EXPANSOR_GPIO) { else if (barramento == EXPANSOR_GPIO) {
if (mcpInicializado) {
return mcp.digitalRead(num); return mcp.digitalRead(num);
} }
}
else if (barramento == EXPANSOR_ADS) { else if (barramento == EXPANSOR_ADS) {
if (adsInicializado) {
double l = 0; double l = 0;
for (int i = 0; i < leituras; i++) { for (int i = 0; i < leituras; i++) {
int leituraADC = (int)(ads.readADC_SingleEnded(num)); int leituraADC = (int)(ads.readADC_SingleEnded(num));
@ -90,6 +97,7 @@ class PinoModel {
return l / leituras; return l / leituras;
} }
} }
}
return -1; return -1;
} }
@ -99,17 +107,19 @@ class PinoModel {
digitalWrite(num, status ? HIGH : LOW); digitalWrite(num, status ? HIGH : LOW);
} }
else if (barramento == EXPANSOR_GPIO) { else if (barramento == EXPANSOR_GPIO) {
if (mcpInicializado) {
mcp.digitalWrite(num, status ? HIGH : LOW); mcp.digitalWrite(num, status ? HIGH : LOW);
} }
} }
} }
}
}; };
void iniciarMCP(T_Code Modulo, String Mod_ID, int sda, int scl, byte endereco, bool Mandatorio = false) { void iniciarMCP(T_Code Modulo, String Mod_ID, int sda, int scl, byte endereco, bool Mandatorio = false) {
PrintTela("Iniciando MCP23X17..."); PrintTela("Iniciando MCP23X17...");
if (!mcpInicializado) { if (!mcpInicializado) {
bool init = Wire.begin(sda, scl); bool init = Wire.begin(sda, scl);
String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init; String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init + " - ";
PrintTela(str, false); PrintTela(str, false);
if (!mcp.begin_I2C(endereco, &Wire)) { if (!mcp.begin_I2C(endereco, &Wire)) {
@ -136,7 +146,7 @@ void iniciarADS(T_Code Modulo, String Mod_ID, int sda, int scl, byte endereco, b
PrintTela("Iniciando ADS1115..."); PrintTela("Iniciando ADS1115...");
if (!adsInicializado) { if (!adsInicializado) {
bool init = Wire.begin(sda, scl); bool init = Wire.begin(sda, scl);
String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init; String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init + " - ";
PrintTela(str, false); PrintTela(str, false);
if (!ads.begin(endereco, &Wire)) { if (!ads.begin(endereco, &Wire)) {