串行端口通讯中的问题 [英] Problem in Serial Port Communication

查看:106
本文介绍了串行端口通讯中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我像下面这样写的话,它可以完美地连接到另一端的设备上

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

推荐答案

''0x01''是不同的为0x01(不带引号).

例如,0x77是值119的十六进制表示形式,而该值又是字符 [
从第二种格式中删除引号,它应该可以工作.
''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);


这篇关于串行端口通讯中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆