您的位置:首页 > 其它

Virtual Serial Port on Ubuntu

2013-09-26 22:11 561 查看
Contents

Introduction
Installing prerequisites
Creating ports

Checking file names

External Links

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: