Passing a serial port to an object?

I'd like to write a class that communicates out a serial port.

First idea was to pass the serial port I wanted to use in the parameters of the constructor. But, what type is a serial port? Serial or Serial1 Are instances of what?

I know I'm getting tired and the answer is probably staring me in the face in the reference, But I ain't seeing it.


-jim lee

You most likely want to pass a Stream type (Serial inherits from this)...

The class name IS a data type.
Call it "Serial", or "serial", or "sPort" or "Ralph".

As stated, all the various "serial" classes (hardware serial, software serial, usb serial, etc) all inherit from the Stream class. So, pass a pointer (or reference) to an object of Stream class.

However, if you're only going to send TX data out, then make it a pointer (or reference) to an object of the Print class. Stream inherits from Print. Specifying a Print object would allow you to also send TX data to write-only devices like LCD screens (in addition to Serial objects, of course).