简体   繁体   English

Linux串行端口-wrtie()字节通过串行端口到达目标设备

[英]Linux serial port - wrtie( ) byte to the target device through serial port

unsigned char cmd[] = {'A', 'T', '+', "0x07", "0x08", 'D', 'F', "0xA6"};

To write this command to my target device, I expect to write byte 要将此命令写入目标设备,我希望写入字节

41 54 2b 07 08 44 46 A6 

accordingly. 相应地。

However, the actual bytes written to device are 但是,写入设备的实际字节为

41 54 2b b8 bb 44 46 be

and it's obvious wrong at 这显然是错误的

0x07 0x08 0xA6

How to write bytes are I expect to have in the 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 for ‘cmd[3]’) [enabled by default]
warning: initialization makes integer from pointer without a cast [enabled by default]

代替"0x07", "0x08"等,请使用'\\x07', '\\x08 '等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM