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. How to send data other than string through serial
QtWS25 Last Chance

How to send data other than string through serial

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • R Offline
    R Offline
    rvrv
    wrote on last edited by
    #1

    Hi everyone,
    I am programming in Qt and I would like to send data other than string through the serial port. For example: using the YAT software, it is necessary to use the command \d(number) to send decimal number or \h(number) to send a hexadecimal number. How would be it in Qt? Is there a way of doing it?
    Tks in advance,

    K 1 Reply Last reply
    1
    • R rvrv

      Hi everyone,
      I am programming in Qt and I would like to send data other than string through the serial port. For example: using the YAT software, it is necessary to use the command \d(number) to send decimal number or \h(number) to send a hexadecimal number. How would be it in Qt? Is there a way of doing it?
      Tks in advance,

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @rvrv

      Hi and welcome to devent

      Why should this not possible?
      You basically give a pointer to writeData() and tell it the number of bytes to send. Either you pack your binary number into a binary stream and send off this, or you can send also directly.

      int i = 15;
      serial->writeData (&i, sizeof (int) );
      

      Probably you have to cast the pointer.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rvrv
        wrote on last edited by
        #3

        @koahnig

        Thanks for your help!

        I have implemented the mentioned code, but it still not working. The following message is given:
        " error: no matching function for call to 'QSerialPort::write(int*, unsigned int)'
        serial->write(&i, sizeof(8));"

        K 1 Reply Last reply
        0
        • R rvrv

          @koahnig

          Thanks for your help!

          I have implemented the mentioned code, but it still not working. The following message is given:
          " error: no matching function for call to 'QSerialPort::write(int*, unsigned int)'
          serial->write(&i, sizeof(8));"

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @rvrv

          int i = 15;
          serial->writeData ( (char *) &i, sizeof (int) );
          

          That is what I meant with "Probably you have to cast the pointer."
          You might want tohave also a look on to QDataStream . There you can store several values in teh buffer and send all at once.

          Vote the answer(s) that helped you to solve your issue(s)

          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