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 on Serial, which is a waste of memory.
- On some platforms (e.g. some STM32),
Serial is of type USBSerial. As the RS485 constructor only accepts HardwareSerial, 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 with HardwareSerial as well as with USBSerial 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 the begin method (I guess it is ok to have SERIAL_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.
Currently (1.0.0), the library automatically creates a RS485 object running on the
SERIAL_PORT_HARDWAREserial 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:
Serial, you still have to live with the automatically created RS485 object onSerial, which is a waste of memory.Serialis 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:
Streamas interface type for the RS485 constructor, so it can be created withHardwareSerialas well as withUSBSerialinterfaces.SERIAL_PORT_HARDWARE, but rather require the user to actively chose the desired port as a parameter in thebeginmethod (I guess it is ok to haveSERIAL_PORT_HARDWAREas 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.