QSerialPort not working, but shows no errors (Ubuntu)
Hello,
I need to use QSerialPort together with a USB serial adapter on Ubuntu.
This is a FT232RL which is mounted as "ttyUSB0".
Using CuteCom I can use the serial adapter and it is working fine.
Sadly with QT I am not able to access ttyUSB0.
I get no errors while compiling and executing the programm leads to an empty console window which freezes :-(
If I change ttyUSB0 to some not existing thing like ttyUSB, I get the error that he could not open the device.
So this is actually good.
But I have no Idea, how to solve my problem :-(
It would be really nice if you could help me.
Thank you very much :-)
This is the code I tried:
Code:
#include <iostream>
#include <QApplication>
#include <QSerialPort>
using namespace std;
QSerialPort serial;
int main (int argc, char *argv[])
{
serial.setPortName("/dev/ttyUSB0");
serial.setBaudRate(QSerialPort::Baud19200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
for (int i=0; i<100; i++)
{
serial.write("test");
serial.flush();
cout << i << endl;
}
serial.close();
return 0;
}
And this is my .pro file:
Code:
QT += core serialport widgets
QT -= gui
TARGET = Timer
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x
Re: QSerialPort not working, but shows no errors (Ubuntu)
Shouldn't you be setting the options before opening the port? And I would suggest to avoid making the port object a global variable.
Re: QSerialPort not working, but shows no errors (Ubuntu)
As I recall QSerialPort needs an event loop or the use of method waitForBytesWritten();
Re: QSerialPort not working, but shows no errors (Ubuntu)
Also check that the user you are running as has read and write permission to that port. Usually this means a particular group membership. ( Cutecom may be working only because it is marked setuid or setgid.)
Re: QSerialPort not working, but shows no errors (Ubuntu)
Sorry for the late reaction.
I had no Internet on the last days :-(
I found out the problem.
The last hint with the permissions was quiet good. :-)
There was a lockfile on the port.
After deleting the lockfile in the folder /var/lock everything worked well :-)
Thank you very much!