免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 682 | 回复: 2
打印 上一主题 下一主题

串口字符 0x0a [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-21 08:26 |只看该作者 |倒序浏览
这是我在linux下的一个串口设置函数
int tty_set_attr(int fd)
{
        int i;
        int status;
        struct termios options;
        int baud=B115200;

        tcgetattr(fd, &oldoptions);
        options=oldoptions;
     
        cfsetispeed(&options,baud);
        cfsetospeed(&options,baud);

        options.c_cflag|=(CLOCAL|CREAD|HUPCL);

        options.c_cflag&=~CSIZE;
        options.c_cflag|=CS8;

        options.c_cflag&=~CSTOPB;
   
        options.c_cflag&=~PARENB;
        options.c_cflag&=~PARODD;
   
        options.c_iflag=IGNBRK|IGNPAR; //(IXON|IXOFF) will use 0x11 0x13
        options.c_lflag=0;  //turn canonial

        options.c_cc[VMIN]=1;
        options.c_cc[VTIME]=0;

        //options.c_cflag&=~CRTSCTS;  // (hardware control)


       status = tcsetattr(fd, TCSANOW, &options);
        if  (status != 0)
       {
                printf("tcsetattr fd error\n");
              return -1;
       }
       return 0;
}

通过这个串口与一个无线模块进行通讯时,发现如果发出去的数据里有0x0a,0x0b,通讯就会不正常。
请大侠们指点

论坛徽章:
0
2 [报告]
发表于 2006-09-21 08:37 |只看该作者
options.c_lflag&=~(ICANON | ECHO | ECHOE | ISIG);
        options.c_oflag&=~OPOST;
找了个Modem程序,加了这两句就好了,也不清楚是哪个设置起效果了

论坛徽章:
0
3 [报告]
发表于 2006-09-22 08:29 |只看该作者
options.c_lflag&=~(ICANON | ECHO | ECHOE | ISIG);

不对串口数据进行解码,原始数据模式吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP