Virtual Serial Port on Ubuntu

Introduction

Virtual serial ports are commonly used in development of programs using serial connection as well as debugging existing applications - to check what kind of data is transmitted over a serial connection.

The idea of virtual serial port is to create two virtual serial ports linked with a null modem cable, attaching one end to tested application and the other end to (usually) serial terminal (e.g. Cutecom).

Installing prerequisites

To create a pair of ports you will need a utility called "socat". It is located in "universe" repository, so you should be able to find it in Synaptic. Alternatively install using

sudo apt-get install socat

Creating ports

After installing socat you have to execute following command:

socat PTY: PTY:

That should create and link the virtual port pair for as long as socat is running.

If you are like me and want a little more feedback on what is happening instead of a command line that is hanging, use verbose mode instead:

socat -d -d PTY: PTY:

You can put the -d argument up to four times, increasing the information fed back to you each time.

Checking file names

Using socat

The easiest way to tell which file names are assigned to these virtual ports is to tell socat to print information about opened pseudo terminals during initialization using following options (verbose mode):

socat -d -d PTY: PTY:

Your applicantion should connect to these files.

Using lsof

Another way is to list socat's open files:

lsof -c socat

You should notice file /dev/ptmx, that is pseudo terminal multiplexer and directly below each entry should be listed /dev/pts/X file, which are the ends of created pair. 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值