Results 1 to 3 of 3

Thread: QtSerialPort synchronous approach

  1. #1
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QtSerialPort synchronous approach

    Hi!
    i'm trying to communicate some device that have been programmed myself to PC. Just a simple one to test QtSerialPort. In terminal example on QtSerialPort's help its work fine.
    Here is the reading result :
    308
    307
    309
    308
    .
    .
    .

    But when i write my code using synchronous approach, the reading is terrible. Here is the code :
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QtDebug>
    3. #include <QtAddOnSerialPort/serialport.h>
    4.  
    5. QT_USE_NAMESPACE_SERIALPORT
    6.  
    7. void setup();
    8. SerialPort serial;
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. serial.setPort("COM20");
    13. serial.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
    14. setup();
    15.  
    16. QCoreApplication a(argc, argv);
    17.  
    18. //here is the problem
    19. while (serial.waitForReadyRead(100)) {
    20. qDebug() << serial.read(8);
    21. }
    22.  
    23. return a.exec();
    24. }
    25.  
    26. void setup()
    27. {
    28. serial.setRate(SerialPort::Rate9600);
    29. // serial.setBaudRate(AbstractSerial::BaudRate9600);
    30. serial.setDataBits(SerialPort::Data8);
    31. serial.setParity(SerialPort::NoParity);
    32. serial.setStopBits(SerialPort::OneStop);
    33. serial.setFlowControl(SerialPort::NoFlowControl);
    34. }
    To copy to clipboard, switch view to plain text mode 

    and the result :
    "308"
    "307"
    "308"
    "3"
    "0"
    "9"
    "
    "
    "3"
    "0"
    "7"
    "
    "3"
    "0"
    "9"
    .
    .

    Well previusly i using QSerialDevice for Serial Communication its work fine with simple reading like that. Until i use it for multithreading, it mostly crash all over time. Then i use QtSerialPort for multithreading its work fine until i found the reading is bad. Is there a way to solve that problem?

  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: QtSerialPort synchronous approach

    What exactly do not like? That received an one by one byte?

    UPD: Is not recommended to use synchronous reading, because it is not tested.
    Also expected to implement a big change of the internal structure of the library.

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

    Default Re: QtSerialPort synchronous approach

    But all is OK. Terminal is writing to screen received bytes one by one. Yours program reads a few bytes from COM buffer and writes it to screen with qDebug which adds new line. It is all.

Similar Threads

  1. Adding QtSerialPort as a library -
    By HSPalm in forum Newbie
    Replies: 14
    Last Post: 26th June 2014, 16:16
  2. Replies: 4
    Last Post: 24th July 2012, 10:31
  3. cannot build qtserialport
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2011, 05:56
  4. gdb error 'Unavailable synchronous data'
    By glafauci in forum Qt Programming
    Replies: 0
    Last Post: 6th August 2011, 11:37
  5. Synchronous QFtp?
    By aarpon in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2009, 09:28

Tags for this Thread

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.