智能创客,中国最大的极客空间,智能平台,免费教学,视频教程,手把手教你创造儿时梦想!

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 12555|回复: 28
打印 上一主题 下一主题

wiringpi教程5 读串口serialRead.c

  [复制链接]

110

主题

396

帖子

2329

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2329
QQ
跳转到指定楼层
楼主
发表于 2014-2-11 12:02:29 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
/*
* serialRead.c:
*    Example program to read bytes from the Serial line
*
*/

#include <stdio.h>
#include <string.h>
#include <errno.h>

#include <wiringSerial.h>

int main ()
{
  int fd ;
//看解释
//int serialOpen (char *device, int baud) ;
//This opens and initialises the serial device and sets the baud rate. It sets the port into “raw” mode //(character at a time and no translations), and sets the read timeout to 10 seconds. The return value is the file //descriptor or -1 for any error, in which case errno will be set as appropriate
// 没有接到设备就是-1 超时为10秒

  if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
  {
    fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
    return 1 ;
  }

// Loop, getting and printing characters

  for (;;)
  {
//
//int serialGetchar (int fd) ;

//Returns the next character available on the serial device. This call will block for up to 10 seconds if no data //is available (when it will return -1)

    putchar (serialGetchar (fd)) ;
    fflush (stdout) ;
  }
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|手机版|智能创客 ( 桂ICP备14000828号

GMT+8, 2024-5-8 07:02 , Processed in 0.121151 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表