test2.c

来自「《linux驱动程序设计从入门到精通》一书中所有的程序代码含驱动和相应的应用程序」· C语言 代码 · 共 57 行

C
57
字号
/* * This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2007, 2010 fengGuojin(fgjnew@163.com) */#include<sys/types.h>#include<unistd.h>#include<fcntl.h>#include<linux/rtc.h>#include<linux/ioctl.h>#include<stdio.h>#include<stdlib.h>main(){  int fd;  int i=0;;  char data[256];    int retval;  fd=open("/dev/fgj",O_RDWR);  if(fd==-1)  {     perror("error open\n");     exit(-1);  }  printf("open /dev/smbus successfully\n");    while(i<1000)  {	retval=write(fd,"222",3);	if(retval==-1)	{		perror("write error\n");		exit(-1);	}	retval=lseek(fd,0,0);	if(retval==-1)	{		perror("lseek error\n");		exit(-1);	}	retval=read(fd,data,3);	if(retval==-1)	{		perror("read error\n");		exit(-1);	}	printf("read2 successfully:%s\n",data);	i++;   }  close(fd);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?