Results 1 to 3 of 3

Thread: serial communication

  1. #1
    Join Date
    Oct 2008
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default serial communication

    Hi everybody. Iam working with serial communication , using qextserialport library on QT 4.4.3 intergrated with visual studio 2005.
    I have been able to successfully configure the library and try out an example QESPTA , which is able to recieve data from an embedded system to the computer running the QESPTA example.
    Iam able to recieve data when i click on the open and recieve buttons, my problem is that i want to continously recieve data as long as it is available on the port , not just by clicking the recieve buttom.

    I need some guidance.

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    You need to write either a thread that runs in the background and collects the data, or use a QTimer to periodically poll the serial port. The threaded version looks something like this:

    Qt Code:
    1. setupTheSerialPortJustLikeInQESPTA();
    2.  
    3. while (true)
    4. {
    5. receiveData();
    6. msleep(100);
    7. }
    8.  
    9. void receiveData()
    10. {
    11. // Check if there is any data to read.
    12. if (!port->bytesAvailable())
    13. return -1;
    14.  
    15. // Read as much data as you can from the port.
    16. bytesRead = port->read(receiveBuffer, qMin(port->bytesAvailable(), BUFFER_SIZE));
    17. }
    To copy to clipboard, switch view to plain text mode 

    With the QTimer solution you don't have an infinite loop with a sleep, but you call receiveData() with a timer instead.

    A blocking approach that tries to read from the port and waits until data arrives would be preferable, but I couldn't make that work because of a problem with waitForReadyRead().
    Last edited by Cruz; 13th February 2009 at 10:00. Reason: spelling error

  3. #3
    Join Date
    Oct 2008
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial communication

    Thanks , i will try it now and see how it works

Similar Threads

  1. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 02:38
  2. serial communication problem
    By Tavit in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2008, 12:56
  3. serial communication programming
    By jagadish in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 07:47
  4. C++ Library for serial communication
    By dec0ding in forum General Programming
    Replies: 7
    Last Post: 8th July 2007, 18:18
  5. How to transfer file through serial communication
    By shamik in forum Qt Programming
    Replies: 29
    Last Post: 29th May 2007, 10:22

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.