/*com_writer.c*/
#include "uart_api.h"

int main(void)
{
 int fd;
 char buff[BUFFER_SIZE];
 if((fd=open_port(HOST_COM_PORT))<0)  /*打开串口*/
 {
  perror("open serial error");
  return 1;
 }
 if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
 {
  perror("set_com_config error");
  return 1;
 }
 do
 {
  printf("Input some words(enter 'quit' to exit):");
  memset(buff,0,BUFFER_SIZE);
  if(fgets(buff,BUFFER_SIZE,stdin)==NULL)
  {
   perror("fgets");
   break;
  }
  write(fd,buff,strlen(buff));
 }while(strncmp(buff,"quit",4));
 close(fd);
 return 0;
 
}

/*com_reader.c*/
#include "uart_api.h"
#define COM_TYPE GNR_COM
int main(void)
{
 int fd;
 char buff[BUFFER_SIZE];
 if((fd=open_port(TARGET_COM_PORT))<0)
 {
  perror("open serial error");
  return 1;
 }
 if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
 {
  perror("set_com_config error");
  return 1;
 }
 do
 {
  memset(buff,0,BUFFER_SIZE);
  if(read(fd,buff,BUFFER_SIZE)>0)
  {
   printf("the receive words are:%s",buff);
  }
 }while(strncmp(buff,"quit",4));
 close(fd);
 return 0;
}

/*uart_api.h*/

#include<errno.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include <termios.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <ctype.h>
#define HOST_COM_PORT 1
#define BUFFER_SIZE  4096
#define MAX_COM_NUM  5
#define TARGET_COM_PORT 1
extern int open_port(int com_port);
extern int set_com_config(int fd,int baud_rate, int data_bits,char parity,int stop_bits);

最新文章

  1. CS193P - 2016年秋 第一讲 课程简介
  2. 背水一战 Windows 10 (5) - UI: 标题栏
  3. 复制选中的listbox内容
  4. mvc Html.BeginForm 生成 ?Length=
  5. ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明
  6. 每日一dp(2)——龟兔赛跑(hdu 2059)
  7. HDU1166 数状数组
  8. jquery系列教程3-DOM操作全解
  9. 人体姿态的相似性评价基于OpenCV实现最近邻分类KNN K-Nearest Neighbors
  10. ubuntu安装fat32和exfat文件系统支持
  11. (NO.00004)iOS实现打砖块游戏(三):游戏主场景和砖块
  12. SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码
  13. redis主从同步故障切换及集群配置
  14. 看不懂霍尔效应的直接看视频https://www.bilibili.com/video/av11446173/
  15. SharePoint 2013 Workflow Manager 1.0 远程服务器返回错误: (400) 错误的请求。 不支持查询字符串中的 api-version
  16. Installation of Scylla on CentOS 7
  17. [svc]linux日志和安全日志
  18. shell脚本基本用法
  19. linux 常用命令总结(三)
  20. iview(DatePicker)时间转入后台少一天 解决方案

热门文章

  1. opera mini 改服
  2. [ Tomcat ] [ startup ] Tomcat 無法在時限內開啟問題
  3. numpy_basic
  4. MFC只允许程序单开
  5. SQL查询练习二(From LeetCode)
  6. libcurl 通过http协议下载文件并显示下载进度
  7. java 文件读写--转载
  8. AndroidStudio 内存泄漏分析 Memory Monitor
  9. ASP.Net中页面传值的几种方式
  10. ThinkPHP5.0---方法异常格式