Unsolved QSerialPort doesn't actually print to port
-
I'm trying to make a very simple app in Qt that prints a "G" to a comport, that is connected to a driver through rs232. After sending the G, the light should turn on, and I should get a response from the driver. These are the snippets of code that deals with the serialport:
The setup:
ledDriver = new QSerialPort; ledDriver->setPortName(right); ledDriver->open(QSerialPort::ReadWrite); ledDriver->setBaudRate(QSerialPort::Baud38400); ledDriver->setDataBits(QSerialPort::Data8); ledDriver->setParity(QSerialPort::NoParity); ledDriver->setStopBits(QSerialPort::OneStop); ledDriver->setFlowControl(QSerialPort::NoFlowControl);
and the writing that happens when you click a button:
ledDriver->flush(); if(ledDriver->isWritable()){ QString temp = "G"; qDebug() << temp; QByteArray ba = temp.toLocal8Bit(); ledDriver->write(ba); if (ledDriver->waitForBytesWritten(1000)) { } else { qDebug() << "Write timed out"; } }else{ qDebug() << "Serial is not writable"; } if (ledDriver->waitForReadyRead(1000)) { QByteArray responseData = ledDriver->readAll(); while (ledDriver->waitForReadyRead(10)) responseData += ledDriver->readAll(); QString response(responseData); qDebug() << "response:" + response; } else { qDebug() << "Read timed out"; }
Now the only response I get is the exact same phrase I send. So if I send G, the response is "G" instead of the number I'm suppose to be getting.
If I open Putty afterwards, and send anything (doesn't matter what), THEN the G is sendt, the light turns on, and I get the respons I'm suppose to be getting. So it seems like Qt is writing the signal but not sending it? Am I missing something very obvious here?
Environment is Windows 10 x64 on Qt 5.5.1 with newest MinGW32.
-
I should also add that I have the same issue when using the blockingmaster example (not a large surprise since that's where I've taken much of the code from). BUT the terminal example works perfectly..
-
These same and same and same questions appears hundred thousand times per month. And nobody want to search the solution (by googling) himself, it take about 5 minutes. The terminal example sends the 'CR' character when you press to "Enter" button, but your code does not!
-
I understand the frustration about people asking the same questions, I share it equally, but I have been googling this for absolutely days now (and no, my googling skills do not suck). There is ZERO documentation in the code itself, so it's difficult enough to understand what the fuck is going on let alone debug the thing. I did also look through this forum quickly to see if there was a question similar to mine but couldn't find any.
I thank you for your answer thought. That should help me plenty :)
-
Can you try!
ledDriver ->write(command.toStdString().c_str());
-