Uso del protocolo Modbus TCP/IP para enviar y recibir datos desde Labview hacia una ESP8266

Buscando en foros y videos logre armar un pequeño código para lo anteriormente mencionado, pero al momento de enviar datos de labview hacia arduino este ultimo no recibe ningún dato, estoy utilizando un servidor OPC y en este servidor si logro visualizar los datos a enviados desde labview.

Estos son los datos recibidos:

Adjunto el código realizado en arduino:

#include <ESP8266WiFi.h>
#include <ModbusTCPSlave.h>
#include <Ticker.h>
#include <Servo.h>

//MODULO L298N
#define IN_1  15          // L298N in1 motors Right           GPIO15(D8)
#define IN_2  13          // L298N in2 motors Right           GPIO13(D7)
#define IN_3  2           // L298N in3 motors Left            GPIO2(D4)
#define IN_4  0           // L298N in4 motors Left            GPIO0(D3)


long lastMsg = 0;

//CONFIGURAR WIFI
byte ip[] ={ 192, 168, 100, 102};
byte gateway[] ={192, 168, 100, 1};
byte subnet[] ={255, 255, 255, 0};

ModbusTCPSlave Mb;

void setup() {
  Serial.begin(115200);
  Mb.begin("NETLIFE-SANTIAGO", "1713499596", ip, gateway, subnet);
  //WiFi.begin("NETLIFE-SANTIAGO", "1713499596");
  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print("."); 
  }
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);

  
  Serial.println("WiFi conectado");
  Serial.print("IP: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  
  long now = millis();
  //El siguiente if se encarga de realizar las acciones dentro del mismo cada "lastMsg" milisegundos
  if (now - lastMsg >3000) {
    lastMsg = now;
    
  if(bitRead(Mb.MBHoldingRegister[2],0)==1){
     digitalWrite(IN_1, HIGH);
     digitalWrite(IN_2, LOW);
     delay(1000);
     digitalWrite(IN_1, LOW);
     digitalWrite(IN_2, HIGH);
     delay(1000);
     Serial.println(bitRead(Mb.MBHoldingRegister[2],0));
  }

  if(bitRead(Mb.MBHoldingRegister[3],0)==1){
     digitalWrite(IN_1, LOW);
     digitalWrite(IN_2, LOW);
     Serial.println(bitRead(Mb.MBHoldingRegister[3],0));
  }
 
  }

  Mb.Run();
  delay(10);
}

Moderador:
Por favor, lee las Normas del foro y edita tu título.
No puedes poner un comentario como si fuera un título.
Se mas preciso y no uses palabras inútiles.
Te dejo el punto 5 de las normas.

5. Piensa un título y descriptivo

Trata de resumir tu problema con un título inteligente, útil e informativo.
Un título útil salta a la vista de las personas que podrían conocer la respuesta. Los títulos inútiles son los que deberías evitar.
Ejemplos de títulos inútiles que deberías evitar:
• ERROR EN CODIGO, AYDUA URGENTE
• Problema al programar
• Tengo un error
• Error
• Tendré problemas?
• Novato en apuros
• POR FAVOR NECESITO AYUDA RAPIDO!!!!

Lo primero es probar si recibes las tramas en otro dispositivo (PC por ejemplo). Usando algun programa d emonitoreo MODBUS TCP/IP.
Verifica eso.
un error menor pero siempre usa unsigned long no solo long

long now = millis();

Si usas millis() no uses delay en tu código
Esto genera en MODBUS siempre problemas de timming.

  if(bitRead(Mb.MBHoldingRegister[2],0)==1){
     digitalWrite(IN_1, HIGH);
     digitalWrite(IN_2, LOW);
     delay(1000);
     digitalWrite(IN_1, LOW);
     digitalWrite(IN_2, HIGH);
     delay(1000);
     Serial.println(bitRead(Mb.MBHoldingRegister[2],0));
  }

Ya me dirás si se reciben las tramas.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.