/*串口自收自发程序主函数*/
#include"uart_api.h"
int main()
{
 int fd;
 char buff[BUFFER_SIZE];
 char buff2[]="Hello NUAA2440!\n";
 int nread,nwrite;
 if((fd=open_port(TARGET_COM_PORT))<0)
 {
  perror("open serial error");
  return 1;
 }
 printf("open ok!\n");
 if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
 {
  perror("set_com_config error");
  return 1;
 }
 printf(" set ok!\n");
 
 /*将缓冲区buff2中的数据写入到串口1中去*/
 nwrite=write(fd,buff2,sizeof(buff2));
 printf("nwrite=%d\n",nwrite);   /*打印写入的数据*/
 /*接下来就是读数据*/
 while(1)
 {
  if((nread = read(fd,buff,1024))>0)
  {
   buff[nread] = '\0';
   printf("\nrecv:%d\n",nread);
   printf("%s",buff);
  }
 }
 close(fd);
 return 0;
 
}
 
 

最新文章

  1. django 操作 下载 excel xls xlsx csv
  2. beego中orm关联查询使用解析
  3. 36.Android之多线程和handle更新UI学习
  4. 【题解】【字符串】【Leetcode】Valid Palindrome
  5. Tomcat在eclipse中起动成功,主页却打不开
  6. 文件操作 - NSFileManager
  7. 解决poi导出Excel异常org.openxmlformats.schemas.spreadshe
  8. linux下C++对线程的封装
  9. 【转】MUD教程--巫师入门教程4
  10. Json.Net系列教程 4.Linq To JSON
  11. Java后端开发书架
  12. 04flask_scripts使用
  13. [SQL]事务回滚详解及示例
  14. php php-fpm安装 nginx配置php
  15. swift计算 switch case
  16. python的索引问题
  17. linux下uptime命令详解
  18. java泛型讲解
  19. argunlar 1.0.1 【数据绑定】
  20. 用Keras搭建神经网络 简单模版(一)——Regressor 回归

热门文章

  1. BZOJ3530: [Sdoi2014]数数(Trie图,数位Dp)
  2. 关于搭建Session服务器(转载)
  3. [Vue + TS] Use Properties in Vue Components Using @Prop Decorator with TypeScript
  4. A glance on VDBI
  5. android中常见声音操作方式(Ringtone,SoundPool,MediaPlayer)小结
  6. ORA-16009 remote archive log destination must be a STANDBY database
  7. Cocos2d-x学习笔记(一)HelloWorld
  8. 谈谈vector容器的三种遍历方法
  9. AJAX有关的请求协议及HTTP报文
  10. startActivityForResult()方法具体解释