test.c

来自「Linux 2.6.24通过SMBUS总线(也类似于i2c总线)读写内存上的SP」· C语言 代码 · 共 58 行

C
58
字号
/*  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>#define		COUNT  (100)int main(void){	int fd;	int i,result;	unsigned char buf[COUNT];	for(i=0;i<COUNT;i++)		buf[i] = 0x00;  	fd=open("/dev/spd",O_RDWR);  	if(fd==-1)  	{		perror("  #### i2c test device open failed #### \n");     	return -1;  	} 	//printf("  open /dev/spd successfully\n");/*	while(chr != '9'){		chr = getchar();		if(chr != 10)			printf("%x ",chr);	}	getchar();*/	result = read(fd,&buf,COUNT);	if(result < 0)	{		perror("   #### read data form smbus failed #### \n");		goto out;	}	for(i=0; i<COUNT;i++)	{		printf("   buf[%d]=%2x",i,buf[i]);		if(i%5 == 0)  printf("\n");	}	printf("\n");out:	close(fd);	return result;}

⌨️ 快捷键说明

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