Go Down

Topic: Modbus TCP/IP Arduino (Read 13437 times) previous topic - next topic

RoqueM

Jan 18, 2018, 02:58 pm Last Edit: Jan 18, 2018, 03:26 pm by RoqueM
Dear,

I am working on a project in which I seek to collect information from a similar input and then send the data via Modbus TCP / IP. For which I am using an Arduino MEGA together with an Ethernet Shield W5100, I want to configure them as a server.

I am using the library: Libreria modbus TCP/IP

I am also using the Radzio Software to simulate communication as Maestro from another PC.

My problem is the following, when making the tests I connect my Arduino to a Thomsom DCW775EU Router by network wire, then I simulate the Master controller. I open the window cmd to ping the IP of the arduino (successful test), when communicating Client-Server throws me "Modbus message timeout"

As I read the problem can be in Three Way Handshake

I leave the code on which I rely for the measurement and sending data (is one of the examples that come with the library)

Code: [Select]

#include <SPI.h>
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>

//Modbus Registers Offsets (0-9999)
const int SENSOR_IREG = 100;
//Used Pins
const int sensorPin = A0;

//ModbusIP object
ModbusIP mb;

long ts;

void setup() {
  
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
    
    byte ip[] = { 192, 168, 0, 32 };  
    
    mb.config(mac, ip);

    // Add SENSOR_IREG register - Use addIreg() for analog Inputs
    mb.addIreg(SENSOR_IREG);
    
    ts = millis();
}

void loop() {
   //Call once inside loop() - all magic here
   mb.task();
  
  
   if (millis() > ts + 2000) {  
       ts = millis();
      
       mb.Ireg(SENSOR_IREG, analogRead(sensorPin));
   }
}


pylon

Quote
I am working on a project in which I seek to collect information from a similar input and then send the data via Modbus TCP / IP. For which I am using an Arduino MEGA together with an Ethernet Shield W5100, I want to configure them as a server.
If you configure your Arduino as a ModBus TCP server ("slave" in ModBus RTU naming) you cannot send any data via ModBus, it can only be queried by the client ("master" in ModBus RTU naming).

What do you use to simulate the client (master)? Is it qmodbus?

Go Up