37 #define TF_SERIALPORT_CC_VERSION \ 38 "TF_SERIALPORT_CC V1.1" 39 #define TF_SERIALPORT_CC_CVSID \ 53 Mfd=open(devname.c_str(), flags);
75 int n,len=text.size();
95 std::cout <<
"SerialPort::read: " << std::endl
96 <<
"read " << nbytes <<
" characters" << std::endl;
98 if (nbytes>0) { retval.append(buffer, nbytes); }
99 if (retval.find(delim)!=std::string::npos) { hot=
false; }
109 {
return(::
read(
Mfd, buffer, bufsize)); }
125 struct termios options;
126 ::tcgetattr(
Mfd, &options);
127 options.c_cflag |= CLOCAL;
128 ::tcsetattr(
Mfd, TCSANOW, &options);
135 struct termios options;
136 ::tcgetattr(
Mfd, &options);
137 options.c_cflag |= PARENB;
138 options.c_cflag &= ~PARODD;
139 options.c_cflag &= ~CSTOPB;
140 options.c_cflag &= ~CSIZE;
141 options.c_cflag |= CS7;
142 ::tcsetattr(
Mfd, TCSANOW, &options);
149 struct termios options;
150 ::tcgetattr(
Mfd, &options);
151 options.c_iflag |= (IXON | IXOFF | IXANY);
152 ::tcsetattr(
Mfd, TCSANOW, &options);
154 ::tcflow(
Mfd, TCIOFF);
161 struct termios options;
162 ::tcgetattr(
Mfd, &options);
163 ::cfsetispeed(&options, B9600);
164 ::cfsetospeed(&options, B9600);
165 ::tcsetattr(
Mfd, TCSANOW, &options);
172 struct termios options;
173 ::tcgetattr(
Mfd, &options);
174 ::cfmakeraw(&options);
175 ::tcsetattr(
Mfd, TCSANOW, &options);
void clocal() const
set clocal
void baud9600() const
select 9600 baud
std::string read(const std::string &delim="\) const
read from port until delimiter
#define SERIALPORT_assert(C, M)
Check an assertion and report by throwing an exception.
code to access a serial port (prototypes)
bool Musexon
use xon/xoff flow control
error handling code for serial port access (prototypes)
Root namespace of library.
struct termios Mdevoptions
remember device status
void makeraw() const
issue cfmakeraw
void write(const std::string &text) const
write string to port
void mode7E1() const
set 7 data bits, even parity, 1 stop bit
SerialPort(const std::string &devname, const int &flags=(O_RDWR|O_NOCTTY|O_NDELAY))
open port by name of device file
void sendxoff() const
send xoff
int Mfd
file descriptor to this port
void flowxon()
set xon/xoff slow control
void sendxon() const
send xon