diff options
Diffstat (limited to 'glcddrivers/port.c')
-rw-r--r-- | glcddrivers/port.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/glcddrivers/port.c b/glcddrivers/port.c index cfb4156..26592c4 100644 --- a/glcddrivers/port.c +++ b/glcddrivers/port.c @@ -16,7 +16,6 @@ #include <string.h> #include <syslog.h> #include <unistd.h> -#include <termios.h> #include <pthread.h> #include <sys/io.h> #include <sys/ioctl.h> @@ -335,19 +334,30 @@ int cSerialPort::Open(const char * device) cfsetispeed(&options, B921600); cfsetospeed(&options, B921600); + // 8 bits, no parity, no stop bits options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; + // No "hangup" (prevents Arduino firmware reboots) + options.c_cflag &= ~HUPCL; + + // No hardware flow control options.c_cflag &= ~CRTSCTS; + // Enable receiver, ignore status lines options.c_cflag |= (CLOCAL | CREAD); + // disable canonical input, disable echo, + // disable visually erase chars + // disable terminal-generated signals options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + // disable input/output flow control, disable restart chars options.c_iflag &= ~(IXON | IXOFF | IXANY); + // disable output processing options.c_oflag &= ~OPOST; tcsetattr(fd, TCSANOW, &options); @@ -363,6 +373,15 @@ int cSerialPort::Close() return 0; } +void cSerialPort::SetBaudRate(speed_t speed) +{ + struct termios options; + tcgetattr(fd, &options); + cfsetispeed(&options, speed); + cfsetospeed(&options, speed); + tcsetattr(fd, TCSANOW, &options); +} + int cSerialPort::ReadData(unsigned char * data) { if (fd == -1) @@ -382,4 +401,8 @@ void cSerialPort::WriteData(unsigned char * data, unsigned short length) write(fd, data, length); } +void cSerialPort::WriteData(std::string data) { + WriteData((unsigned char*)data.c_str(), data.length()); +} + } // end of namespace |