Modbus RTU in esp32 via software serial
Posted: Wed Jan 18, 2023 4:37 am
I am shifting my project platform from ESP8266 to ESP32. The Modbus RTU read and write via Software serial worked fine with esp8266 using modbus-esp8266 library and as per the documentations I guess this library must work with ESP32. But it causes compilation errors as shown below:
E:\AMAL\micredge\iiotnext-edge\Code\main\modbus_driver_2.ino: In function 'void BeginModbus2()':
modbus_driver_2:79:41: error: no matching function for call to 'ModbusRTU::begin(SoftwareSerial*, int, int)'
mb.begin(&modSerial, ENABLEPIN, HIGH);
^
In file included from E:\AMAL\micredge\iiotnext-edge\Code\main\main.ino:79:
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:55:8: note: candidate: 'bool ModbusRTU::begin(HardwareSerial*, int16_t, bool)'
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);
^~~~~
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:55:8: note: no known conversion for argument 1 from 'SoftwareSerial*' to 'HardwareSerial*'
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:56:8: note: candidate: 'bool ModbusRTU::begin(Stream*)'
bool begin(Stream* port);
^~~~~
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:56:8: note: candidate expects 1 argument, 3 provided
E:\AMAL\micredge\iiotnext-edge\Code\main\modbus_driver_2.ino: In function 'bool ParseAndSaveTags(uint16_t*, int*, tagmsgs_t*)':
modbus_driver_2:237:57: error: argument to 'sizeof' in 'char* strncpy(char*, const char*, size_t)' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
strncpy(messageTag.TagName, Taginfo.TagName, sizeof(Taginfo.TagName));
^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus.exe: some warnings being treated as errors
Any solution for this issue is much appreciated.
E:\AMAL\micredge\iiotnext-edge\Code\main\modbus_driver_2.ino: In function 'void BeginModbus2()':
modbus_driver_2:79:41: error: no matching function for call to 'ModbusRTU::begin(SoftwareSerial*, int, int)'
mb.begin(&modSerial, ENABLEPIN, HIGH);
^
In file included from E:\AMAL\micredge\iiotnext-edge\Code\main\main.ino:79:
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:55:8: note: candidate: 'bool ModbusRTU::begin(HardwareSerial*, int16_t, bool)'
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);
^~~~~
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:55:8: note: no known conversion for argument 1 from 'SoftwareSerial*' to 'HardwareSerial*'
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:56:8: note: candidate: 'bool ModbusRTU::begin(Stream*)'
bool begin(Stream* port);
^~~~~
C:\Users\DELL\Documents\Arduino\libraries\modbus-esp8266\src/ModbusRTU.h:56:8: note: candidate expects 1 argument, 3 provided
E:\AMAL\micredge\iiotnext-edge\Code\main\modbus_driver_2.ino: In function 'bool ParseAndSaveTags(uint16_t*, int*, tagmsgs_t*)':
modbus_driver_2:237:57: error: argument to 'sizeof' in 'char* strncpy(char*, const char*, size_t)' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
strncpy(messageTag.TagName, Taginfo.TagName, sizeof(Taginfo.TagName));
^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus.exe: some warnings being treated as errors
Any solution for this issue is much appreciated.