27 className = this->staticMetaObject.className();
40 struct termios options;
46 mDev_fd = open(dev_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
52 if (ioctl(
mDev_fd, TIOCEXCL) == -1)
54 emit
message(QString(
"<font color=\"#FF0000\">ERROR %1 setting TIOCEXCL on serial device:<br>%2 in %3.</font>").arg(errno).arg(strerror(errno)).arg(
className));
55 emit
message(QString(
"<font color=\"#FF0000\">Serial port already opened?</font>"));
61 if (fcntl(
mDev_fd, F_SETFL, 0) == -1)
63 emit
message(QString(
"<font color=\"#FF0000\">ERROR %1 clearing O_NONBLOCK on serial device:<br>%2 in %3.</font>").arg(errno).arg(strerror(errno)).arg(
className));
69 emit
message(QString(
"<font color=\"#FF0000\">ERROR %1 opening serial device:<br>%2 in %3.</font>").arg(errno).arg(strerror(errno)).arg(
className));
78 options.c_cflag |= CLOCAL;
81 options.c_cflag &= ~PARENB;
82 options.c_cflag &= ~CSTOPB;
83 options.c_cflag &= ~CSIZE;
84 options.c_cflag |= CS8;
87 options.c_cflag &= ~CRTSCTS;
91 options.c_cc[VTIME] = 0;
92 options.c_cc[VMIN] = 0;
95 newbaud = (baudrate/100);
147 spd = B115200;
break;
151 spd = B500000;
break;
158 if (cfsetispeed(&options, (speed_t) spd) != 0)
160 emit
message(QString(
"<font color=\"#FF0000\">ERROR setting serial port input speed at DirecsSerial::openPort!</font>"));
164 if (cfsetospeed(&options, (speed_t) spd) != 0)
166 emit
message(QString(
"<font color=\"#FF0000\">ERROR setting serial port output speed at DirecsSerial::openPort!</font>"));
172 emit
message(QString(
"<font color=\"#FF0000\">ERROR: Wrong value for speed parameter at DirecsSerial::openPort!</font>"));
177 if (tcflush(
mDev_fd, TCIFLUSH) != 0)
179 emit
message(QString(
"<font color=\"#FF0000\">ERROR fluhsing serial input buffer at DirecsSerial::openPort!</font>"));
188 if (tcsetattr(
mDev_fd, TCSANOW, &options) != 0)
190 emit
message(QString(
"<font color=\"#FF0000\">ERROR setting serial port attributes at DirecsSerial::openPort!</font>"));
194 emit
message(
"Serial device openend.");
205 return tcflush(
mDev_fd, TCIFLUSH);
215 emit
message(QString(
"<font color=\"#FF0000\">ERROR '%1=%2' when writing to serial device at DirecsSerial::writeData called from %3.</font>").arg(errno).arg(strerror(errno)).arg(callingClassName));
234 int amountRead = 0, bytes_read = 0;
252 returnValue = select(
mDev_fd + 1, &
set, NULL, NULL, &t);
255 if (returnValue == -1)
257 emit
message(QString(
"<font color=\"#FF0000\">ERROR '%1=%2' <br>when selecting serial device at DirecsSerial::readData called from %3.</font>").arg(errno).arg(strerror(errno)).arg(callingClassName));
269 emit
message(QString(
"<font color=\"#FF0000\">ERROR No data available within %1 ms when using select() on serial device at DirecsSerial::readData called from %2.</font>").arg(
READ_TIMEOUT_ATMEL).arg(callingClassName));
270 emit
message(QString(
"<font color=\"#FF0000\">ERROR %1: %2.</font>").arg(errno).arg(strerror(errno)));
277 amountRead = read(
mDev_fd, buf, nChars);
279 if (amountRead < 0 && errno != EWOULDBLOCK)
281 emit
message(QString(
"<font color=\"#FF0000\">ERROR '%1=%2' when using read() on serial device at DirecsSerial::readData called from %3.</font>").arg(errno).arg(strerror(errno)).arg(callingClassName));
289 bytes_read += amountRead;
290 nChars -= amountRead;