6 years, 8 months ago.

How to read serial data sent by the board on the IDE?

Hello everyone!

I'm trying to use the data acquired by my board as an input for another program in C++ running on my IDE and I'm not sure about what's the best way to do so.

Can I simply use the mbed library on the IDE and use the SerialPC from that? Would that work?

Otherwise I found multiple solutions on the internet, all of which use different libraries like SerialComm.h or SerialClass.h and I'm getting just a lot of problems in using them as most of the times some adjustments in the code are required and there's not much helping material to be easily found on internet.

So... What are your suggestions? Thanks a lot!

1 Answer

6 years, 8 months ago.

Either:

  1. Connect to the COM port directly and read the data from there straight into your program. On Windows you can do this by creating a handle through CreateFile and then use ReadFile. See here. On Linux and macOS you can also get a handle to the port.
  2. Use a serial monitor that can take the data from your board and append it to a file. Tera Term on Windows does this via *File > Log*. Data gets written to the file when read and you can use normal file system calls to tail the file.

On the mbed board just call printf like you'd always do (or putc() or whatever).