4 #include "abstractio.hpp"
10 #include <sys/types.h>
16 class SerialPort: public AbstractIo
22 SerialPort(std::string _tty)
33 int setSpeed(int newspeed)
61 fd = ::open(tty.c_str(), O_RDWR, O_NOCTTY);
65 DebugOut()<<"Cannot open serial device."<<endl;
69 struct termios oldtio;
70 tcgetattr(fd,&oldtio);
72 oldtio.c_cflag |= CS8 | CLOCAL | CREAD;
74 oldtio.c_iflag |= IGNPAR;
75 oldtio.c_iflag &= ~(ICRNL | IMAXBEL);
78 oldtio.c_oflag &= ~OPOST;
80 oldtio.c_lflag |= ECHOE | ECHOK | ECHOCTL | ECHOKE;
81 oldtio.c_lflag &= ~(ECHO | ICANON | ISIG);
83 //oldtio.c_cc[VEOL] = '\r';
85 cfsetispeed(&oldtio, speed);
86 cfsetospeed(&oldtio, speed);
88 tcflush(fd, TCIFLUSH);
89 tcsetattr(fd, TCSANOW, &oldtio);
91 fcntl(fd,F_SETFL,O_NONBLOCK);
96 int fileDescriptor() { return fd; }
108 while( bytesread = ::read(fd,&buff,1) > 0 )
115 perror("Error while reading: ");
120 void write(std::string data)
122 int written = ::write(fd,data.c_str(),data.length());
125 DebugOut()<<"Unable to write"<<endl;