Results 1 to 5 of 5

Thread: QSerialPort not working, but shows no errors (Ubuntu)

  1. #1
    Join Date
    Mar 2014
    Posts
    18
    Qt products
    Qt5

    Unhappy 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:

    Qt Code:
    1. #include <iostream>
    2.  
    3. #include <QApplication>
    4. #include <QSerialPort>
    5.  
    6. using namespace std;
    7.  
    8. QSerialPort serial;
    9.  
    10.  
    11. int main (int argc, char *argv[])
    12. {
    13. QApplication app(argc, argv);
    14. serial.setPortName("/dev/ttyUSB0");
    15. serial.open(QIODevice::WriteOnly);
    16. serial.setBaudRate(QSerialPort::Baud19200);
    17. serial.setDataBits(QSerialPort::Data8);
    18. serial.setParity(QSerialPort::NoParity);
    19. serial.setStopBits(QSerialPort::OneStop);
    20. serial.setFlowControl(QSerialPort::NoFlowControl);
    21.  
    22.  
    23.  
    24. for (int i=0; i<100; i++)
    25. {
    26. serial.write("test");
    27. serial.flush();
    28. cout << i << endl;
    29. }
    30.  
    31. serial.close();
    32. return 0;
    33. }
    To copy to clipboard, switch view to plain text mode 

    And this is my .pro file:
    Qt Code:
    1. QT += core serialport widgets
    2.  
    3. QT -= gui
    4.  
    5. TARGET = Timer
    6. CONFIG += console
    7. CONFIG -= app_bundle
    8.  
    9. TEMPLATE = app
    10.  
    11.  
    12. SOURCES += main.cpp
    13. QMAKE_CXXFLAGS += -std=c++0x
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,531
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort not working, but shows no errors (Ubuntu)

    As I recall QSerialPort needs an event loop or the use of method waitForBytesWritten();

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.)

  5. #5
    Join Date
    Mar 2014
    Posts
    18
    Qt products
    Qt5

    Default 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!

Similar Threads

  1. Replies: 1
    Last Post: 1st December 2013, 20:27
  2. Replies: 7
    Last Post: 24th September 2012, 07:17
  3. Replies: 1
    Last Post: 8th August 2011, 15:04
  4. Getting linker errors trying to build formerly working programs under 4.7.1
    By MattPhillips in forum Installation and Deployment
    Replies: 6
    Last Post: 26th February 2011, 21:48
  5. Working with MYSQL in ubuntu
    By zero-n in forum Newbie
    Replies: 1
    Last Post: 26th July 2010, 21:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.