usb转串口异步读取数据
来源:互联网 发布:网络cv设备 编辑:程序博客网 时间:2024/06/16 08:10
该实验是通过usb转串口线连接了开发板的 uart3和pc。
在pc上编译下面代码并执行
#include<stdio.h>#include <signal.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#define MODEMDEVICE "/dev/ttyUSB0"#define FALSE 0#define TRUE 1int wait_flag=TRUE;void signal_handler(int i){ printf("%s\n", __func__); wait_flag=TRUE; }int main(){ int fd=0; int res; char buf[512]={0}; int STOP = 1; fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd <0) {perror(MODEMDEVICE); return -1; } signal(SIGIO, signal_handler); /* allow the process to receive SIGIO */ fcntl( fd, F_SETOWN, getpid() ); int flags = fcntl( fd, F_GETFL ); fcntl( fd, F_SETFL, flags|FASYNC ); while(STOP){ if(wait_flag){ res = read(fd,buf,512); buf[res]='\0'; printf("%d : %s\n", res, buf); if(buf[0]=='s' && buf[1] =='t'){ STOP = 0; } wait_flag=FALSE; } //sleep(1); } printf("exit...\n"); close(fd); return 0;}
执行效果:
阅读全文
0 0
- usb转串口异步读取数据
- Linux下使用USB转串口读取GPS数据
- 从Garmin USB中读取GPS数据(串口实现)
- linux 使用usb转串口模块并读串口数据
- 在mac os下读取usb转串口的信息
- MFC读取串口数据
- 读取串口数据画图
- 线程读取串口数据
- MFC读取串口数据
- 读取串口数据画图
- Web串口读取数据
- java读取串口数据
- QT串口读取数据
- 串口读取数据
- 读取串口数据
- Linux读取串口数据
- 串口以及USB转串口收发程序(16进制数的读取发送)
- Linux下使用USB转串口读GPS数据
- vue 的全局API
- [Python]cannot import name IntEnum
- POI读取excel转换成XML
- MySQL 第五天
- object转化成json,json格式字符串转字典,数组或字典转为json串
- usb转串口异步读取数据
- 背包DP合辑
- 某外企C++面试题
- Android BLE 开发资料汇总
- Spark机器学习之协同过滤算法使用-Java篇
- vue-router(1)
- MySQL 第四天
- python,Windows环境安装及导入beautifulsoup
- RSA密钥,JAVA与.NET之间转换