Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. send uint8_t using serialPort.writeData
Forum Updated to NodeBB v4.3 + New Features

send uint8_t using serialPort.writeData

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 500 Views
  • 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.
  • A Offline
    A Offline
    Aeroplane123
    wrote on last edited by
    #1

    Hello,

    I am new to this forum. I have a problem when i am using serialPort.writeData i NEED to send data as uint8_t as this is what the receiver expects and I cannot change that at this point.

    When i try

      uint8_t cmd[3000];
    
        memcpy(cmd, "x", 4);
        cmd[4] =  CMD_SENDING_FIRMWARE_PAGE & 0xFF;
        cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
        cmd[6] = (uint8_t)(payLoadSize & 0xFF);
        cmd[7] = (uint8_t)(payLoadSize >>8);
        cmd[8] = pageId;
    
        memcpy(&cmd[9], data, pageSize);`
        cmd[8 + payLoadSize] = CalcChecksum(cmd, cmdSize);
    
        serialPort.write(cmd, cmdSize + 1);
    

    I get the error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]

    
    Can anyone please help? The data must be sent as uint8_t
    
    Thanks
    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • A Aeroplane123

      Hello,

      I am new to this forum. I have a problem when i am using serialPort.writeData i NEED to send data as uint8_t as this is what the receiver expects and I cannot change that at this point.

      When i try

        uint8_t cmd[3000];
      
          memcpy(cmd, "x", 4);
          cmd[4] =  CMD_SENDING_FIRMWARE_PAGE & 0xFF;
          cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
          cmd[6] = (uint8_t)(payLoadSize & 0xFF);
          cmd[7] = (uint8_t)(payLoadSize >>8);
          cmd[8] = pageId;
      
          memcpy(&cmd[9], data, pageSize);`
          cmd[8 + payLoadSize] = CalcChecksum(cmd, cmdSize);
      
          serialPort.write(cmd, cmdSize + 1);
      

      I get the error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]

      
      Can anyone please help? The data must be sent as uint8_t
      
      Thanks
      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Aeroplane123 You have to reinterpret_cast<> it to a const char* when passing it to QSerialPort::write()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Aeroplane123
        wrote on last edited by
        #3

        Will this keep the data the same for the receiving end?

        jsulmJ A 2 Replies Last reply
        0
        • A Aeroplane123

          Will this keep the data the same for the receiving end?

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

          @Aeroplane123 said in send uint8_t using serialPort.writeData:

          Will this keep the data the same for the receiving end?

          Yes, a cast does not change the data, it just tells the compiler how to treat the data.

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

          1 Reply Last reply
          1
          • A Aeroplane123

            Hello,

            I am new to this forum. I have a problem when i am using serialPort.writeData i NEED to send data as uint8_t as this is what the receiver expects and I cannot change that at this point.

            When i try

              uint8_t cmd[3000];
            
                memcpy(cmd, "x", 4);
                cmd[4] =  CMD_SENDING_FIRMWARE_PAGE & 0xFF;
                cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
                cmd[6] = (uint8_t)(payLoadSize & 0xFF);
                cmd[7] = (uint8_t)(payLoadSize >>8);
                cmd[8] = pageId;
            
                memcpy(&cmd[9], data, pageSize);`
                cmd[8 + payLoadSize] = CalcChecksum(cmd, cmdSize);
            
                serialPort.write(cmd, cmdSize + 1);
            

            I get the error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]

            
            Can anyone please help? The data must be sent as uint8_t
            
            Thanks
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Aeroplane123 said in send uint8_t using serialPort.writeData:

            cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
            

            As a minor point/aside, this is almost certainly incorrect/not what you intend....

            1 Reply Last reply
            2
            • A Aeroplane123

              Will this keep the data the same for the receiving end?

              A Offline
              A Offline
              Aeroplane123
              wrote on last edited by
              #6
              This post is deleted!
              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