emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#define MODBUSRTU_REDE leads to compiler errors

fredlcore opened this issue · comments

It's not an actual error, but current default settings in Arduino IDE lead to this error when compiling with MODBUSRTU_REDE enabled:

/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/ModbusRTU.cpp: In member function 'bool ModbusRTUTemplate::rawSend(uint8_t, uint8_t*, uint8_t)':
/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/ModbusRTU.cpp:138:6: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
      if (_txPin >= 0)
      ^~
/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/ModbusRTU.cpp:140:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   if (_rxPin >= 0)
   ^~
/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/ModbusRTU.cpp:167:6: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
      if (_txPin >= 0)
      ^~
/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/ModbusRTU.cpp:169:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   if (_rxPin >= 0)
   ^~
cc1plus: some warnings being treated as errors
/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/Modbus.cpp: In member function 'void Modbus::slavePDU(uint8_t*)':
/Users/frederik/Documents/Arduino/libraries/modbus-esp8266/src/Modbus.cpp:318:25: warning: comparison is always false due to limited range of data type [-Wtype-limits]
             if (bufSize > MODBUS_MAX_FRAME) {  // Frame to return too large

Using library modbus-esp8266 at version 4.1.0 in folder: /Users/frederik/Documents/Arduino/libraries/modbus-esp8266 
exit status 1

Compilation error: exit status 1

It's really just a matter of indention. By moving the commands into the same line as the if-statement, the error disappears.

This is caused by that this part of code has a mix of spaces and TABs as indent, where the TAB size setting is different from what the code maintainer has uses.
Convert TAB to spaces and proper formatting the code will solve warnings.
(someone has instructed gcc to treat warnings as errors... its a certain way to get those pesky warnings get fixed before anyone can continue...)

I know, and I fixed it myself already. I just wanted to highlight this to be fixed in this repo as well so that others won't run into this problem on a standard Arduino IDE installation.