Solved Problem transmitting '0x20' via serial port
-
QSerialPort mSerial;
QByteArray data;...
mSerial.write( data.data(), data.size() );
…Hi.
I don't know!
I've never problem to send data with this code, try it. -
@armorex said in Problem transmitting '0x20' via serial port:
I have tried to use QByteArray::toHex as well but that doesn't work too.
What exactly do you mean by this? It sounds like you are suggesting
QByteArray::toHex()
doesn't cope with space character in the bytes?? -
You can use any of serial port sniffer to see a real output data flow to the serial port driver. Seems, you do something wrong, or, maybe, there are some noise on a line. You should not use serial communication without of CRC calculation.
-
@CP71 Ok i will try it and let you know
-
@kuzulis said in Problem transmitting '0x20' via serial port:
You can use any of serial port sniffer to see a real output data flow to the serial port driver. Seems, you do something wrong, or, maybe, there are some noise on a line. You should not use serial communication without of CRC calculation.
I have already included a screenshot of a file that was made by the logic analyzer. Which gets gets the output from a physical serial port. You can see that the top file does not contain 0x20. The bottom (original) file, however does. I have tired it multiple times with the same output which eliminates the possibility of noise
-
Hi @armorex,
99% surely the problem is in your code.
But please tell us, which operating system, compiler and Qt version you use.
I'd try to separate the problem in two parts:
- Make sure the file is read correctly. Check it before writing it to the serial port. BTW: How big is this file?
- Make sure the serial writing is done correctly. Start by writing a small buffer containing spaces and verify they are sent.
If I were you, I'd not use
waitForBytesWritten
. It is unrelyable anyway, as the data is still buffered in the OS or driver level when Qt's buffer get empty. A better handshake is to send ACKs from the bootloader when when (a chunk of/all) data arrived.Regards
-
@CP71 said in Problem transmitting '0x20' via serial port:
QSerialPort mSerial;
QByteArray data;...
mSerial.write( data.data(), data.size() );
…Hi.
I don't know!
I've never problem to send data with this code, try it.This worked! But now i don't understand why can't we use QByteArray directly and have to use data(). But at least it works now. Thanks!
-
@aha_1980 said in Problem transmitting '0x20' via serial port:
Hi @armorex,
99% surely the problem is in your code.
But please tell us, which operating system, compiler and Qt version you use.
I'd try to separate the problem in two parts:
- Make sure the file is read correctly. Check it before writing it to the serial port. BTW: How big is this file?
- Make sure the serial writing is done correctly. Start by writing a small buffer containing spaces and verify they are sent.
If I were you, I'd not use
waitForBytesWritten
. It is unrelyable anyway, as the data is still buffered in the OS or driver level when Qt's buffer get empty. A better handshake is to send ACKs from the bootloader when when (a chunk of/all) data arrived.Regards
I had to use the blocking function because it wasn't transmitting all the data. It would stop in the middle. The file is 36349 bytes.
-
You are welcome!
It is old code, so I don’t remember why I have used this way instead of .write( QbyteData ), maybe I have had same result! But I can’t say now because I don’t remember ;)I don’t know how .write() functions work at low level, but QByteData is unicode chars container. This call receives a no unicode chars. Maybe the difference is this.
-
I don’t know how .write() functions work at low level, but QByteData is unicode chars container.
No, that's wrong. QByteArray just holds Bytes without interpreting them.
So I really wonder why using the other write makes a difference.
Still the OP didn't answer my questions.
Regards
-
@aha_1980
Yes, sorry!
You are right, my mistake.
I don’t know why I was thinking at QChar :(