Unsolved Unable to read the response from the hardware.
-
This post is deleted! -
@Mohit-Tripathi said in Unable to read the response from the hardware.:
Can I know what is wrong here?
You don't start the event loop. So
waitForReadyRead()
won't work.Start the event loop (
app.exec()
) and then kickoff your algorithm (via QTimer for example). -
@sierdzio said in Unable to read the response from the hardware.:
@Mohit-Tripathi said in Unable to read the response from the hardware.:
Can I know what is wrong here?
You don't start the event loop. So
waitForReadyRead()
won't work.Start the event loop (
app.exec()
) and then kickoff your algorithm (via QTimer for example).Furthermore, don't use an infinite loop (
while (true) {...}
). The infinite loop blocks the event loop.See the QSerialPort examples for help.
-
This post is deleted! -
This post is deleted! -
@Mohit-Tripathi said in Unable to read the response from the hardware.:
return app.exec();
Calling app.exec() in a loop is utterly wrong. Don't ever do it!
If your previous solution did work, stick to that. Or rewrite your code as I suggested initially (move serial code into a class, call it using
QTimer::singleShot(1, &YourClass::start);
).I am getting the value in split form and not getting the excepted result.
Then simply glue the response back together in your code.
-
-
@Mohit-Tripathi said in Unable to read the response from the hardware.:
@sierdzio @JKSH
Is this the right format of read value in Qt "303030303030313000632c"?
The write value is 01020001000a.
How can I check the read value is correct?We have no way of knowing that. You are communicating with your serial port device. Inspect the device API to know what kind of responses you should expect. We don't know what device it is and what software it runs...
-
@JKSH @sierdzio
I am using the Hercules software to get the response from the hardware.
But, I am not getting the same response in the Qt. I am using the PIC micro-controller.
The query is 01020001000a.
I am getting the response from the hardware into the Hercules is 00000010{00}c but into Qt "03030303030313000632c".
How can I get the same response?
I think that I am getting the correct response in Hercules but I am not getting the correct response in Qt.
I want to be sure about the response in Qt. This is correct or not.
Is there any way to find? -
What happens if you convert to hex before sending?
void transmit(QSerialPort & port, const QByteArray & data) { port.write(data.toHex()); qDebug() << "\nWrote" << data.size() << ":" << data.toHex().constData(); chkError(port); }
-
@sierdzio
Nothing is reading here. If I am using the port.write(data.toHex()). -
@Mohit Tripathi
just use waitForBytesWritten() after the write call, and wairForReadyRed() before the read call, in your synhronous approach.