zoukankan      html  css  js  c++  java
  • 嵌入式linux串口通信自发自收测试程序

     /*串口自收自发程序主函数*/
    #include"uart_api.h"
    int main()
    {
     int fd;
     char buff[BUFFER_SIZE];
     char buff2[]="Hello NUAA2440! ";
     int nread,nwrite;
     if((fd=open_port(TARGET_COM_PORT))<0)
     {
      perror("open serial error");
      return 1;
     }
     printf("open ok! ");
     if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
     {
      perror("set_com_config error");
      return 1;
     }
     printf(" set ok! ");
     
     /*将缓冲区buff2中的数据写入到串口1中去*/
     nwrite=write(fd,buff2,sizeof(buff2));
     printf("nwrite=%d ",nwrite);   /*打印写入的数据*/
     /*接下来就是读数据*/
     while(1)
     {
      if((nread = read(fd,buff,1024))>0)
      {
       buff[nread] = '';
       printf(" recv:%d ",nread);
       printf("%s",buff);
      }
     }
     close(fd);
     return 0;
     
    }
     
     
  • 相关阅读:
    手机操作
    模拟手机操作
    get_attribute_value
    test_order
    信息收集-FOFA资产收集与FOFA api
    html中form讲解
    安装redis
    yum vs rpm
    yum 安装java环境
    显示当前目录所有文件大小的命令ls -lht
  • 原文地址:https://www.cnblogs.com/lidabo/p/5391069.html
Copyright © 2011-2022 走看看