Results 1 to 4 of 4

Thread: COM port reading with Qextserialport is creating problem:

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    15
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default COM port reading with Qextserialport is creating problem:

    I am new to QT programming. Serial communication application is being developed. For this Qextserialport classes are successfully conformed with QT classes and is being utilised for developing application. writing to port and Reading from port are incorporated in same application. Am able to write all the bytes in a msgpckt to port but reading from that port is creating the problem. It can only read one byte when read function of qextserialport is called. First byte is read properly rest its showing junk values.
    How to debug it??? Is the method am following is correct??? here is the piece of code



    Writing to port (COM1) : here is the code
    ///////////////////////////////////

    Qt Code:
    1. openflag = port ->isOpen();
    2. if(openflag)
    3. {
    4. int i = port->write((const char *) &Hmi_statusMsg, sizeof(Hmi_statusMsg));
    5.  
    6. qDebug("Transmitted bytes =%d",i);
    7. }
    8.  
    9. else
    10. {
    11. qDebug("COM1 port is not open");
    12. }
    To copy to clipboard, switch view to plain text mode 

    //////////////////////////////////////End code ///
    Hmi_statusMsg in above code is Msg packet, each feilds are of type unsigned char, having data : MsgHdr = 0x75
    Data1 = 0x08
    Data2 = 0x02
    Data3 = 0x40
    Data4 = 0x10
    chksum = 0xcd


    Reading from port and displaying it on text-edit box: here is the code

    Qt Code:
    1. char buff [1024];
    2. int numBytes;
    3.  
    4. numBytes = port->bytesAvailable();
    5. if(numBytes > 0)
    6. {
    7.  
    8. int i = port->read(buff, numBytes);
    9.  
    10. buff[i] = '\0';
    11. QString msg = (QString) buff;
    12.  
    13. received_msg->append(msg);
    14. received_msg->ensureCursorVisible();
    15. qDebug("bytes available: %d", numBytes);
    16. qDebug("received: %d", i);
    17.  
    18. ui->textEdit->setText(msg);
    19.  
    20. }
    21.  
    22. else
    23. {
    24. qDebug("bytes not available: %d", numBytes);
    25. }
    To copy to clipboard, switch view to plain text mode 

    /////////////////////////////////////////////////////




    Transmitter output::::

    Status Msg header = 75
    Status Msg Data1 = 8
    Status Msg Data2 = 2
    Status Msg Data3 = 40
    Status Msg Data4 = 10
    Status Msg chksum = cd
    Transmitted bytes =6



    Receiver Output::::


    bytes available: 6
    received: 6
    RCVD Status Msg header = u
    RCVD Status Msg Data1 = 
    RCVD Status Msg Data2 = 
    RCVD Status Msg Data3 = @
    RCVD Status Msg Data4 = 
    RCVD Status Msg chksum = Í



    First byte is displayed in ASCII, but remaining all are junk values...

    Expecting guidance,
    Thanks in advance
    Last edited by high_flyer; 27th April 2011 at 11:21. Reason: code tags

Similar Threads

  1. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 14:59
  2. Problem in reading port using QextSerialPort
    By cutie.monkey in forum Qt Programming
    Replies: 6
    Last Post: 2nd July 2009, 02:07
  3. Replies: 1
    Last Post: 1st July 2009, 00:36
  4. QextSerialPort with QTimer approch for reading
    By PaceyIV in forum Qt Programming
    Replies: 1
    Last Post: 18th May 2009, 14:33
  5. Replies: 7
    Last Post: 29th August 2008, 10:24

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.