Using Serial I/O in cpp

Can Serial I/O be used in cpp files?

I believe that’s a yes?

Why should it not be possible?
Actually an .ino will be made into a .cpp by the preprocessor anyway by adding #include "Particle.h" and required function prototypes.

Thanks ScruffR. Is there a list of includes available. That suggestion solved one problem, but now I am having trouble with using Serial with output stream.

 cqueue.cpp:18:10: error: no match for 'operator<<' (operand types are 'USBSerial' and 'const char [15]')
   Serial << "\nQueue is full" ;
          ^

Any ideas would be welcome.

I’m not sure why, but the << operator seems to be missing in Print class (one of the base classes of USBSerial), so you might need to use the clumsy way of calling functions (write()/print()).

Normally you shouldn’t need to include anything other than Particle.h (unless instructed in the docs or non-Particle stuff).
You can always download the open source firmware repo to see what’s there and how it’s done.


Update:
I’ve filed an enhancment issue for this on GitHub

2 Likes

Thanks again, ScruffR