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. [Solved] Qextserialport send ascii problem
QtWS25 Last Chance

[Solved] Qextserialport send ascii problem

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 3.9k 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.
  • M Offline
    M Offline
    Memphis
    wrote on last edited by
    #1

    Hello,
    I made an Qt application that send and received data from a board throught a serial port, but i have some problem with the sending.

    @QByteArray data4;
    data4[0] = 124;
    port->write(data4, data4.length());@

    The board receive the ASCII characters of the number "|" instead of the decimal value 124.
    If I convert the value in HEX like this

    @data4 = data4.toHex;@

    the sent value is right, 7C.
    How can I send decimal value?

    Thank you

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      You have to think in byte.
      124 (decimal) means 7c (hexadecimal) means | (see ascii table, in this case is a printable value).
      Always only one byte.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        You need to decide what to send. As already pointed out you are basically sending the byte representation of 124 which is binary and only one byte.

        If you would like to send it as three characters '1', '2' and '4' you have to convert the binary representation to ASCII characters first.

        E.g.
        @
        QString str = QString::number ( 124 );
        @

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Memphis
          wrote on last edited by
          #4

          I would like to send an integer through the port as the board's firmware is programmed to receive an integer and not a character or hexadecimal,

          @ QByteArray data4;
          data4[0] = 124;
          port->write(data4, data4.length());
          @

          but in this way the board receives only an ASCII character "|"

          Even if I perform a conversion of this type

          @ QString str = QString::number ( 124 );@

          the board continues to see ASCII characters and does not work

          Thank you

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            Hi,

            You might be misunderstanding something:

            124 == 7C == |

            These are three representations of the same value. Could you post the portion of the firmware that handles that ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Memphis
              wrote on last edited by
              #6

              Thank you very much, I solved thanks to your advice

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

                @Memphis

                Could you share the solution you found. I am facing the same problem and I couldn't solve it so far.
                Thanks,

                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