Skeletal Animation Multithread Face
serial_com.cpp
Go to the documentation of this file.
1#include "../include/serial_com.h"
2
8void SerialCOM::writeString(std::string s)
9{
10 boost::asio::write(serial,boost::asio::buffer(s.c_str(),s.size()));
11}
12
20{
21 //Reading data char by char, code is optimized for simplicity, not speed
22 using namespace boost;
23 char c;
24 std::string result;
25 for(;;)
26 {
27 asio::read(serial,asio::buffer(&c,1));
28 switch(c)
29 {
30 case '\r':
31 break;
32 case '\n':
33 return result;
34 default:
35 result+=c;
36 }
37 }
38}
39
46{
47 // Read first (iter) lines to start
48 for (size_t i = 0; i < iter; i++)
49 {
50 std::string incoming_str = this->readLine();
51 }
52}
void writeString(std::string s)
Write a string to the serial device.
Definition: serial_com.cpp:8
void initialize_stream(int iter=3)
Setup up stream by reading the values a couple times first.
Definition: serial_com.cpp:45
std::string readLine(void)
Blocks until a line is received from the serial device.
Definition: serial_com.cpp:19
boost::asio::serial_port serial
Boost serial port handle.
Definition: serial_com.h:43