Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    4
    5
    989
    Loading More Posts
    • 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.
    • AnilReddy
      AnilReddy last edited by

      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 Reply Quote 0
      • ?
        A Former User @AnilReddy last edited by A Former User

        @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 Reply Quote 1
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 1
          • C
            ChrisW67 @SGaist last edited by

            @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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              @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 Reply Quote 0
              • First post
                Last post