4 #include "abstractio.hpp"
10 #include <sys/types.h>
16 class SerialPort: public AbstractIo
19 SerialPort(std::string _tty)
32 fd = ::open(tty.c_str(), O_RDWR, O_NOCTTY);
36 DebugOut()<<"Cannot open serial device."<<endl;
40 struct termios oldtio;
41 tcgetattr(fd,&oldtio);
43 oldtio.c_cflag |= CS8 | CLOCAL | CREAD;
45 oldtio.c_iflag |= IGNPAR;
46 oldtio.c_iflag &= ~(ICRNL | IMAXBEL);
49 oldtio.c_oflag &= ~OPOST;
51 oldtio.c_lflag |= ECHOE | ECHOK | ECHOCTL | ECHOKE;
52 oldtio.c_lflag &= ~(ECHO | ICANON | ISIG);
54 //oldtio.c_cc[VEOL] = '\r';
56 cfsetispeed(&oldtio, B9600);
57 cfsetospeed(&oldtio, B9600);
59 tcflush(fd, TCIFLUSH);
60 tcsetattr(fd, TCSANOW, &oldtio);
62 fcntl(fd,F_SETFL,O_NONBLOCK);
67 int fileDescriptor() { return fd; }
79 while( bytesread = ::read(fd,&buff,1) > 0 )
86 perror("Error while reading: ");
91 void write(std::string data)
93 int written = ::write(fd,data.c_str(),data.length());
96 DebugOut()<<"Unable to write"<<endl;