Arduino Forum

Development => Other Software Development => Topic started by: liuzengqiang on Jan 17, 2012, 02:43 am

Title: No begin in Stream, how to handle soft and hard serials as one general class?
Post by: liuzengqiang on Jan 17, 2012, 02:43 am
I am trying to write code that can take either software or hardware serial object (arduino 1.0) and use it for communication. I'm aware that both inherit from Stream but after checking out the Stream code, I didn't find begin. Read, available are both there. I suppose the print and write are inherited from Print.

So my options are:
* Split into one function that does soft serial with a begin and another function that does hard serial with a begin.
* Demand the port to be initialized with a begin before the code can accept the pointer to the port and have one function to handle both initialized (begun) soft and hard serial ports.
* Any more elegant ways? Thank you!!!