Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This is part of a series of blog posts on the Windows Subsystem for Linux (WSL). For background information you may want to read the architectural overview, introduction to pico processes, WSL system calls, and WSL file system blog posts.
Posted on behalf of Stephen Hufnagel
In Windows Insider build #16176 WSL now allows access to serial devices (COM ports).
This blog post will describe how to use this feature and the work that was involved in exposing this functionality within WSL.
On Windows, COM ports are named COM1 through COM256. On Linux, serial devices can have arbitrary names but are typically character devices with a major number of 4 and a minor number from 64 to 256 represented by /dev/ttyS0 through /dev/ttyS191. By default init will populate this mapping using the mknod
system call. Alternate mknod
mappings can be created at runtime if needed.
In WSL, the lxcore driver maps COM ports to Linux devices by the COM port number so /dev/ttyS<N> is tied to COM<N>. More specifically, the mapping is on the minor number, so minor number 65 (/dev/ttyS1) is COM1, 66 (/dev/ttyS2) is COM2, and so forth. Since pty, tty, and ttyS share a terminal library code base, ttyS will behave similarly but also support the following termios settings which are simply mapped to Windows serial driver ioctls:
To use your favorite serial tool\library in WSL, just map from the COM port of the device using device manager or the SERIALCOMM registry key (HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM).
Figure 1. This diagram shows the basic architecture of WSL exposes Windows COM ports as serial devices in WSL.
The following scenarios were tested and confirmed to be working:
cu
toolPlease note that some serial drivers have known bugs. These issues exist on both native Windows and within WSL.
The following areas are known to not work. We are tracking updates to future Windows Insider builds to address them.
On a Windows 10 machine where a Raspberry Pi is connected on COM5 connect using the following steps:
sudo chmod 666 /dev/ttyS5
- This is required since cu changes it's uid which drops capabilities even when running as root. Not all serial programs have the same behavior.stty -F /dev/ttyS5 -a
. Optionally check your current serial settings before updating.stty -F /dev/ttyS5 sane 9600
stty -F /dev/ttyS5 raw 9600 -echo -echoe -echok -echoctl -echoke -iexten -onlcr cs8 crtscts
cu -l /dev/ttyS5 -s 9600
Please let us know on our Github about the specific serial scenarios that you are trying. Your feedback helps us prioritize what we should focus on next.
picocom
use?Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in