最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - Python pyserial can't access com0com virtual serial ports even though they appear in Device Manager and com0co

programmeradmin5浏览0评论

I've set up virtual COM ports with com0com (COM20 and COM21), but I'm having trouble accessing them through Python's pyserial.

What I've tried

I can successfully create the port pair using com0com's setupc.exe:

> setupc.exe install PortName=COM20 PortName=COM21

The virtual port pair is visible in the com0com GUI:

and they appear under com0com - serial port emulators in device manager:

But when I try to access these ports with pyserial, I get a FileNotFoundError:

import serial
import serial.tools.list_ports

# List available ports
print("Available COM ports:")
for port in serial.tools.list_portsports():
    print(f"  {port.device}: {port.description}")

# Try to open the virtual port
try:
    ser = serial.Serial('COM20', 9600, timeout=1)
    print("Successfully opened COM20")
    ser.close()
except Exception as e:
    print(f"Error: {e}")

Output:

Available COM ports:
  COM7: Standard Serial over Bluetooth link (COM7)
  COM3: Intel(R) Active Management Technology - SOL (COM3)
  COM6: Standard Serial over Bluetooth link (COM6)
Error: could not open port 'COM20': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

Environment

  • Windows 10
  • Python 3.12.2
  • pyserial 3.5
  • com0com 3.0.0.0
  • Running script with administrator privileges

Questions

  1. Why aren't the com0com virtual ports appearing in the pyserial port list?
  2. How can I make pyserial recognize and use com0com virtual ports?
  3. Is there a delay or extra step needed after creating ports before they're accessible?

I've already tried:

  • Running as administrator
  • Creating ports with higher numbers (COM20, COM21)
  • Verifying the ports in Device Manager and com0com GUI
  • Restarting the computer

Any insights or alternative approaches would be greatly appreciated.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论