Results 1 to 5 of 5

Thread: Not reading the serial port data fully using QExserialports readyread of singal slot

  1. #1
    Join Date
    Jul 2012
    Location
    India
    Posts
    33
    Thanks
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Not reading the serial port data fully using QExserialports readyread of singal slot

    OS:Ubuntu 11
    QExtSerialport 1.2 beta


    I am creating an application to write an instruction to a device and receive its response from the device. I connected the readyread() singal to onReadyRead() slot. but sometime its getting only the partial data from the device to the onReadyRead() slot.

    I am writing *Read to device
    and getting
    *Read<Values>
    P=122
    C=0.33
    sometime I got only the partial result in my onReadyRead()

    I tried event driven and Polling methods.Still the issue exist.How I can completely read the device input in my onReadyRead().
    I checked this on putty software also. its working perfectly in there.

    my code sample is given below

    Qt Code:
    1. void Reader::Create()
    2. {
    3. PortSettings settings = {BAUD19200, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 20};
    4. port = new QextSerialPort(m_strPortName, settings, QextSerialPort::EventDriven);
    5.  
    6. timer = new QTimer(this);
    7. timer->setInterval(20);
    8.  
    9.  
    10.  
    11. connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
    12. connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));
    13.  
    14. if (!port->isOpen())
    15. {
    16. port->setPortName(m_strPortName);
    17. port->open(QIODevice::ReadWrite);
    18. }
    19. else {
    20. // port->close();
    21. }
    22.  
    23. if (port->isOpen() && port->queryMode() == QextSerialPort::Polling)
    24. timer->start();
    25. else
    26. timer->stop();
    27.  
    28. }
    29.  
    30. void Reader::onReadyRead()
    31. {
    32. if (port->bytesAvailable())
    33. {
    34. m_strData= port->readAll();
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Not reading the serial port data fully using QExserialports readyread of singal s

    Your slot will be called again when more data is available.
    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.


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

    Default Re: Not reading the serial port data fully using QExserialports readyread of singal s

    Remember that the slot can be called after the first byte of data.

  4. #4
    Join Date
    Jul 2012
    Location
    India
    Posts
    33
    Thanks
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Not reading the serial port data fully using QExserialports readyread of singal s

    How can I get the full data to a string with a single call.

    I want to read the full data to a string before next input to the serial device

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

    Default Re: Not reading the serial port data fully using QExserialports readyread of singal s

    Quote Originally Posted by arunkumaraymuo1 View Post
    How can I get the full data to a string with a single call.
    You can't. The speed of data transmission over the wire is finite.

    I want to read the full data to a string before next input to the serial device
    Aggregate incoming data in a buffer and once you detect(*) all of it has arrived, you can start processing it.

    *) how to do that depends on your application protocol
    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. Reading/writing a serial port through USB
    By jvwlong in forum Newbie
    Replies: 2
    Last Post: 28th June 2012, 11:09
  2. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 14:59
  3. Replies: 1
    Last Post: 1st July 2009, 00:37
  4. Replies: 1
    Last Post: 1st July 2009, 00:36
  5. Replies: 1
    Last Post: 3rd December 2008, 15:51

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.