Skip to content

Instantly share code, notes, and snippets.

@ukicomputers
Last active December 23, 2023 17:03
Show Gist options
  • Save ukicomputers/0a4f9aa8842a89ebb5fd09589f8c80fd to your computer and use it in GitHub Desktop.
Save ukicomputers/0a4f9aa8842a89ebb5fd09589f8c80fd to your computer and use it in GitHub Desktop.
// Fully working code for reading from serial port in Linux
// Tested on STM32F437ZG
#include <libserial/SerialPort.h>
#include <iostream>
using namespace LibSerial;
int main() {
SerialPort serial;
serial.Open("/dev/ttyUSB0");
serial.SetBaudRate(BaudRate::BAUD_115200);
serial.SetFlowControl(FlowControl::FLOW_CONTROL_NONE);
while(1) {
std::string read;
serial.ReadLine(read);
std::cout << read;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment