Results 1 to 6 of 6

Thread: Assigning quint16_t to QByteArray while sending serial data frame from PC to device

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2021
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Assigning quint16_t to QByteArray while sending serial data frame from PC to device

    Hi,

    My structure contains a variable of type quint16_t and before sending to a device through serial port, I am appending it to a QByteArray. As QByteArray holds byte, I see only one byte is sent. Actually I want len field should hold 2 bytes.

    Qt Code:
    1. typedef struct x_hdr
    2. {
    3. ....
    4. quint16_t len;
    5. }x;
    6.  
    7.  
    8. void tx_msg_fun(QByteArray *tx_msg)
    9. {
    10. tx_msg->append(sizeof(x));
    11. }
    To copy to clipboard, switch view to plain text mode 

    serial data frame is : SOF (1 byte)| seq (1 byte) | len (2 bytes) [holds length of data] | payload (n bytes)| chksum (2 bytes) | eof (1 byte)

    When I send this, only one byte is allocated for len & chksum field.
    How can append 2 bytes in the serial frame. Could someone help me on this ?

    Best Regards,
    Anita
    Last edited by d_stranz; 21st January 2021 at 20:40. Reason: missing [code] tags

Similar Threads

  1. sending data in hex with QByteArray
    By QJak in forum Newbie
    Replies: 3
    Last Post: 17th April 2018, 16:31
  2. Sending serial data over ethernet
    By awpitt13 in forum Newbie
    Replies: 2
    Last Post: 27th February 2017, 13:06
  3. Problem sending data over to serial port
    By hovuquocan1997 in forum Qt Programming
    Replies: 6
    Last Post: 28th July 2015, 17:49
  4. How to interrupt serial port sending?
    By redkit_redkit in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2014, 12:58
  5. Replies: 1
    Last Post: 5th December 2013, 06:46

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.