c - Linux serial port - wrtie( ) byte to the target device through serial port -
unsigned char cmd[] = {'a', 't', '+', "0x07", "0x08", 'd', 'f', "0xa6"};
to write command target device, expect write byte
41 54 2b 07 08 44 46 a6
accordingly.
however, actual bytes written device
41 54 2b b8 bb 44 46
and it's obvious wrong @
0x07 0x08 0xa6
how write bytes expect have in above example ?
----- write function -------
void writetodevice(){ unsigned char cmd[]={'a', 't', '+', "0x07", "0x08", 'd', 'f', "0xa6"}; int n = write(fd,&cmd,8); for(p=0;p<8;p++){ printf("bytes written: %02x \n", cmd[p]); } if(n<0){ printf("write error \n"); } else{ printf("%d bytes written \n", n); } };
compiler warning
warning: (near initialization ‘cmd[3]’) [enabled default] warning: initialization makes integer pointer without cast [enabled default]
instead of "0x07", "0x08"
, etc use '\x07', '\x08
', etc.
Comments
Post a Comment