Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (6.1k points)

I want to test a serial port application on Linux, but my test machine only has one serial port.

How to add a virtual serial port to Linux and test my application by emulating a device through a script or shell?

I won’t be able to remap the port as it is hardcoded on ttys2 and I need to test the application the way it is without any changes. 

1 Answer

0 votes
by (11.7k points)

It can be done easily on a Linux machine, you can use a pty ("pseudo-teletype", where a serial port is a "real teletype"). From one end, open /dev/ptyp5, and then attach your program to /dev/ttyp5; ttyp5 act as a serial port, but will send/receive everything it does via /dev/ptyp5.

If you want to access and talk to file /dev/ttys2, then move your old /dev/ttys2 out of the way and make a symlink from ptyp5 to ttys2.

Yes, you can use some other number rather than ptyp5. You can prefer to pick one with a high number to avoid duplication because all of your login terminals will also be using ptys.

If you want to read more about ptys, visit this link.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Apr 2, 2021 in Linux by sheela_singh (9.5k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...