ModbusTCP Client - ArduinoModbus.h

Post Reply
Arickzon93
Posts: 1
Joined: Sun Jan 26, 2020 7:27 pm

ModbusTCP Client - ArduinoModbus.h

Post by Arickzon93 » Sun Jan 26, 2020 7:37 pm

Hello, I have a Controllino MEGA and need to a Modbus Read and Write Holding Register programm. The Controllino has to be the Client, the Robot i use is the Server with a fixed IP and fixed Modbus address to the PLC Registers.

PLC Register 1 = Modbus address 41002
PLC Register 2 = Modbus address 41004
etc.

I have a Ethernet connection to the Robot and use the Port 502.

Code: Select all

#include <SPI.h>
#include <Controllino.h>
#include <Ethernet.h>
#include <ArduinoModbus.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress serverIP (192, 168, 12, 20);

int port = 502;

EthernetClient client;

 void setup() {

Serial.begin(9600);

  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    while (true) {
      delay(1); // do nothing, no point running without Ethernet
    }
  } else {
    Serial.print("  DHCP assigned ClientIP: ");
    Serial.println(Ethernet.localIP());
    Serial.print("  ServerIP:               ");
    Serial.println(serverIP);
    Serial.print("  ServerPort:             ");
    Serial.println(port);
  }
if (client.connect(serverIP, port)) {

    client.setTimeout(2000);

    Serial.println(F("Client connected"));
}
}
Now i want to use the Arduino lib for Modbus, as i read in a other Post in this Forum that the Arduino lib is complete compatible with the Controllino. Can you help me to implement the Read and Write Holding Register function to the Sketch? I´m lost at the moment, because my knowledge about Arduino is not that good.

I want to use https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus ArduinoModbus.h lib, but everything i try runs into error. How can i use for example the holdingRegisterWrite(); function?

Please help me :roll:

User avatar
Lukas
Posts: 74
Joined: Tue Dec 18, 2018 3:44 pm

Re: ModbusTCP Client - ArduinoModbus.h

Post by Lukas » Thu Mar 05, 2020 10:31 am

Hello,

our Modbus example is only for Modbus RTU - which means Modbus over RS485 serial line.

But the ArduinoModbus library should work also over Ethernet. CONTROLLINO MEGA should be compatible to Arduino Mega + Ethernet Shield.

Do you have any progress so far?

Have you tried to connect to you robot from some Modbus client app running on a PC?

Post Reply