In my project I’m using both an AltSoftSerial port and the USB Serial debug port.
I want to set a variable to either a reference to an AltSoftSerial object or else to the normal Serial object. Both inherit from Stream.
At first I made the variable of type Stream& = Serial, but that failed when I used the begin() method, since that isn’t in the Stream definition.
Browsing the code, I see that Serial is actually an instance of the Serial_ class, so I tried the following:
#ifdef DEBUG #include <USBAPI.h> // Where class Serial_ is defined Serial_& MyPort = Serial; #else AltSoftSerial MyPort; // Calls constructor #endif
No matter what I do, the compiler throws an error that “Serial_ is not a type”.
I even tried a typedef, as well as creating MySerial class which would inherit from both AltSoftSerial and Serial_.
I think that it just doesn’t like the trailing underscore.
Any help? Both AltSoftSerial and Serial inherit from Stream, and both define the same methods.