bool CommInterface::openPort(const QString& portname, const QString& baudrate) { QSerialPort* port = new QSerialPort(portname); _port = port; connect(port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handleSerialError(QSerialPort::SerialPortError))); _protocol = new Comm::RobotProtocol(port, 0, true); _protocol->beQuiet(true); _protocol->setDebugMode(true, false, false); if (_protocol->open()) { port->setBaudRate(baudrate.toInt()); port->setFlowControl(QSerialPort::NoFlowControl); port->setParity(QSerialPort::NoParity); port->setDataBits(QSerialPort::Data8); port->setStopBits(QSerialPort::OneStop); } else { delete _protocol; _protocol = 0; return false; } _comm = new Comm::RobotCommInterface(_protocol, new Comm::AX12CommManager, 0, this, this); changeStatus(true); return true; }
SerialCommandQueue::SerialCommandQueue(QObject *parent) : QObject(parent) { serial = new QSerialPort(this); serial->setSettingsRestoredOnClose(false); connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handleSerialError(QSerialPort::SerialPortError))); connect(serial, SIGNAL(readyRead()), this, SLOT(handleReadData())); commandTimeoutTimer.setSingleShot(true); connect(&commandTimeoutTimer, SIGNAL(timeout()), this, SLOT(handleCommandTimeout())); }