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. Does Qt serial port supports the QbitArray . I need to transmit the data in bit form. how am i suppose to send .

Does Qt serial port supports the QbitArray . I need to transmit the data in bit form. how am i suppose to send .

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.2k 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.
  • AnilReddyA Offline
    AnilReddyA Offline
    AnilReddy
    wrote on last edited by
    #1

    Does Qt serial port supports the QbitArray . I need to transmit the data in bit form. how am i suppose to transit the 8-bit data to control robotic arm.

    ? 1 Reply Last reply
    0
    • AnilReddyA AnilReddy

      Does Qt serial port supports the QbitArray . I need to transmit the data in bit form. how am i suppose to transit the 8-bit data to control robotic arm.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      @AnilReddy said:

      how am i suppose to transit the 8-bit data

      If you need to write only a single byte:

      const char c = 0x23;
      port.write(&c, 1);
      

      Otherwise:

      const QByteArray ba("Hello");
      port.write(ba);
      

      Bit manipulation is provided by the language:

      c |= (1<<4); // set bit #4
      c &= ~(1<<2); // clear bit #2
      
      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        No QSerialPort doesn't support that. However it's not complicated to send a QBitArray. Something like:

        QBuffer buffer;
        buffer.open(QIODevice::WriteOnly);
        QDataStream stream(&buffer);
        stream << bitArray;
        
        serialPort.write(buffer.buffer());
        

        should do the job.

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

        C 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          No QSerialPort doesn't support that. However it's not complicated to send a QBitArray. Something like:

          QBuffer buffer;
          buffer.open(QIODevice::WriteOnly);
          QDataStream stream(&buffer);
          stream << bitArray;
          
          serialPort.write(buffer.buffer());
          

          should do the job.

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @SGaist This will write a four-byte number representing the bit count followed by the bits according to http://doc.qt.io/qt-5/datastreamformat.html

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

            @ChrisW67 Good point ! That's indeed something to take into account when reading the data on the other side of the connection.

            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

            • Login

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