Open
Description
Currently (1.0.0), the library automatically creates a RS485 object running on the SERIAL_PORT_HARDWARE
serial port (https://github.com/arduino-libraries/ArduinoRS485/blob/master/src/RS485.cpp#L181).
Although it might be idiomatic for Arduino libraries to automatically create an object to work with, for this library it causes trouble on some platforms and use cases:
- If you want to use a different Serial port than
Serial
, you still have to live with the automatically created RS485 object onSerial
, which is a waste of memory. - On some platforms (e.g. some STM32),
Serial
is of typeUSBSerial
. As the RS485 constructor only acceptsHardwareSerial
, and you cannot set another Serial port, this causes that the library cannot be compiled for these platforms. Workaround is to remove L181 of RS485.cpp.
So actually, I propose two changes:
- Use
Stream
as interface type for the RS485 constructor, so it can be created withHardwareSerial
as well as withUSBSerial
interfaces. - Do not create a RS485 object on
SERIAL_PORT_HARDWARE
, but rather require the user to actively chose the desired port as a parameter in thebegin
method (I guess it is ok to haveSERIAL_PORT_HARDWARE
as the default value for the port parameter.) Drawback: This change is not backwards-compatible. Current users of the library will have to add a line to create the RS485 object manually.