Results 1 to 7 of 7

Thread: Definitive serial library

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Definitive serial library

    I add this method to query available ports name, on both Windows and GNU\Linux

    Qt Code:
    1. #ifdef _TTY_POSIX_
    2. #include <QDir>
    3. #endif
    4.  
    5.  
    6. const int MAX_COM_PORT = 20;
    7.  
    8. // Query available SerialPort name
    9. QStringList MySerialPort::availablePortsName()
    10. {
    11. QextSerialPort testPort;
    12. testPort.setBaudRate(BAUD115200);
    13. testPort.setFlowControl(FLOW_OFF);
    14. testPort.setParity(PAR_NONE);
    15. testPort.setDataBits(DATA_8);
    16. testPort.setStopBits(STOP_1);
    17.  
    18. QStringList portsName;
    19. QString testPortName;
    20.  
    21. #ifdef _TTY_WIN_
    22. for (i=1; i<MAX_COM_PORT; i++)
    23. {
    24. testPortName = QString("COM%1").arg(i)
    25. testPort.setPortName(testPortName);
    26. if (testPort.open(QIODevice::ReadWrite))
    27. {
    28. portsName.append(testPortName);
    29. testPort.close();
    30. }
    31.  
    32. }
    33. #else // _TTY_POSIX_
    34. QDir dir("/dev");
    35. QStringList filters;
    36. filters << "ttyS*" << "ttyUSB*";
    37. dir.setNameFilters(filters);
    38. dir.setFilter(QDir::Files | QDir::System);
    39. QFileInfoList list = dir.entryInfoList();
    40. for (int i=0; i< list.size(); i++)
    41. {
    42. portsName.append(list.at(i).canonicalFilePath ());
    43. }
    44. #endif
    45.  
    46. return portsName;
    47. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2009
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Definitive serial library

    Thank you very much PaceyIV, I'll play with you class!
    It's a pity that QT4 doesn't have a built-in serial class, I can't understand why.

    In this way, everybody should reinvent the wheel... And there are many people (like me) who aren't so skilled to implement the library themselves.

    Marco

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

    Default Re: Definitive serial library

    There is a big chance a serial class from Qt Extended will make it into desktop Qt.

    http://doc.qtsoftware.com/qtextended...liodevice.html
    http://doc.qtsoftware.com/qtextended...erialport.html
    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.


Similar Threads

  1. Extending a plugin in a static library
    By ultim8 in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2010, 15:10
  2. plugin in a library
    By alisami in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2008, 17:21
  3. C++ Library for serial communication
    By dec0ding in forum General Programming
    Replies: 7
    Last Post: 8th July 2007, 18:18
  4. Replies: 1
    Last Post: 5th March 2007, 20:50
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.