飞凌-unix 发表于 2012-11-12 16:27:21

红外代码

/*
forlinx
*/
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/stat.h>
#include <fcntl.h>
//#include <sys/time.h>
//#include<unistd.h>
int main(void)
{
    int fd;
    unsigned char buf;

    if ((fd=open("/dev/irda0",O_RDONLY)) < 0)
    {
            printf("Open Device IRDA failed.\r\n");
            exit(1);
    }
    else
    {
            printf("Open Device IRDA successed.\r\n");

            while (1)
            {
               read(fd, buf, 1);
            if (buf == 0)
                printf("0\n");//判断数据为0则输出0
            else    printf("1\n"); //否则输出1
      
            //sleep(1);
            }
      close(fd);

      }

    return 0;
}


页: [1]
查看完整版本: 红外代码