How can I set up virtual serial ports (Linux null modem emulator) using tty0tty
Installation
-
Download the tty0tty package from one of these sources:
-
clone the repo https://github.com/freemed/tty0tty:
git clone https://github.com/freemed/tty0tty
-
Extract it:
tar xf tty0tty-1.2.tgz
-
Build the kernel module from provided source:
cd tty0tty-1.2/module make
-
Copy the new kernel module into the kernel modules directory:
sudo cp tty0tty.ko /lib/modules/$(uname -r)/kernel/drivers/misc/
-
Load the module:
sudo depmod sudo modprobe tty0tty
You should see new serial ports in
/dev/
(ls /dev/tnt*
) -
Give appropriate permissions to the new serial ports:
sudo chmod 666 /dev/tnt*
You can now access the serial ports as /dev/tnt0
(1,2,3,4 etc)
Note that the consecutive ports are interconnected. For example, /dev/tnt0
and /dev/tnt1
are connected as if using a direct cable.
Persisting across boots
Edit the file /etc/modules
(Debian) or /etc/modules.conf
sudo nano /etc/modules.conf
and add the following line:
tty0tty
Warning
Note that this method will not make the module persist over kernel updates so if you ever update your kernel, make sure you build tty0tty again repeat the process.
If you don't move the module on every kernel update systemctl --failed
will return that service systemd-modules-load.service
ended "failed
". Also on journalctl -xe | grep "Failed to find"
.
Related videos on Youtube
yuva
Updated on September 18, 2022Comments
-
yuva almost 2 years
I want to set up a virtual serial port emulator in Linux. I want the ports to be permanent, so that I can use them every time I restart. I tried using socat for that purpose in this way,
socat -d -d pty,raw,echo=0 pty,raw,echo=0
But I often get "port busy" issues during the usage of these VSPs (Virtual Serial Ports) in my test programs. Also, I find it hard to create permanent/persistent VSPs.
I now want to try out tty0tty for my purposes. But I have found little documentation on how to use it. Can anyone enlighten me on this? Please do comment if there are any solutions for socat as well.
-
yuva over 9 yearsThanks mate, that worked pretty fine. Wasn't being able to find this anywhere else.
-
Ruraj over 9 years:) glad I could help!
-
Foad over 5 yearsDoes
tty0tty
also support mac OS? -
Ruraj almost 5 yearsYou might be able to build it and load the kernel module using
kextutil
, but I have never tried it! -
master_clown almost 5 yearsGorgeous explanation. Every point is nice and neat. Always glad to see such responses