免费注册 查看新帖 |

Chinaunix

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

串口不能接收到数据问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-10-16 10:43 |只看该作者 |倒序浏览
串口不能接收到数据,在发送则有回显现像,望赐教!

#include     <stdio.h>;      /*鏍囧噯杈撳叆杈撳嚭瀹氫箟*/
#include     <stdlib.h>;     /*鏍囧噯鍑芥暟搴撳畾涔?/
#include     <unistd.h>;     /*Unix鏍囧噯鍑芥暟瀹氫箟*/
#include     <sys/types.h>;  /**/
#include     <sys/stat.h>;   /**/
#include     <fcntl.h>;      /*鏂囦欢鎺у埗瀹氫箟*/
#include     <termios.h>;    /*PPSIX缁堢?鎺у埗瀹氫箟*/
#include     <errno.h>;      /*閿欒?鍙峰畾涔?/

#define FALSE 0
#define TRUE 1
/***@brief  璁剧疆涓插彛閫氫俊閫熺巼
*@param  fd     绫诲瀷 int  鎵撳紑涓插彛鐨勬枃浠跺彞鏌?*@param  speed  绫诲瀷 int  涓插彛閫熷害
*@return  void*/

int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300,
            B38400, B19200, B9600, B4800, B2400, B1200, B300, };
int name_arr[] = {38400,  19200,  9600,  4800,  2400,  1200,  300,
            38400,  19200,  9600, 4800, 2400, 1200,  300, };
void set_speed(int fd, int speed)
{
  int   i;
  int   status;
  struct termios   Opt;
  tcgetattr(fd, &Opt);
  for ( i= 0;  i < sizeof(speed_arr) / sizeof(int);  i++)
   {
           if  (speed == name_arr)
           {
               tcflush(fd, TCIOFLUSH);
            cfsetispeed(&Opt, speed_arr);
            cfsetospeed(&Opt, speed_arr);
            status = tcsetattr(fd, TCSANOW, &Opt);
            if  (status != 0)
            perror("tcsetattr fd1";
             return;
             }
   tcflush(fd,TCIOFLUSH);
   }
}
/**
*@brief   璁剧疆涓插彛鏁版嵁浣嶏紝鍋滄?浣嶅拰鏁堥獙浣?*@param  fd     绫诲瀷  int  鎵撳紑鐨勪覆鍙f枃浠跺彞鏌?
*@param  databits 绫诲瀷  int 鏁版嵁浣?  鍙栧

论坛徽章:
0
2 [报告]
发表于 2003-10-16 12:01 |只看该作者

串口不能接收到数据问题!

呵呵,这段例程我也刚用过,前面几个函数好象没有改吧,没问题的。
收不到数据的?写串口你是怎么做的,帖出的main只有读
spring_sky 该用户已被删除
3 [报告]
发表于 2003-10-16 14:58 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
4 [报告]
发表于 2003-10-16 23:56 |只看该作者

串口不能接收到数据问题!

写用write()写就是了呀,我写是好的,这个是网上下的,我就不明白什么不能读呢.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP