没有合适的资源?快使用搜索试试~ 我知道了~
linux下的串口通信程序详解.doc
0 下载量 115 浏览量
2024-05-15
09:07:46
上传
评论
收藏 58KB DOC 举报
温馨提示
试读
5页
linux下的串口通信程序详解.doc
资源推荐
资源详情
资源评论
linux 下的串口通信程序详解
2009-07-19 12:37
为了说明问题,下面给出测试程序来理解 linux 下的串口操作流程,例程 receive.c
用来接收从串口发来的数据,而例程 send.c 用来发送数据到串口。二者成功建立串
口连接后,串口接收端会收到串口发送端发来的字符串数据“Hello,this is a
Serial Port test!”。
1. receive.c 程序清单:
view plain
1. /*******************************************************
2. *ilename:receive.c
3. * Description:Receive data from Serial_Port
4. * Date:
5. *******************************************************/
6. /*********************头文件定义***********************/
7. #include <stdio.h>
8. #include <string.h>
9. #include <malloc.h>
10. #include <sys/types.h>
11. #include <sys/stat.h>
12. #include <fcntl.h>
13. #include <unistd.h>
14. #include <termios.h>
15. #include "math.h"
16. #define max_buffer_size 100 /*定义缓冲区最大宽度*/
17. /*********************************************************/
18. int fd,s;
19. int open_serial(int k)
20. {
21. if(k==0) /*串口选择*/
22. {
23. fd = open("/dev/ttyUSB0",O_RDWR|O_NOCTTY); /*读写方式打开串口*/
24. perror("open /dev/ttyUSB0");
25. }
26. else
27. {
28. fd = open("/dev/ttyS1",O_RDWR|O_NOCTTY);
29. perror("open /dev/ttyS1");
30. }
31. if(fd == -1) /*打开失败*/
32. return -1;
33. else
34. return 0;
35. }
资源评论
平头哥在等你
- 粉丝: 2
- 资源: 7332
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功