SERIAL++ library: simple serial port access

◆ read() [1/2]

std::string serialport::SerialPort::read ( const std::string &  delim = "\n") const

read from port until delimiter

read from port

Definition at line 83 of file serialport.cc.

References Mdebug, Mfd, sendxoff(), and sendxon().

Referenced by main(), and read().

84  {
85  std::string retval;
86  const int nbuf=255;
87  char buffer[nbuf];
88  bool hot=true;
89  this->sendxon();
90  while (hot)
91  {
92  int nbytes=::read(Mfd, buffer, nbuf);
93  if (Mdebug)
94  {
95  std::cout << "SerialPort::read: " << std::endl
96  << "read " << nbytes << " characters" << std::endl;
97  }
98  if (nbytes>0) { retval.append(buffer, nbytes); }
99  if (retval.find(delim)!=std::string::npos) { hot=false; }
100  }
101  this->sendxoff();
102  return(retval);
103  }
std::string read(const std::string &delim="\) const
read from port until delimiter
Definition: serialport.cc:83
void sendxoff() const
send xoff
Definition: serialport.cc:118
int Mfd
file descriptor to this port
Definition: serialport.h:90
bool Mdebug
debug flag
Definition: serialport.h:92
void sendxon() const
send xon
Definition: serialport.cc:113
Here is the call graph for this function:
Here is the caller graph for this function: