Results 1 to 5 of 5

Thread: qextserialport taking value 0 as null ?

  1. #1
    Join Date
    Mar 2008
    Posts
    46
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default qextserialport taking value 0 as null ?

    Hi friends i am using qextserialport for RS232 communication between a targetboard and a PC. Now i have a serious issue which i am not able to solve. I am receiving data from the target board every thing is fine but when i receive the value " 0x00 " I get null, i am not able to receive it
    as it is. When i receive it the byte coming after 0 is taken as a new frame, example - i receive a single frame which is --> 0x04,0x08,0x81,0x00,0x89,0x78 . I get it as 0x04,0x08,0x81 as one frame and 0x89,0x78 as another frame. I wanted this whole thing as a single frame.
    When i receive 0x00 i get it as Null. But i wanted the 0x00 to be received as any other hex value.
    This is the code i am using to receive.
    Qt Code:
    1. char buff[2];
    2. int numBytes;
    3. numBytes = port->bytesAvailable();
    4. int i= port->read(buff, numBytes);
    5. if (i!= -1)
    6. buff[i] = '\0';
    7. else
    8. buff[0] = '\0';
    9. QByteArray msg = buff;
    10. textBrowser->append(msg.toHex());
    To copy to clipboard, switch view to plain text mode 

    Help me solve this problem. !!

    Thank You

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qextserialport taking value 0 as null ?

    What's the difference between NULL and 0x00?

    You have
    Qt Code:
    1. char buff[2];
    To copy to clipboard, switch view to plain text mode 
    and then you read some unknown number of characters. Are you sure there are only two to read?

    Are you sure, that all the characters (whole frame) are read before you use QTextBrowser::append() ? If not, you'll see some characters in new line every time you run this code.
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  3. #3
    Join Date
    Mar 2008
    Posts
    46
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qextserialport taking value 0 as null ?

    Hi

    What's the difference between NULL and 0x00?
    For me in my program null means nothing no value, But 0x00 is taken as null i din't want that happen because i have some service request with 0x00.

    char buff[2];
    Sorry that was a mistake , I changed it to 1024 but forgot to change it while i posted it here.

    Hey so is there any way i can take 0x00 as a normal hex number. Actually i receive this frame from the target board. I send a request frame in response to it the target board sends back a frame which may have 0x00, and if 0x00 is received the frame is broken and the hex values after 0x00 are taken has a second frame. How can i avoid this.


    Thank You.

  4. #4
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qextserialport taking value 0 as null ?

    Instead of this
    Qt Code:
    1. QByteArray msg = buff;
    To copy to clipboard, switch view to plain text mode 
    try
    Qt Code:
    1. QByteArray msg = QByteArray::fromRawData(buff,numBytes);
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QByteArray msg = port->read(numBytes);
    To copy to clipboard, switch view to plain text mode 

    Sorry, i think i din't read your post carefully last time
    Last edited by calhal; 11th August 2008 at 07:49. Reason: Forgot something
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  5. #5
    Join Date
    Mar 2008
    Posts
    46
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: qextserialport taking value 0 as null ?

    Hey thanks for the help it worked. !!!

    I changed it to

    QByteArray msg = QByteArray::fromRawData(buff,numBytes);
    and now i am able to even receive zeros . Thank You again friend.



    Cheers
    Dheeraj

Similar Threads

  1. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18

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.