diff --git a/plugins/dmxusb/src/qtserial-interface.cpp b/plugins/dmxusb/src/qtserial-interface.cpp index 6311e43e8..481369aad 100644 --- a/plugins/dmxusb/src/qtserial-interface.cpp +++ b/plugins/dmxusb/src/qtserial-interface.cpp @@ -135,7 +135,8 @@ QList QtSerialInterface::interfaces(QList discov QString name(info.description()); QString vendor(info.manufacturer()); - qDebug() << "[QtSerialInterface] Serial: " << serial << "name:" << name << "vendor:" << vendor; + if (!serial.isEmpty() && !name.isEmpty() && !vendor.isEmpty()) + qDebug() << "[QtSerialInterface] Serial: " << serial << "name:" << name << "vendor:" << vendor; // Skip non wanted devices if (validInterface(info.vendorIdentifier(), info.productIdentifier()) == false) @@ -199,8 +200,8 @@ bool QtSerialInterface::open() return false; } - m_handle->setReadBufferSize(1024); - qDebug() << "Read buffer size:" << m_handle->readBufferSize() << m_handle->errorString(); + //m_handle->setReadBufferSize(1024); + //qDebug() << "Read buffer size:" << m_handle->readBufferSize() << m_handle->errorString(); return true; } @@ -392,7 +393,7 @@ bool QtSerialInterface::write(const QByteArray& data) } } -QByteArray QtSerialInterface::read(int size, uchar* userBuffer) +QByteArray QtSerialInterface::read(int size, uchar *userBuffer) { //qDebug() << Q_FUNC_INFO; @@ -401,14 +402,21 @@ QByteArray QtSerialInterface::read(int size, uchar* userBuffer) if (m_handle == NULL) return QByteArray(); - if (m_handle->waitForReadyRead(10) == true) + if (m_readBuffer.length() < size) { - return m_handle->read(size); + if (m_handle->waitForReadyRead(10) == true) + { + m_readBuffer.append(m_handle->read(1024)); + //qDebug() << "[QtSerial] read buffer payload:" << m_readBuffer.toHex(','); + } } - return QByteArray(); + QByteArray ret = m_readBuffer.mid(0, qMin(size, m_readBuffer.length())); + m_readBuffer.remove(0, qMin(size, m_readBuffer.length())); + + return ret; } -uchar QtSerialInterface::readByte(bool* ok) +uchar QtSerialInterface::readByte(bool *ok) { if (ok) *ok = false; @@ -417,15 +425,22 @@ uchar QtSerialInterface::readByte(bool* ok) //qDebug() << Q_FUNC_INFO; - if (m_handle->waitForReadyRead(10) == true) + if (m_readBuffer.length() < 1) { - QByteArray array = m_handle->read(1); - if (array.size() > 0) + if (m_handle->waitForReadyRead(10) == true) { - if (ok) *ok = true; - return (uchar)array.at(0); + m_readBuffer.append(m_handle->read(1024)); + //qDebug() << "[QtSerial] read buffer payload:" << m_readBuffer.toHex(','); } } + if (m_readBuffer.size() > 0) + { + if (ok) *ok = true; + uchar retByte = uchar(m_readBuffer.at(0)); + m_readBuffer.remove(0, 1); + return retByte; + } + return 0; } diff --git a/plugins/dmxusb/src/qtserial-interface.h b/plugins/dmxusb/src/qtserial-interface.h index 78b4b71fb..daed5a7bc 100644 --- a/plugins/dmxusb/src/qtserial-interface.h +++ b/plugins/dmxusb/src/qtserial-interface.h @@ -99,6 +99,7 @@ class QtSerialInterface : public DMXInterface private: QSerialPort *m_handle; QSerialPortInfo m_info; + QByteArray m_readBuffer; }; #endif