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 can i pass characters into Qserialport: write() instead of qbytearray
Forum Updated to NodeBB v4.3 + New Features

how can i pass characters into Qserialport: write() instead of qbytearray

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 283 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.
  • D Offline
    D Offline
    DiaaQTdev
    wrote on last edited by
    #1

    Hello, i was wondering how Qserialport work... i have read that it can takes only QbyteArray in write mode and returns only Qbytearray in read mode => is converting what read function have returned into the variable i am expecting will return the correct data?

    For example, i have in my other end a device that is configured to read only raw byte values, and writes also only byte values(like 0x12), how do i pass to write function in my QT app a value like 0xDD while the microcontroller reads it as a byte value?

    JonBJ 1 Reply Last reply
    0
    • D DiaaQTdev

      Hello, i was wondering how Qserialport work... i have read that it can takes only QbyteArray in write mode and returns only Qbytearray in read mode => is converting what read function have returned into the variable i am expecting will return the correct data?

      For example, i have in my other end a device that is configured to read only raw byte values, and writes also only byte values(like 0x12), how do i pass to write function in my QT app a value like 0xDD while the microcontroller reads it as a byte value?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @DiaaQTdev
      I think you are getting yourself mixed up. "QByteArray" and your "raw bytes" are the same thing. You should send & receive bytes. When you talk about "byte values(like 0x12)", I think/presume that 0x12 is something a debugger or viewer is showing to you, human-readable. I would assume you will actually send/receive it as a byte with value 18/0x12.

      1 Reply Last reply
      2
      • D Offline
        D Offline
        DiaaQTdev
        wrote on last edited by
        #3

        yes i understand your input on this. however, i have an edit line that i give the control to the user to write to the device. then if he write something like 0xDD. how, it is understood by QT as only a byte and not characters? i hope you can see my point on this. for sure, i don't understand how it works and i appreciate your time on explaining a little bit how data is read between the two ends as expected to be read. thank you !

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you have to convert the string0xDD to a byte/char with the value 0xDD and send this to your device. See for example https://doc.qt.io/qt-5/qbytearray.html#fromHex

          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
          3

          • Login

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