linux虚拟串口创建,linux虚拟串口编程

环境: unbuntu14 虚拟机,已设置可联网

目的1:在linux环境下读写虚拟串口(2虚拟串口连接)

步骤:

一,创建虚拟串口

1.安装虚拟软件

apt-get install socat

2.创建虚拟串口

socat -d -d pty,raw,echo=0 pty,raw,echo=0

二,串口读写测试-echo测试

写串口:

echo 设备

读串口:

cat设备

参考文档:

https://blog.csdn.net/rainertop/article/details/26706847

目的2:在linux环境下利用调试工具调试串口

工具:cutecom

主要内容:

利用cutecom 串口调试工具,利用两个虚拟串口进行收发通信

参考文档:

https://blog.csdn.net/zhaoqi2617/article/details/72238546

目的3:在linux环境下编写串口程序,实现收发

暂未执行

参考:

详解linux下的串口通讯开发

https://user.qzone.qq.com/249149995/2

https://blog.csdn.net/baweiyaoji/article/details/72885633

原创实例:serial_test.c

#include

#include

#include

#include

#include

#include

#include

#include

#include

//#include

int main()

{

char sbuf[]="humin is handsome";

struct termios opt;

int len_send=sizeof(sbuf);

int fd;

int ret;

cfsetispeed(&opt, B9600);

cfsetospeed(&opt, B9600);

fd = open("/dev/pts/24", O_RDWR|O_NOCTTY);

if(fd == -1)

perror("Can not open Serial_Port 1/n!");

ret = write(fd,sbuf,len_send);

if(ret == -1) {

printf("Wirte sbuf error./n");

}

ret = close(fd);

if(ret == -1) {

printf("Close fd error./n");

}

return 0;

}

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值