Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

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

    I am trying to read binary data from a serial port with qextserialport (getChar(), readAll(), readLine()) but the problem is that every 0x00 character are neglected by the read function. For example, instead of reading: "0x02 0x03 0x1a 0x00 0x00 0x1a 0x1b", i get "0x02 0x03 0x1a 0x1a 0x1b". I tried every reading function (getChar(), readAll(), readLine()). And i get the same problem. I tried to look only at the number of Bytes which are readed and i get every time the expected total - # of 0x00. Which means that my problem do not comes from the conversion of the QByteArray in Hex. I don't know what to do now and i would be very happy if someone could help me!!!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    I don't know what to do
    post code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #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 17: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, 12:09
  2. send binary file over serial port with QSerialDevice
    By ilpaso in forum Qt Programming
    Replies: 30
    Last Post: 13th December 2010, 13:08
  3. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 15:59
  4. Problem in reading port using QextSerialPort
    By cutie.monkey in forum Qt Programming
    Replies: 6
    Last Post: 2nd July 2009, 03:07
  5. Replies: 1
    Last Post: 1st July 2009, 01: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.