smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

Use SoftwareSerial with RS485 #43

Closed MathiasMoog closed 5 years ago

MathiasMoog commented 5 years ago

Problem:

The availabel constructor and begin method in the Modbus class alows only RS232 communication for SoftwareSerial since the u8txenpin is allways 0 in this use case.

Solution:

I add an additional begin method for Software Serial:

void begin(SoftwareSerial *sPort, long u32speed, uint8_t u8txenpin);

This allows the use of the txenpin even for SoftwareSerial and hence the use in RS485 communications.

Additionally I fixed some compile warnings. Now it compiles in the Arduino IDE 1.8.9 even with -Wall without any warning.