Activity › Forums › Questions & Troubleshooting › Software & Firmware › ModbusTCP Client – ArduinoModbus.h
-
ModbusTCP Client – ArduinoModbus.h
-
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
#includebyte 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
ArduinoModbus.h lib, but everything i try runs into error. How can i use for example the holdingRegisterWrite(); function?https://www.arduino.cc/en/ArduinoModbus/ArduinoModbushttps://www.arduino.cc/en/ArduinoModbus/ArduinoModbus” class=”bbcode_url”> Please help me
🙄 -
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?
Log in to reply.