test_tty.c

来自「深圳英培特EduKit-III实验箱实验程序。一共有10多个」· C语言 代码 · 共 42 行

C
42
字号
/*********************************************************************
* File:		test_tty.c
* Author:	Embest	J.Zhao	2004.3.20
* Desc:		
* History:	
*********************************************************************/

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

int main()
{
	int fd;
	int n;
	char buf[10] = "1234567890";
	
	/* open ttyS0 device file --- S3CEV40 UART0 */
	fd = open("/dev/ttyS0", O_RDWR|O_NOCTTY|O_NDELAY);
	if(fd == -1)
	{
		printf("Fail to open /dev/ttyS0\n");
		return -1;
	}
	else
		fcntl(fd, F_SETFL, 0);
	
	/* write data to UART0 */
	if(write(fd, buf, 10) != 10)
	{
		printf("Fail to open /dev/ttyS0\n");
		return -1;
	}
	
	/* close ttyS0 */
	close(fd);
	
	return 0;
}

⌨️ 快捷键说明

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