I wish to know if there is a way to use a single property Serial0
to hold a HardwareSerial
or a SoftwareSerial
or other class instances supporting basic methods such as available()
, read()
and write()
, in order to make a CustomSerial
Class (polymorphism?).
class CustomSerial{
<GenericSerial??> Serial0;
char c;
void read(void){
c=Serial0.read();
}
};
The calls should be:
CustomSerial SerialCus;
int n=SerialCus.available();
char c=SerialCus.read();
SerialCus.write(c);
What should I use as GenericSerial
class, or what should be the proper use? I tried the Stream
class (as the answer pointed), but for some reason the functionality is not preserved (it writes unknown characters). Should indeed Stream
be the generic class I need for this?