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
This can be done by connecting the serial port of the Raspberry PI to a RS-232 adapter and then to the serial port of a PC; or a USB to serial converter cable plugged into the PC. In this article, the Raspberry PI serial port is connected to a Linux PC running minicom – terminal emulation software that connects to the serial port. Minicom is a communication program which somewhat resembles the shareware program TELIX but is free with source code and runs under most unices. Features include dialing directory with auto-redial, support for UUCP-style lock files on serial devices, a separate script language interpreter, capture to file, multiple users with individual configurations, and more.
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. 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:
- 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:
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.
Created on: 25 March 2014
The Raspberry PI can be operated without a network connection, keyboard, mouse and screen.
This can be done by connecting the serial port of the Raspberry PI to a RS-232 adapter and then to the serial port of a PC; or a USB to serial converter cable plugged into the PC.
In this article, the Raspberry PI serial port is connected to a Linux PC running minicom – terminal emulation software that connects to the serial port.
Commands can be sent to the Raspberry PI from minicom as if entering commands from a keyboard plugged into the RPI board.
Windows users go to the Windows version of this article.
Installing minicom
On a Debian based Linux distribution such as Ubuntu or Mint, minicom can be installed from the command prompt:
Connecting the Linux PC to the Raspberry PI via the Serial Port
This video shows how to connect a USB to serial port cable to a RS-232 adapter board that is plugged into the Raspberry PI. The command line of the Raspberry PI is then accessed through minicom. The Raspberry PI is then shut down from the command line.
Connecting to the Serial Port and Running minicom
Connect the USB to serial adapter to the PC and then to the Raspberry PI through the Raspberry PI RS-232 adapter board (Or if the PC has a serial port, connect it to the adapter board).
To start minicom, open a command line terminal and enter:
This assumes that the device name of the USB to serial adapter cable is /dev/ttyUSB0.
Switch Flow Control Off in minicom
In minicom, press Ctrl + A then press Z. Now press O to configure minicom.
In the menu that appears, press the down arrow to move to Serial port setup and the press then Enter key.
Serial Port Arduino
Press F to switch flow control off and then press the Enter key.
Scroll down to Exit and press Enter.
The Raspberry PI can now be powered up. Messages from the Raspberry PI will be displayed in minicom.
Logging In and Entering Commands
After booting, the login prompt from the Raspberry PI will be displayed in minicom. Log in as normal.
Minicom Serial Port Setup Ubuntu
Commands can now be entered just as if a keyboard were connected directly to the Raspberry PI.
Minicom Serial Port Settings
Please enable JavaScript to view the comments powered by Disqus.Minicom Serial Port Test
Raspberry PI