QserialPort and QTcpSocket, led to a difference in the QByteArray sent through them
When sending 2 Bytes (a QByteArray) through a QTcpSocket, using the methods write(QByteArray) and readAll.
In the write side, the debugger shows the values:
Code:
-21 / 235
-112 / 144
In the read side, the debugger shows the same values, as expected.
But When the same Bytes are sent through the QSerialPort, using the methods write(QByteArray) and readAll, a difference is noted.
In the write side, the debugger shows the values as above.
And in the read side, it shows:
Why? How to convert from to
Code:
-21 / 235
-112 / 144
?
Thanks for the attention
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
235 - 128 == 107
144 - 128 == 16
My guess that your serial port is configured for 7 data bits, or the receiving software is, so the most significant bit (128) is being dropped.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
In case of the serial, it was noted that when writing what is read is .
Why can that happen?
A QByteArray is being used to write/read.
Thanks for the attention.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
The byte you send has the most significant bit set, and what you receive does not.
Code:
240 = 11110000 in binary
112 = 01110000 in binary
Have you eliminated the possibility that your serial data channel is configured for 7 data bits?
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
Hi ChrisW67,
The serial port is configured with
Code:
setDataBits(QSerialPort::Data8)
, but actually I'm not sure of which variable to verify in the debugger in order to confirm. May be ByteSize, under currentDcb, d_ptr? The value of ByteSize is 7.
Emulated serial ports are being utilized, could the issue be related to the emulator? The software being used is Virtual Serial Port Kit version 5.4.1 from FabulaTech (www.virtual-serial-port.com). Alternatively the Virtual Serial Ports Emulator 0.938.4.846 from Eterlogic (www.eterlogic.com) was used and it presents a different behavior.
It shows the exact same data which is sent, as expected.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
Check returns value from
Code:
setDataBits(QSerialPort::Data8)
at successful should be "true".
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
Is true.
Thank you kuzulis.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
It is strange. Give a code where you configure and open port.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
Code:
SettingsDialog::Settings s = settingsDialog->settings();
serial->setPortName(s.name);
if (!serial->setBaudRate(s.baudRate)
&& serial->setDataBits(s.dataBits)
&& serial->setParity(s.parity)
&& serial->setStopBits(s.stopBits)
&& serial->setFlowControl(s.flowControl))
return; // Failed
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
Please replace part of code to:
Code:
bool success
= serial
->open
(QIODevice::ReadWrite) && serial->setBaudRate(s.baudRate)
&& serial->setDataBits(s.dataBits)
&& serial->setParity(s.parity)
&& serial->setStopBits(s.stopBits)
&& serial->setFlowControl(s.flowControl);
if (!success ) {
return; // Failed
}
and check now.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
Still true.
Thank you kuzulis.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
In this case, check the correctness of installation of databits in DCB in debugger after setDataBits() call.
Re: QserialPort and QTcpSocket, led to a difference in the QByteArray sent through th
My fault! Everything is working now. May be a full rebuild/make was required to effectively apply the setDataBits.
Sorry.