Hello,
I am currently facing a problem while using the library ArduinoModbus 1.0.6. What I want to do is to read and write coils using Ethernet and Modbus TCP with my Arduino Mega2560 as the master.
I read that you need to use ModbusTCPClient to setup your Arduino as the master.
https://www.arduino.cc/reference/en/libraries/arduinomodbus/
Problem is, in my code, I can set up as a slave using ModbusTCPServer without any problem, but the IDE doesn't seem to recognize the ModbusTCPClient class at all, wich is weird because it comes from the same library. I tried writing "modbusTCPClient", "ModbusTCPclient" and "modbusTCPclient", I tried with an instance but same result: the class in not recognized.
Here is my code:
#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
byte mac[]={0xA8, 0x61, 0x0A, 0xAE, 0x7A, 0x08}; // Adresse MAC de l'Arduino
IPAddress ipUno; // Adresse IP de l'Arduino
IPAddress ipAuto; // Adresse IP de l'automate
// Initialisation
void setup(){
Serial.begin(115200);
// Démarer la connection Ethernet
while(!Ethernet.begin(mac)){ // Demander une adresse en DHCP toutes les secondes si échec
delay(1000);
}
}
// Programme principale
void loop(){
Ethernet.maintain(); // Maintenir la connection en DHCP
ipAuto=lireIp(); // Obtenir l'IP de l'automate avec le dip switch
if(!ModbusTCPClient.connected()){ // Se connecter à l'automate
ModbusTCPClient.begin(ipAuto);
}
}
Here is my errors:
Arduino : 1.8.15 (Windows 10), Carte : "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
D:\2021-2022\Stage\Programme\Programme.ino: In function 'void loop()':
Programme:57:22: error: expected primary-expression before '.' token
if(!ModbusTCPClient.connected()){ // Se connecter à l'automate
^
Programme:58:20: error: expected unqualified-id before '.' token
ModbusTCPClient.begin(ipAuto);
^
exit status 1
expected primary-expression before '.' token
I put a screenshot so you can see the ModbusTCPClient not recognized (in black) and the ModBusTCPServer being recognized (orange).
Have someone an idea of where it is coming from, or how to solve this?
I thank you in advance and don't hesitate to ask for more details.