Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Sending HEX data over Bluetooth (Android)
Forum Updated to NodeBB v4.3 + New Features

Sending HEX data over Bluetooth (Android)

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 3 Posters 683 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ahsan737A Offline
    ahsan737A Offline
    ahsan737
    wrote on last edited by ahsan737
    #1

    Greetings,
    I am trying to send the following Hex string via Bluetooth

    00 02 1b 53 90
    

    and I have tried the following method to do that

        QByteArray hexString;
    
        hexString.append(QByteArray::number(00, 16));
        hexString.append(QByteArray::number(02, 16));
        hexString.append(QByteArray::number(27, 16));
        hexString.append(QByteArray::number(83, 16));
        hexString.append(QByteArray::number(144, 16));
    
        server->sendMessage(hexString);
    

    but whenever I send it then the app gets closed unexpectedly.

    The debug mode shows the following info:
    HEX.JPG

    How can I accomplish it?
    Looking forward to a kind response.

    jsulmJ 1 Reply Last reply
    0
    • ahsan737A ahsan737

      Greetings,
      I am trying to send the following Hex string via Bluetooth

      00 02 1b 53 90
      

      and I have tried the following method to do that

          QByteArray hexString;
      
          hexString.append(QByteArray::number(00, 16));
          hexString.append(QByteArray::number(02, 16));
          hexString.append(QByteArray::number(27, 16));
          hexString.append(QByteArray::number(83, 16));
          hexString.append(QByteArray::number(144, 16));
      
          server->sendMessage(hexString);
      

      but whenever I send it then the app gets closed unexpectedly.

      The debug mode shows the following info:
      HEX.JPG

      How can I accomplish it?
      Looking forward to a kind response.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ahsan737 Is server a valid pointer?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      ahsan737A 1 Reply Last reply
      0
      • KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by KroMignon
        #3

        @ahsan737 said in Sending HEX data over Bluetooth (Android):

        Greetings,
        I am trying to send the following Hex string via Bluetooth
        00 02 1b 53 90

        and I have tried the following method to do that
        QByteArray hexString;

        hexString.append(QByteArray::number(00, 16));
        hexString.append(QByteArray::number(02, 16));
        hexString.append(QByteArray::number(27, 16));
        hexString.append(QByteArray::number(83, 16));
        hexString.append(QByteArray::number(144, 16));
        
        server->sendMessage(hexString);
        

        As QByteArray::number() documentation says, this will return a string:

        QByteArray::number(144, 16) ==> returns a string with "90"

        This is not what you want to have, try this:

            QByteArray hexString;
        
            hexString.append(quint8(0));
            hexString.append(quint8(2));
            hexString.append(quint8(27));
            hexString.append(quint8(83));
            hexString.append(quint8(144));
        
            server->sendMessage(hexString);
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        3
        • jsulmJ jsulm

          @ahsan737 Is server a valid pointer?

          ahsan737A Offline
          ahsan737A Offline
          ahsan737
          wrote on last edited by
          #4

          @KroMignon
          @jsulm Thanks for your kind suggestions. the program crash was because of the invalid pointer. I've fixed that and then the following command did the rest of work

              QByteArray hexString= QByteArray::fromHex("00021b5390");
              socket->write(hexString);
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved