test_spioc.c

来自「it is character driver」· C语言 代码 · 共 41 行

C
41
字号
#include <stdio.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int main(int argc, char **argv){   	int t;	int portfd;	char wstr[32], rstr[32];	int number;	portfd = open("/dev/spioc", O_RDWR | O_NOCTTY | O_NDELAY);	if(portfd == -1) 	{		printf("cannot open /dev/spioc.\n");		return -1;	}	else	{		printf("open /dev/spioc successful.\n");	}	printf("write string abcdefghij to spioc\n");	strcpy(wstr, "abcdefghij");	number = strlen(wstr) - 1;	write(portfd, wstr, number);  for(t=1;t<1000000;t++);		printf("read data from spioc\n");	read(portfd, rstr, number);	rstr[number] = 0;	printf("the output string is %s.\n", rstr);	close(portfd);	return 0;}

⌨️ 快捷键说明

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