0
votes

I am trying to write a string command to the serial port of my Raspberry Pi 2 B without success. I followed this http://www.raspberry-projects.com/pi/programming-in-c/uart-serial-port/using-the-uart, but I need to send and receive QStrings (or arrays of bytes). Are there specific c++ functions that send and receive strings through the RPi Serial Port? Could someone share some sample code? Many thanks in advance!

Andrea

1

1 Answers

0
votes

If you look at the QString docs you will see a number of methods that convert QString to other types. QString is just a wrapper around a character string.

To get at the underlying char buffer you can do something like this:

std::string stdStr = qString.toStdString();
char* buffer = stdStr.c_str();

Make sure that stdStr stays in scope as long as you wish to use buffer otherwise you will end up using a pointer that points to deallocated memory.