Unsolved 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 transit the 8-bit data to control robotic arm.
-
@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
-
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.
-
@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
-
@ChrisW67 Good point ! That's indeed something to take into account when reading the data on the other side of the connection.