-------------------------------------资源来源于网络,仅供自学使用,如有侵权,联系我必删.
第一:
实验-串口发送
串口发送类似文件操作,非常简单。使用 write 函数即可,三个参数分别是句柄,传输的buffer 以及,传输的长度。这个函数前面介绍文件 IO 的时候已经介绍过了,这里就不再重复。
1)先来看一下代码的头文件,然后引入前面的初始化函数。
2)将串口参数配置整合为一个函数,主函数就比较简单了,如下图所示。
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
int set_opt(int,int,int,char,int);
void main()
{
int fd,wr_static,i=10;
char *uart3 = "/dev/ttySAC3";
char *buffer = "hello world!\n";
printf("\r\nitop4412 uart3 writetest start\r\n");
if((fd = open