MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setWindowTitle(QString("XKSimulator %1").arg(getVersionString())); m_serial = new SerialPort(); connect(m_serial, SIGNAL(serialError(QString)), this, SLOT(serialError(QString))); connect(m_serial, SIGNAL(serialStatus(QString)), this, SLOT(serialStatus(QString))); m_error = new QLabel(""); statusBar()->addWidget(m_error); m_enum = new QextSerialEnumerator(); #ifdef Q_OS_WIN connect(m_enum, SIGNAL(deviceDiscovered(QextPortInfo)), this, SLOT(deviceDiscovered(QextPortInfo))); connect(m_enum, SIGNAL(deviceRemoved(QextPortInfo)), this, SLOT(deviceRemoved(QextPortInfo))); m_enum->setUpNotifications(); #endif m_gpsTimer = new QTimer(this); connect(m_gpsTimer, SIGNAL(timeout()), this, SLOT(gpsTimer())); // Load the application settings (not the command settings) loadAppSettings(); // Load the list of available serial ports loadComPorts(); m_serial->open(m_tty); // Open the selected serial port }
void SerialUIUser::checkIfMessageWasError() { static const DRUIDString errorPrefix_str(SUI_SERIALUI_MESSAGE_ERROR_PREFIX); const DRUIDString errorGeneric_str(ctrl_strings.error); // make a copy, last_message can change asynchronously DRUIDString msg(last_msg.get()); if (! boost::algorithm::find_first(msg, errorGeneric_str)) { // no error, fuggetaboudit return; } // get rid of "ERROR:" boost::algorithm::erase_first(msg, errorPrefix_str); boost::algorithm::erase_first(msg, errorGeneric_str); // set the last_message to the "cleaned up" version last_msg.setTo(msg); SerialUserStringList errMsgList = lastMessageAsList(); std::string errMsg; errMsg.reserve(msg.size()); for (SerialUserStringList::iterator iter = errMsgList.begin(); iter != errMsgList.end(); iter++) { errMsg += truncatePromptFrom(*iter); } serialError(errMsg); }
void SerialPort::connects() { connect(serial, SIGNAL(readyRead()), this, SLOT(lineReceived())); connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError))); connect(timer, SIGNAL(timeout()), this, SLOT(onTimerTimeout())); }
// ###################################################################### serialError SerialPort::setCharBits(const int bits) { termios options; if (tcgetattr(dev, &options) == -1) { serialErrno = serialErrTcGetAttrFailed; return serialErrno; } options.c_cflag &= ~CSIZE; // mask off the 'size' bits switch (bits) { case 5: options.c_cflag |= CS5; break; case 6: options.c_cflag |= CS6; break; case 7: options.c_cflag |= CS7; break; case 8: options.c_cflag |= CS8; break; default: return serialError(serialErrCharsizeInvalid); } if (tcsetattr(dev, TCSANOW, &options) == -1) { serialErrno = serialErrTcSetAttrFailed; return serialErrno; } // update our ModelParam: itsCharBits = bits; return serialErrSuccess; }
// ###################################################################### serialError SerialPort::setStopBits(const int bits) { struct termios options; if (tcgetattr(dev, &options) == -1) { serialErrno = serialErrTcGetAttrFailed; return serialErrno; } options.c_cflag &= ~CSTOPB; if (bits == 2) options.c_cflag |= CSTOPB; else if (bits != 1) return serialError(serialErrStopbitsInvalid); if (tcsetattr(dev, TCSANOW, &options) == -1) { serialErrno = serialErrTcSetAttrFailed; return serialErrno; } // update our ModelParam: itsStopBits = bits; return serialErrSuccess; }
// ###################################################################### serialError SerialPort::setSpeed(const int speed) { struct termios options; unsigned int rate; switch (speed) { case 115200: rate = B115200; break; case 57600: rate = B57600; break; case 38400: rate = B38400; break; case 19200: rate = B19200; break; case 9600: rate = B9600; break; case 4800: rate = B4800; break; case 2400: rate = B2400; break; case 1200: rate = B1200; break; case 600: rate = B600; break; case 300: rate = B300; break; case 110: rate = B110; break; case 0: rate = B0; break; default: return serialError(serialErrSpeedInvalid); } // get current options if (tcgetattr(dev, &options) == -1) { serialErrno = serialErrTcGetAttrFailed; return serialErrno; } // set the speed cfsetispeed(&options, rate); cfsetospeed(&options, rate); // change the terminals parameter instantly if (tcsetattr(dev, TCSANOW, &options) == -1) { serialErrno = serialErrTcSetAttrFailed; return serialErrno; } if (tcgetattr(dev, &options) == -1) { serialErrno = serialErrTcGetAttrFailed; return serialErrno; } // update our ModelParam: itsBaud = speed; return serialErrSuccess; }