Go Down

Topic: SoftwareSerial and HardwareSerial common superclass (Read 1 time) previous topic - next topic

wa5znu

I'm writing a library and I'd like it work with either a SoftwareSerial object or HardwareSerial (the "Serial" object).  By clearing the constructor in my library to take a Stream, I can get most of the way there. 

However, I can't call stream.begin(4800) in my library because Stream doesn't have such a begin method, and the two serial classes don't have a common superclass or interface that defines a begin method.

Is there something I'm missing?  If not, it would help in expanding use of SoftwareSerial if there were a common class that could be used.

Leigh.


avenue33

Please check the proxySerial library: it can handle hardware, software and I2C serial ports.

See here and there for documentation, examples, tutorial and code!

liudr


However, I can't call stream.begin(4800) in my library because Stream doesn't have such a begin method, and the two serial classes don't have a common superclass or interface that defines a begin method.


Alternative to avenue33's suggestion, what I did with my phi_interfaces library is to REQUIRE a Stream object that has already begun. There is no standard method to begin or end a serial port or I2C interface under Stream. The user will do the begin of whatever port and pass your library the address to the Stream object that has begun :)

wa5znu

Thank you, all. I am already using the caller-callers-begin() method, so I guess I'll stick with that. I hadn't considered the difficulties of extending to I2C.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy