How to write on a serial port using Qextserialport

I am using Ubunt 10.10.

I want to communicate with the microcontroller (ATmega328p) using serial through QT, so for testing I created a dummy application on the microcontroller that reads a character from UART and responds to the serial port (answers) with the same character, but between the brackets.

If the PC sends: a, then the PC receives a response [a]

The application works fine when I use hyperterminal (GtkTerm) to send characters from a PC, but when I use QT, it does not work. I am sending a character from QT to the serial port, and I am waiting to receive a response to the hyperterminal, but I am not getting any response.

Serial Communication Properties: Baud9600, Parity_none, Stop_bits_1, Data_8bits, Flow_control_Off

#include <QtCore/QCoreApplication> #include <qextserialport.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); const char data[]= "e"; QextSerialPort * port = new QextSerialPort("/dev/ttyUSB0"); port->setBaudRate(BAUD9600); port->setFlowControl(FLOW_OFF); port->setParity(PAR_NONE); port->setDataBits(DATA_8); port->setStopBits(STOP_1); port->setTimeout(0); bool res = false; res = port->open(QIODevice::ReadWrite | QIODevice::Unbuffered); if(res) { qDebug("Opened"); qDebug(data); int i = port->write(data, sizeof(data)); } else { qDebug("Failed to connect"); } return a.exec(); } 

Any idea what is wrong?

+4
source share
1 answer

It does not work because you open the serial port 2 times (1 time in Qt and at another time with your HyperTerminal).

If you want a response from your team, you must do this in your Qt program.

+1
source

All Articles