quint16 to QByteArray Conversion
Hello All,
I begin to work with Qt so sorry if the answer is easy for you.
I am working on a software which communicates with a device.
I use the QextSerialPort librairie and it is working fine.
In fact, it is working fine when I send to my device a constant frame.
Code:
/* Erasing Command */
static const char eraseCmd[] = {0x11, 0x02, 0x00, 0x00, 0x00, 0x02 };
But it is not working when I want to add in the frame a counter as an idFrame;
For example, if I send the 499th frame, I would like to send :
{beginning if the frame....,0x01, 0xF3,...end of the frame }.
I try a lot of functions, but maybe not the good one, like setNum(idFrame,16) but it returns :
Frame[X] = 3 ;
Frame[X+1] = F ;
Frame[X+2] = 1 ;
The best way for me will be to get :
Frame[X] = "0x01" ;
Frame[X+1] = "0xF3" ;
Can someone help me ?
Thank you in advance for your support.
Zidoune
Re: quint16 to QByteArray Conversion
Something like this (frame_no is 2 byte unsigned integer) :
Code:
Frame[X+2] = frame_no % 0xFF ;//lower byte
Frame[X+1] = frame_no / 0xFF ;//higher byte
Re: quint16 to QByteArray Conversion
Thank you for your help Lesiok !
Re: quint16 to QByteArray Conversion
You need to understand the difference between the one byte number 0xF3 (243 in decimal) and the 5 byte string "0xF3" or to understand why setNum() was not the correct approach.