Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
If I write like below it goes perfectly to device at other end
C++
char ch[18] = {0x01,0x01,0x01,0x02,0x00,0x01,0x01,0x0C,0x05,0x00,0x01,0x01,0x55,0x55,0x55,0x55,0x55,0x77};
 pPortInterface->;Writechar(ch);


But if I write like below it does not go

C++
char ch[18];
	ch[0]= '0x01';
	ch[1]='0x01';
	ch[2]='0x01';
	ch[3]='0x02';
	ch[4]='0x00';
	ch[5]='0x01';
	ch[6]='0x01';
	ch[7]='0x0C';
	ch[8]='0x05';
	ch[9]='0x00';
	ch[10]='0x01';
	ch[11]='0x01';
	ch[12]='0x55';
	ch[13]='0x55';
	ch[14]='0x55';
	ch[15]='0x55';
	ch[16]='0x55';
	ch[17]='0x77';

	pPortInterface->Writechar(ch);


I want to assign in second format as I want Variable input to device not fixed one,Please let me know how to do it
Posted

1 solution

'0x01' is not the same as 0x01 (without the quotes).

For example 0x77 is a hexadecimal representation of the value 119, which in turn is character[^] 'w'.

Remove the quotes from the second format and it should work.
C++
char ch[18];
	ch[0]=0x01;
	ch[1]=0x01;
	ch[2]=0x01;
	ch[3]=0x02;
	ch[4]=0x00;
	ch[5]=0x01;
	ch[6]=0x01;
	ch[7]=0x0C;
	ch[8]=0x05;
	ch[9]=0x00;
	ch[10]=0x01;
	ch[11]=0x01;
	ch[12]=0x55;
	ch[13]=0x55;
	ch[14]=0x55;
	ch[15]=0x55;
	ch[16]=0x55;
	ch[17]=0x77;
 
	pPortInterface->Writechar(ch);
 
Share this answer
 
v2
Comments
adityarao31 29-Nov-12 6:59am    
Great Man Thank you very much I was struggling for it for so much time
André Kraak 29-Nov-12 7:06am    
Your welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900