Results 1 to 7 of 7

Thread: Definitive serial library

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

    Default Definitive serial library

    Hello,

    I apologize if my English is not so good.
    I use QT4 to develop applications for Windows and Linux, in both desktop and embedded environments.

    I need use a lot of serial connections (often I have 4-5 serial devices connected) so I'm looking for a *reliable* and complete serial library. I don't understand why QT4 doesn't support serial communication natively, I think they are used a lot in embedded applications.

    Anyway, I'm playing with the Qextserial but it seems to me a bit buggy and it has many limitations.

    Please, may you suggest me a complete serial library that:

    * works under Windows and Linux,
    * uses signals to tell when data is ready to be read (with buffer thresholds)
    * has a working lineread() method
    * enumerates available ports under both Windows and Linux

    I'm asking too much? What do you embedded programmers use?

    Thanks

    Marco Trapanese
    Italy

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Definitive serial library

    See this topic:
    http://www.qtcentre.org/forum/f-qt-p...lue-21168.html

    Try the library.
    Add to the library all that you want.





    PS: but there is a bug.

    Example download: http://www.qtcentre.org/forum/attach...6&d=1242923390

  3. #3
    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

    Marco Trapanese asks for signal when there is data available. In your code there isn't this features.

    See this topic: http://www.qtcentre.org/forum/f-qt-p...ing-21063.html

    In the last post there is my class that use QextSerialPort. It implements 2 thread with the signal "dataReceived": it transports the byte available at the serial port. I also made a basic HyperTerminal to test it (It shows ad transmits data in Hexadecimal).

    * has a working lineread() method

    I don't implement this method: you can add this!

    * enumerates available ports under both Windows and Linux

    I don't know how to implement this features. In Linux I think I can scan for ttyS* file in /dev/ and maybe also ttyUSB*. I windows I don't know.


    Bye

  4. #4
    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 

  5. #5
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  7. #7
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Definitive serial library

    I use the code at http://www.teuniz.net/RS-232/

    It does not use signals but it does work with Linux and windows.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.