Qt serial communication using UART
-
Thaky you for your reply.
i add
//void MainWindow::on_pushButton_send_clicked()
{
port->open(QSerialPort::ReadWrite);
port->write(ui->lineEdit_command->text().toLatin1());}// in my code and enter the command at lineEdit , but device can't conduct command..
Is there something else i have to anything for device's behavior?
@segtteee said in Qt serial communication using UART:
in my code and enter the command at lineEdit , but device can't conduct command..
Well, I can't guess what error codes are you getting, right? I don't even know if you connected to the device correctly. Did it get the command? Did it reply with anything? Have you connected the readyRead() to some slot, or used waitForReadyRead() to wait for the reply?
I don't give you whole solution for your problem, I'm not here to write the code for you. I'm happy to help you overcome problems and learn.
-
@segtteee said in Qt serial communication using UART:
in my code and enter the command at lineEdit , but device can't conduct command..
Well, I can't guess what error codes are you getting, right? I don't even know if you connected to the device correctly. Did it get the command? Did it reply with anything? Have you connected the readyRead() to some slot, or used waitForReadyRead() to wait for the reply?
I don't give you whole solution for your problem, I'm not here to write the code for you. I'm happy to help you overcome problems and learn.
-
@segtteee: I can only recommend you to have a look at the examples (there are a lot of them):
http://doc.qt.io/qt-5/qtserialport-examples.html
Take, e.g. the Terminal example http://doc.qt.io/qt-5/qtserialport-terminal-example.html and try to understand how it works. It should be very near to what you want to achive.
PS: This example also shows how to check for some errors. Depending on the communication protocol, you may have to add more error checks.
-
@segtteee: I can only recommend you to have a look at the examples (there are a lot of them):
http://doc.qt.io/qt-5/qtserialport-examples.html
Take, e.g. the Terminal example http://doc.qt.io/qt-5/qtserialport-terminal-example.html and try to understand how it works. It should be very near to what you want to achive.
PS: This example also shows how to check for some errors. Depending on the communication protocol, you may have to add more error checks.
-
@segtteee said in Qt serial communication using UART:
i have question , how to check connected device with qt ? only i enter the command and device conduct command?
First step is to check if
port->open()
returnedtrue
.
When callingport->write()
you can check if the amount of bytes written is the same you sent. If not, something went wrong. Then you can check QSerialPort::error and see what was the problem.Another clue might be whether
readyRead()
is emitted in response to your command. If there is no reply, then again - something might be wrong (or not - that depends on what the command is and which device you connect to). -
@segtteee said in Qt serial communication using UART:
i have question , how to check connected device with qt ? only i enter the command and device conduct command?
First step is to check if
port->open()
returnedtrue
.
When callingport->write()
you can check if the amount of bytes written is the same you sent. If not, something went wrong. Then you can check QSerialPort::error and see what was the problem.Another clue might be whether
readyRead()
is emitted in response to your command. If there is no reply, then again - something might be wrong (or not - that depends on what the command is and which device you connect to). -
Hi
For a pretty good example, please see
http://doc.qt.io/qt-5/qtserialport-terminal-example.html
It has dialog to select comport properties and allows to send text out of the box.
Its also pretty good explained.~ -
Hi
For a pretty good example, please see
http://doc.qt.io/qt-5/qtserialport-terminal-example.html
It has dialog to select comport properties and allows to send text out of the box.
Its also pretty good explained.~ -
@mrjj said in Qt serial communication using UART:
@aha_1980
Oh yes. sorry. i did miss. Clicked from locked thread. Should have read it all :)No problem :) (And no need to delete your post)