bonjour , j'ai une petite problème concernant l'envoie dune trame en hex , comme vous voyez dans le code buf contient dans ce cas buf[0]='\x1' et buf[1]='\x0' mais quand je l'envoie je trouve pas le buf[1] je pense parce qu'il trouve le 0 , même chose si je le convertir en string il s’arrête a '\0' (end of string) .
dans mon code je veut envoyer ce buf de fois donc je trouve juste le '\x1' répéter deux fois fois.
merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
union IntByte
	{
		uint32_t i;
		uint8_t b[2];
	};
 
int PC=1;
	string data_frame;
	stringstream msg;
	uint8_t tab[2]  ;
 
 
	unsigned char buf1[2];
 
	IntByte ib;
 
	memset(tab, 0, 2 * sizeof(uint8_t));
	ib.i = PC;
	for (int i = 0; i < 2; ++i)
{
cout<< std::hex << (uint32_t)ib.b[i] << std::endl;
buf1[i] = ib.b[i];
}
msg << '\x06' << '\x22' << buf1 << buf1;
data_frame = calcule_crc((uint8_t*)msg.str().c_str(), 8);
	{