Skip to content

Possibility to choose the Serial port to work with #9

Open
@dl1com

Description

@dl1com

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions