Windows
Set up PySerial on Windows with COM port discovery, driver installation, permissions, and Device Manager troubleshooting.
Windows uses COM ports (COM1, COM3, etc.) instead of /dev/tty*. PySerial handles this automatically.
Quick Windows Setup
Install Python and PySerial
Download Python from python.org and check "Add Python to PATH" during installation. Then open Command Prompt:
pip install pyserialFind COM Ports
import serial.tools.list_ports
ports = serial.tools.list_ports.comports()
for port in ports:
print(f"{port.device}: {port.description}")
if port.vid:
print(f" VID:PID = {port.vid:04X}:{port.pid:04X}")Test Connection
import serial
ser = serial.Serial('COM3', 9600, timeout=1)
ser.write(b'Hello Windows!')
response = ser.read(100)
print(f"Received: {response}")
ser.close()Log serial data automatically
TofuPilot records test results from your PySerial scripts, tracks pass/fail rates, and generates compliance reports. Free to start.
COM Port Discovery
import serial.tools.list_ports
def find_com_ports():
"""List COM ports grouped by chip type."""
ports = serial.tools.list_ports.comports()
for port in ports:
desc = port.description.lower()
chip = "Unknown"
if 'arduino' in desc:
chip = "Arduino"
elif 'ftdi' in desc or port.vid == 0x0403:
chip = "FTDI"
elif 'prolific' in desc or port.vid == 0x067B:
chip = "Prolific"
elif 'ch340' in desc or 'ch341' in desc:
chip = "CH340"
elif 'cp210' in desc:
chip = "CP210x"
print(f"{port.device}: {port.description} [{chip}]")
if port.vid:
print(f" VID:PID = {port.vid:04X}:{port.pid:04X}")
find_com_ports()# List COM ports
Get-WmiObject Win32_SerialPort | Select-Object DeviceID, Description, Status
# More detailed info (includes USB-serial adapters)
Get-WmiObject Win32_PnPEntity | Where-Object {$_.Caption -match "COM\d+"} |
Select-Object Caption, DeviceID, Status, ManufacturerCommand Prompt alternative:
mode
wmic path Win32_SerialPort get DeviceID,Description,StatusOpen Device Manager with Win+X or devmgmt.msc.
Check these sections:
- Ports (COM & LPT): active COM ports
- Universal Serial Bus controllers: USB-serial adapters
- Other devices: unrecognized hardware (needs driver)
Troubleshooting indicators:
- Yellow triangle: driver issue
- Red X: disabled device
- Question mark: unknown device
Driver Installation
USB-to-serial adapters need drivers on Windows. Download from the chip manufacturer for best compatibility.
| Chip | Download | Notes |
|---|---|---|
| FTDI FT232/FT234X | ftdichip.com/drivers | Most reliable |
| CH340/CH341 | Search "CH341SER driver" | Common on cheap boards |
| Prolific PL2303 | prolific.com.tw | Clone chips cause issues, use official drivers only |
| CP210x | silabs.com/developers | Good Windows support |
Identify Your Chip
Connect the device. If it shows in "Ports (COM & LPT)" you already have the driver. If it shows in "Other devices", note the Hardware ID (right-click, Properties, Details) and install the matching driver above.
Install and Verify
- Run the driver installer as Administrator.
- Restart if prompted.
- Reconnect the device and confirm it appears under "Ports".
Windows-Specific Configuration
Registry COM Port Info
import winreg
def get_registry_com_ports():
"""Read COM port mappings from the Windows registry."""
key_path = r"HARDWARE\DEVICEMAP\SERIALCOMM"
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path)
i = 0
while True:
try:
name, value, _ = winreg.EnumValue(key, i)
print(f"{value} -> {name}")
i += 1
except OSError:
break
winreg.CloseKey(key)
except OSError as e:
print(f"Registry read failed: {e}")
get_registry_com_ports()Buffer Sizes
import serial
ser = serial.Serial('COM3', 115200, timeout=1)
# Windows lets you request specific buffer sizes
ser.set_buffer_size(rx_size=8192, tx_size=4096)
print(f"Buffers configured, timeout={ser.timeout}s")
ser.close()Disable USB Selective Suspend
At high baud rates, Windows USB power management can cause dropped data. Disable it in an elevated PowerShell:
powercfg /setacvalueindex SCHEME_CURRENT `
2a737441-1930-4402-8d77-b2bebba308a3 `
48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
powercfg /setactive SCHEME_CURRENTTroubleshooting
Permission Denied
PermissionError: [Errno 13] usually means another program has the port open.
- Close Arduino IDE, PuTTY, HyperTerminal, or any serial monitor.
- Check Task Manager for processes holding the port.
- If nothing obvious, try running Python as Administrator.
- Some antivirus software blocks serial port access. Add Python to the exclusions list.
COM Port Keeps Changing
USB-serial adapters get a new COM number each time they're plugged into a different USB port.
- Open Device Manager, right-click the port, Properties, Port Settings, Advanced.
- Assign a fixed COM port number (avoid COM1-4, often reserved).
- To clean up phantom ports: set environment variable
DEVMGR_SHOW_NONPRESENT_DEVICES=1, open Device Manager, View, Show hidden devices, and uninstall grayed-out COM entries.
Port Won't Open
import serial
import serial.tools.list_ports
import platform
print(f"Windows {platform.win32_ver()[0]} {platform.win32_ver()[1]}")
print(f"Python {platform.python_version()}")
print(f"PySerial {serial.__version__}")
ports = list(serial.tools.list_ports.comports())
print(f"\n{len(ports)} serial port(s) found:")
for port in ports:
print(f"\n {port.device}: {port.description}")
if port.vid:
print(f" VID:PID: {port.vid:04X}:{port.pid:04X}")
try:
s = serial.Serial(port.device, 9600, timeout=0.1)
print(f" Status: opens OK")
s.close()
except PermissionError:
print(f" Status: permission denied (another app has it open?)")
except serial.SerialException as e:
print(f" Status: error - {e}")If no ports appear at all, the driver is missing. Check "Other devices" in Device Manager and install the correct driver from the table above.