Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months ago.
How to pass serial from main to other moduels?
Thanks for your code. I have ported C libs from AVRlib to mbed C++ for VT100 and cmdline for terminal menu user interaction. The main has a serial called pc, then passed it as parameters to VT100 and cmdline module.
I didn't use serial constructor in VT100 and cmdline because I don't want to contruct same uart three times. But I have some compilation errors.
vt100.h
class vt100{ public: void vt100(); void Init(Serial pc); void ClearScreen(void); ...... private: Serial ser; }
vt100.cpp
#include "vt100.h" void vt100::Init(Serial x){ ser = x; ser.printf("\x1B\x63"); } ...
But I found an error:
Quote:
mbed\Serial.h(47): error: #330-D: "mbed::Stream &mbed::Stream::operator=(const mbed::Stream &)" (declared at line 60 of "mbed\Stream.h") is inaccessible
I also tried to pass parameters to vt100::vt100(), just like passing PinName to serial/spi modules.
vt100.h, revised
class vt100{ public: void vt100(Serial pc); void ClearScreen(void); ...... private: Serial ser; }
vt100.cpp, revised
#include "vt100.h" vt100::vt100(Serial x){ ser = x; ser.printf("\x1B\x63"); }
Then I got this:
Quote:
vt100\vt100.cpp(5): error: #291: no default constructor exists for class "mbed::Serial"
mbed\Serial.h(47): error: #330-D: "mbed::Stream &mbed::Stream::operator=(const mbed::Stream &)" (declared at line 60 of "mbed\Stream.h") is inaccessible
error: #291 points to vt100:vt100() in vt100.cpp. Therefore it still asks for constructor for a parametered serial.
I am not very good at C++. Anything must be wrong, But I have no idea how to fix it.
Would you please help me out? So far I have to use all vt100 C functions in mbed C++ project, which is a bad practice.