Results 1 to 4 of 4

Thread: sending data in hex with QByteArray

  1. #1
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows Android

    Default sending data in hex with QByteArray

    hi i want to send a pack with 3 bytes every time. is this ok?

    Qt Code:
    1. g.insert(0,0x22);
    2. g.insert(1,0x2e);
    3. g.insert(2,1000);
    4. serial.write(g);
    To copy to clipboard, switch view to plain text mode 

  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: sending data in hex with QByteArray

    is this ok?
    No.
    Qt Code:
    1. g.insert(2,1000);
    To copy to clipboard, switch view to plain text mode 

    1000 with this syntax is not hex but decimal, and 1000 is more than one byte. 1000 in hex is 0x3e8 (it spans over 2 bytes).

    So your protocol will have to accommodate sending values spanning over more than one byte.
    ==========================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. The following user says thank you to high_flyer for this useful post:

    QJak (16th April 2018)

  4. #3
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: sending data in hex with QByteArray

    thanks, you are right. if for that i write g.insert(2, 250), is it ok?
    then g (QByteArray) is prepare for sending?

  5. #4
    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: sending data in hex with QByteArray

    thanks, you are right. if for that i write g.insert(2, 250), is it ok?
    Depends what "Ok" means for you.
    250 is decimal not hex, but it still might be ok if the value is value you want (you can represent any of the values in any numerical base).
    But 250 is not 1000 so I don't know what is the consequence for your 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.

Similar Threads

  1. Sending data over QSerialPort
    By jvalerio in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2016, 16:40
  2. Sending sms and gprs data using Qt
    By malikSnisar in forum Newbie
    Replies: 8
    Last Post: 25th May 2011, 07:43
  3. SEnding data between forms
    By core_st in forum Newbie
    Replies: 1
    Last Post: 31st January 2011, 10:23
  4. Sending raw data using QextSerialPort [solved]
    By DrDonut in forum Qt Programming
    Replies: 1
    Last Post: 7th January 2009, 14:14
  5. sending data over signal
    By gyre in forum Newbie
    Replies: 1
    Last Post: 17th December 2007, 00:10

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.