PDA

View Full Version : sending data in hex with QByteArray



QJak
15th April 2018, 14:03
hi i want to send a pack with 3 bytes every time. is this ok?



QByteArray g;
g.insert(0,0x22);
g.insert(1,0x2e);
g.insert(2,1000);
serial.write(g);

high_flyer
15th April 2018, 23:34
is this ok?
No.


g.insert(2,1000);


1000 with this syntax is not hex but decimal, and 1000 is more than one byte. 1000 in hex is 0x3e8 (it spans over 2 bytes).

So your protocol will have to accommodate sending values spanning over more than one byte.

QJak
16th April 2018, 06:05
thanks, you are right. if for that i write g.insert(2, 250), is it ok?
then g (QByteArray) is prepare for sending?

high_flyer
17th April 2018, 16:31
thanks, you are right. if for that i write g.insert(2, 250), is it ok?
Depends what "Ok" means for you.
250 is decimal not hex, but it still might be ok if the value is value you want (you can represent any of the values in any numerical base).
But 250 is not 1000 so I don't know what is the consequence for your code.