how can i pass characters into Qserialport: write() instead of qbytearray
-
Hello, i was wondering how Qserialport work... i have read that it can takes only QbyteArray in write mode and returns only Qbytearray in read mode => is converting what read function have returned into the variable i am expecting will return the correct data?
For example, i have in my other end a device that is configured to read only raw byte values, and writes also only byte values(like 0x12), how do i pass to write function in my QT app a value like 0xDD while the microcontroller reads it as a byte value?
-
@DiaaQTdev
I think you are getting yourself mixed up. "QByteArray" and your "raw bytes" are the same thing. You should send & receive bytes. When you talk about "byte values(like 0x12)", I think/presume that0x12
is something a debugger or viewer is showing to you, human-readable. I would assume you will actually send/receive it as a byte with value 18/0x12. -
yes i understand your input on this. however, i have an edit line that i give the control to the user to write to the device. then if he write something like 0xDD. how, it is understood by QT as only a byte and not characters? i hope you can see my point on this. for sure, i don't understand how it works and i appreciate your time on explaining a little bit how data is read between the two ends as expected to be read. thank you !
-
Then you have to convert the string
0xDD
to a byte/char with the value 0xDD and send this to your device. See for example https://doc.qt.io/qt-5/qbytearray.html#fromHex