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.
It is serial port 2 (- /dev/ttymxc2) on APF51; it is debug serial port 0 (- /dev/ttyAM0 (2.6.35 kernel) or /dev/ttyAMA0 (3.x kernels)) on APF28; So, without software modifications, this port is not available to connect a MODEM or any other RS-232 device. If you want to use it as a normal serial port on Linux then: be sure that your device won. For settings specific to Linux distributions, see Serial console Linux distribution availability. Your VM or virtual machine scale set instance must be configured for serial output on ttys0. This is the default for Azure images, but you will want to double check this on custom images. Details below. Setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on. The server must be configured to use a serial console so there are a couple of places to check. Find a drivers license number online. The kernel setup involves adding the 'console' parameter to the command line of your kernel. For example adding 'console=ttyS0,9600' tells the kernel to send messages to the first serial port (/dev/ttyS0, COM1 in DOS/Windows terms) at 9600 baud. I was using the suggestions in this post to write to a serial port, then using the info from another post to read from the port, with mixed results. I found that using screen is an 'easier' solution, since it opens a terminal session directly with that port.
Posted on behalf of Stephen Hufnagel
Summary
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. Beauty beast 123 movies. 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:
- Standard baud rates - B*
- Stop bits - CSTOPB
- Word length - CSIZE
- Parity checking - PARENB, PARODD, CMSPAR, INPCK
- Software flow control - IXON, IXOFF
- Hardware flow control - CRTSCTS, CLOCAL
- Control characters - VSTART, VSTOP, VEOF
To use your favorite serial toollibrary in WSL, just map from the COM port of the device using device manager or the SERIALCOMM registry key (HKEY_LOCAL_MACHINEHARDWAREDEVICEMAPSERIALCOMM).
Figure 1. This diagram shows the basic architecture of WSL exposes Windows COM ports as serial devices in WSL.
Scenarios
The following scenarios were tested and confirmed to be working: https://dbentrancement.weebly.com/bluetooth-usb-host-controller-download.html.
- Programming pixhawk light controller - Thanks @lovettchris!
- Connecting to Raspberry Pi 2 serial terminal using the
cu
tool - Transferring data on various serial configurations:
- Hyper-V virtual COM port
- FTDI USB to serial converter
- Prolific USB to serial converter
- Physical COM port
Please 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.
- Using legacy raw ioctls instead TCGETS or TCSETS* to configure and query the serial device
- Screen and minicom depend on the above so they do not currently work as a serial terminal, but cu is an alternative.
Example
On a Windows 10 machine where a Raspberry Pi is connected on COM5 connect using the following steps:
Linux See Serial Port Settings
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.- Set your serial settings, depending on your application this usually will be raw or sane. Either one seems to work fine with cu:
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
- Hit enter to refresh the cu console
Feedback
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.
Linux Change Serial Port Settings
Start by going to the Device Manager. Once there do the following:
Expand the Ports ‘(COM& LPT)’
You should be looking at something like this:
As you can see Windows has set the port to COM10. However many legacy applications expect the port to be between 1-4. Let’s change that:
Right click on the device and click on ‘Properties’.
Click on ‘Port Settings’. Then click on ‘Advanced…’.
Once you’re in ‘Advanced Settings for COM10’ on the bottom you can see the ‘COM Port Number: COM10’. Click on that to change it to the lowest possible number (between 1-4).
Then click ‘OK’ on all open Property Windows.
Now the device should look like this:
Expand the Ports ‘(COM& LPT)’
You should be looking at something like this:
As you can see Windows has set the port to COM10. However many legacy applications expect the port to be between 1-4. Let’s change that:
Right click on the device and click on ‘Properties’.
Click on ‘Port Settings’. Then click on ‘Advanced…’.
Once you’re in ‘Advanced Settings for COM10’ on the bottom you can see the ‘COM Port Number: COM10’. Click on that to change it to the lowest possible number (between 1-4).
Then click ‘OK’ on all open Property Windows.
Now the device should look like this: