Click here to Skip to main content
12,501,882 members (51,247 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: serialport VisualC++
If I write like below it goes perfectly to device at other end
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

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 29-Nov-12 0:42am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

'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.
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);
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100