QT reading Serialport of Arduino
-
@mimamrafi I don't know how your Arduino side is working, so can't comment
-
@mimamrafi said in QT reading Serialport of Arduino:
yes, I have been open it and the output is true
yes, thats obvious, but did you open it after setting the settings ? e.g:
void SerialPortManager::openSerialPort() { arduino->setPortName("COM8"); arduino->setBaudRate(QSerialPort::Baud9600); arduino->setDataBits(QSerialPort::Data8); arduino->setParity(QSerialPort::NoParity); arduino->setStopBits(QSerialPort::OneStop); arduino->setFlowControl(QSerialPort::NoFlowControl); arduino->open(QIODevice::ReadWrite); }
assuming of course, those are the same settings as the other program uses.
-
@mimamrafi try adding a sleep/delay at the end of your Arduino loop, see if that improves things.
-
@jsulm said in QT reading Serialport of Arduino:
Yes, it should be AFTER you set the parameters (like setFlowControl).
No. It is irrelevant.
-
@kuzulis I was about to vehemently deny this, but then I noticed the setters have boolean return type.
I was only going on the notes from https://doc.qt.io/qt-5/qserialport.html#open
that says it sets the settings during open().did this change in one of the newer versions?apparently not. At least not as far back as 5.12 -
Hai everyone. I found some clues about this topic. The serial communication have to enable the DTR (Data Terminal Ready). So this is my current code that I used
void SerialPortManager::openSerialPort() { arduino->setPortName("COM8"); arduino->open(QIODevice::ReadWrite); arduino->setBaudRate(QSerialPort::Baud9600); arduino->setDataBits(QSerialPort::Data8); arduino->setParity(QSerialPort::NoParity); arduino->setStopBits(QSerialPort::OneStop); arduino->setFlowControl(QSerialPort::NoFlowControl); arduino->setDataTerminalReady(true); }
Actually, I don't know why its working, but some of tutorial it's not a problem without writing setDataTerminalReady
-
J J.Hilk referenced this topic on