Results 1 to 6 of 6

Thread: Need help setting up a serial port connection

  1. #1
    Join Date
    Jun 2012
    Posts
    6
    Qt products
    Qt4

    Default Need help setting up a serial port connection

    Hello, I am trying to wrtie a program in Ubuntu where, throught the console, I can read and write a serial port. So I have started using the qextserialport library. I found code online and tried to emulate it to make a simple test to see if I can get the program to merely connect to the serial port. But alas my program does not seem to be connecting. And I am at a loss for why it won't open the port. Here is my code

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <3rdparty/qextserialport/src/qextserialport.h>
    3. #include <iostream>
    4. #include <qiodevice.h>
    5. using namespace std;
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9. const char data[]= "e";
    10. QextSerialPort * port = new QextSerialPort("/dev/ttyUSB0");
    11. port->setBaudRate(BAUD115200);
    12. port->setFlowControl(FLOW_OFF);
    13. port->setParity(PAR_NONE);
    14. port->setDataBits(DATA_8);
    15. port->setStopBits(STOP_1);
    16. port->setTimeout(10);
    17. bool res = false;
    18. res = port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
    19.  
    20. if(res)
    21. {
    22. cout << "Opened" << endl;
    23. char i = port->write(data);
    24. }
    25. else
    26. {
    27. cout << "Failed to connect" << endl;
    28. }
    29. return a.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    The console that is opened always displays "Failed to connect"
    Can anyone see any very obvious erros?

    Thanks
    -Jvwlong

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need help setting up a serial port connection

    Do You have rigths to use /dev/ttyUSB0 ?

  3. #3
    Join Date
    Jun 2012
    Posts
    6
    Qt products
    Qt4

    Default Re: Need help setting up a serial port connection

    I believe I do? How would I check if I have permission or not?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need help setting up a serial port connection

    Quote Originally Posted by jvwlong View Post
    I believe I do? How would I check if I have permission or not?
    From command line :

    ls -l /dev/ttyUSB0

    and watch at screen.

  5. #5
    Join Date
    Jun 2012
    Posts
    6
    Qt products
    Qt4

    Default Re: Need help setting up a serial port connection

    This is the output from that command
    "crw-rw---- 1 root dialout 188, 0 Jul 2 09:30 /dev/ttyUSB0"

  6. #6
    Join Date
    Jun 2012
    Posts
    6
    Qt products
    Qt4

    Default Re: Need help setting up a serial port connection

    Solved. I just needed to be added to the dialout group.

Similar Threads

  1. Serial port performance
    By marcvanriet in forum General Programming
    Replies: 1
    Last Post: 2nd January 2012, 12:40
  2. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 02:38
  3. serial port issues
    By jhowland in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2009, 13:38
  4. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 02:05
  5. serial port and USB communication
    By shamik in forum Qt Programming
    Replies: 5
    Last Post: 4th December 2006, 10:40

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
  •  
Qt is a trademark of The Qt Company.