Activity Forums Questions & Troubleshooting Software & Firmware ModbusTCP Client – ArduinoModbus.h

  • ModbusTCP Client – ArduinoModbus.h

     Lukas updated 4 years, 8 months ago 2 Members · 2 Posts
  • arickzon93

    Member
    January 26, 2020 at 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:

    #include
    #include
    #include
    #include

    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” class=”bbcode_url”>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 🙄

  • Lukas

    Member
    March 5, 2020 at 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?

Viewing 1 - 2 of 2 replies

Log in to reply.

Original Post
0 of 0 posts June 2018
Now