Results 1 to 3 of 3

Thread: QExtSerialPort binary serial port reading ignoring or disregarding 0x00 null char.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QExtSerialPort binary serial port reading ignoring or disregarding 0x00 null char

    ok my code look like:


    /
    Qt Code:
    1. /serial port settings
    2. PortSettings ps;
    3. ps.BaudRate = 9600;
    4. ps.DataBits = DataBitsType(DB8);
    5. ps.Parity = ParityType(P_NONE);
    6. ps.StopBits = StopBitsType(SB1);
    7. ps.FlowControl = FlowType(FC_NONE);
    8.  
    9. //open serial port for writing and reading
    10. QextSerialPort port = new QextSerialPort("COM1", ps, QextSerialPort::Polling);
    11. port->open(QIODevice::ReadWrite);
    12.  
    13. //send a command (txbuf) to the gps
    14. port->setTimeout(200);
    15. port->write(txbuf, txlen);
    16.  
    17. // read the answer packet
    18. QByteArray binrx;
    19. binrx.resize(128);
    20. char* rxbuf = binrx.data();
    21. int rxlen = binrx.size();
    22.  
    23. port->setTimeout(200);
    24. // wait for the first character
    25. forever
    26. {
    27. if (! port->getChar(rxbuf))
    28. else
    29. {
    30. break;
    31. }
    32. }
    33.  
    34. // read until EOL
    35. port->setTimeout(200);
    36.  
    37. for (int i = 1; i < rxlen; i++)
    38. {
    39. if (! port->getChar(rxbuf+i))
    40. {
    41. binrx.resize(i);
    42. qDebug() << binrx.toHex();
    43. return;
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 

    With this code i get the received data without every 0x00 character. The function getChar() seems to ignore the incoming 0x00 characters. I get the same result by using port->readAll() or port->read(). I absolutely need the COMPLETE answer of my GPS which contains 0x00 characters. Thanks for the help!
    Last edited by high_flyer; 3rd July 2012 at 16:59. Reason: code tags

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. send binary file over serial port with QSerialDevice
    By ilpaso in forum Qt Programming
    Replies: 30
    Last Post: 13th December 2010, 12:08
  3. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 14:59
  4. Problem in reading port using QextSerialPort
    By cutie.monkey in forum Qt Programming
    Replies: 6
    Last Post: 2nd July 2009, 02:07
  5. Replies: 1
    Last Post: 1st July 2009, 00:36

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
  •  
Qt is a trademark of The Qt Company.