Ubuntu 虚拟串口 Serial port

http://www.xappsoftware.com/wordpress/2013/10/07/using-virtual-serial-ports-on-linux-ubuntu/?goback=%2Egde_65688_member_5792872722853814274#%21

A virtual serial port is a redirector without network software support which is usually used to create a pair of back-to-back virtual COM ports on the same computer. Two legacy applications can then communicate using virtual serial ports instead of conventional inter-process communication mechanisms such as named pipes.

This type of software is capable of emulating all serial port functionality, including Baud rate, data bits, parity bits, stop bits, etc. Additionally, it allows the data flow to be controlled, emulating all signal lines (DTR/DSR/CTS/RTS/DCD/RI) and customizing pinout.

Often I write software for embedded devices, and they have to exchange data with a PC. Since the devices often, if we don't want to say "always", aren't available during the development phase I have to simulate the connection in other ways. When I have to use UARTs to communicate, I use a tool which generates 2 virtual ports and then joins them back to back.

The software I use on Linux is socat, it is a very complex software and it can do a lot of other things, maybe in another article I'll show other functionalities of socat.

Socat Man Page: "Socat  is  a  command  line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed from a large set of  different  types  of  data  sinks  and  sources (see address types), and because lots of address options may be applied to the streams, socat can be used for many different purposes."

 

However let's try socat:

Installation on Ubuntu

To install socat on Ubuntu (I'm using 12.04) just run the following command:

# sudo apt-get install socat

 

Setting up two serial lines

now on a terminal window run socat

# socat -d -d PTY PTY:

The output should look like the following one:

2013/09/20 14:07:10 socat[6871] N PTY is /dev/pts/5
2013/09/20 14:07:10 socat[6871] N PTY is /dev/pts/6
2013/09/20 14:07:10 socat[6871] N starting data transfer loop with FDs [3,3] and [5,5]

 

Now you have two "serial" ports connected back to back

Testing the ports

open a new terminal and issue the following command

# sudo cat /dev/pts/5

open a new terminal and issue the following command

# sudo echo "Hello World" > /dev/pts/6

On the first terminal you should see the string "Hello World".

 

That's all, nothing more.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Ubuntu上安装串口助手可以帮助我们测试蓝牙等设备的串口连接。你可以按照以下步骤进行安装: 1. 打开终端,使用以下命令安装Minicom串口助手: ``` sudo apt-get install minicom ``` 2. 安装完成后,你可以通过以下命令打开Minicom: ``` sudo minicom -s ``` 3. 在Minicom配置界面中,你需要进行一些设置: - 使用箭头键选择"Serial port setup",然后按下回车键。 - 在"Serial Device"选项中,选择正确的串口设备,比如/dev/ttyS0或/dev/ttyUSB0。 - 在"Hardware Flow Control"选项中,选择"No"。 - 在"Software Flow Control"选项中,选择"No"。 - 选择"Save setup as dfl",然后按下回车键保存设置。 - 按下"Exit"键退出配置界面。 4. 现在,你可以使用Minicom来测试串口连接了。在终端中运行以下命令: ``` sudo minicom ``` 这样,你就可以使用Minicom进行串口通信和测试了。 如果你使用的是无线串口或蓝牙连接设备,你还需要确保端口具有适当的权限。你可以使用以下命令修改端口权限: ``` sudo chmod 666 /dev/ttyS* ``` 其中,`/dev/ttyS*`是你所使用的串口设备路径。中提供的链接。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ubuntu下安装使用串口助手cutecom](https://blog.csdn.net/qqliuzhitong/article/details/114335835)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【Ubuntuubuntu桌面版 安装 串口调试助手](https://blog.csdn.net/weixin_42123784/article/details/89712811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值