QSerial Problems
-
Hello,
I used QSerial to make a connection between a computer and a µC. The µC sends every time data. Then my routine is connected to readyRead(). So I get every byte. But the readyRead() function will called two times even I send only one Byte. So when I add the byte to a listwidget it adds me one time the char and an empty line. Why thats do that? The controller send also a '\0' char but for this I don't get a call of readyRead(). Does anyone know how I can do it right?
Martin
-
Hi if you do
void MainWindow::handleReadyRead() {
m_readData.append( m_serialPort->readAll() );
then m_readData.size() == 2 even if u send one 1 char?(m_readData is bytearray)
-
I would start with disconnecting readyRead with suitable slot and than connecting it again just to make sure you dont have double connection (which can couse function to be called twice)
disconnect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead())); connect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
-
@michelson said:
I would start with disconnecting readyRead with suitable slot and than connecting it again just to make sure you dont have double connection (which can couse function to be called twice)
disconnect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead())); connect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
This cleared all empty lines out. But the '\0' will not handled why?
-
@Wuzi
Ok. on win 7. mingw
I can send \0 and it will trigger readyRead()send: QByteArray t; t.append('\0'); serial->write(t); read: mainWindow::handleReadyRead() { QByteArray buf = m_serialPort->readAll(); m_readData.append( buf);
Strange it won't trigger in your case. What platform are you on?
-
@Wuzi said:
QStrings do not use \0 as end of string marker , as far as i know
but will put one there when converted to std string etc.
QbyteArray can also include the \0
please see
http://doc.qt.io/qt-5/qbytearray.html#data