嵌入式linux串口通信自发自收测试程序

简介: /*串口自收自发程序主函数*/#include"uart_api.h"int main(){ int fd; char buff[BUFFER_SIZE]; char buff2[]="Hello NUAA2440!\n"; int nread,nwrite; if((fd=open_port(T...
 /*串口自收自发程序主函数*/
#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;
 
}
 
 
目录
相关文章
|
2月前
|
Linux Shell
linux自动崩溃,模拟测试
该脚本创建一个 systemd 服务和定时器,在系统启动3分钟后触发崩溃。通过向 /proc/sysrq-trigger 写入 &quot;c&quot; 来实现内核崩溃,用于测试系统崩溃后的恢复机制。
62 3
|
2月前
|
安全 Linux iOS开发
Burp Suite Professional 2025.7 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
Burp Suite Professional 2025.7 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
307 0
Burp Suite Professional 2025.7 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
|
3月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.7-2025061201 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.7-2025061201 (Linux, Windows) - 专业渗透测试框架
113 3
Metasploit Pro 4.22.7-2025061201 (Linux, Windows) - 专业渗透测试框架
|
1月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-2025073001 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025073001 (Linux, Windows) - 专业渗透测试框架
85 0
|
4月前
|
监控 安全 测试技术
【01】卓伊凡收到冒充税务机关的诈骗程序-决定在沙盒Sandbox环境中运行测试下-广大企业同胞们注意防诈骗
【01】卓伊凡收到冒充税务机关的诈骗程序-决定在沙盒Sandbox环境中运行测试下-广大企业同胞们注意防诈骗
131 14
【01】卓伊凡收到冒充税务机关的诈骗程序-决定在沙盒Sandbox环境中运行测试下-广大企业同胞们注意防诈骗
|
4月前
|
安全 Unix Linux
Metasploit Pro 4.22.7-2025052201 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.7-2025052201 (Linux, Windows) - 专业渗透测试框架
115 5
Metasploit Pro 4.22.7-2025052201 (Linux, Windows) - 专业渗透测试框架
|
4月前
|
安全 前端开发 Linux
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
152 3
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
|
4月前
|
安全 测试技术 Linux
Flawnter 5.9.1 (macOS, Linux, Windows) - 应用程序安全测试软件
Flawnter 5.9.1 (macOS, Linux, Windows) - 应用程序安全测试软件
136 2
Flawnter 5.9.1 (macOS, Linux, Windows) - 应用程序安全测试软件
|
4月前
|
数据采集 安全 Linux
Metasploit Pro 4.22.7-2025051201 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.7-2025051201 (Linux, Windows) - 专业渗透测试框架
92 4
Metasploit Pro 4.22.7-2025051201 (Linux, Windows) - 专业渗透测试框架
|
4月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.63 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.63 (macOS, Linux, Windows) - 开源渗透测试框架
102 4
Metasploit Framework 6.4.63 (macOS, Linux, Windows) - 开源渗透测试框架