我正在使用Pyserial 2.6在 Windows 7 上,我正在尝试连接到 Tiva C Series Launchpad 。它在设备管理器下列为 COM5,并且我已成功下载并安装了所有必需的驱动程序。我使用 TI 的 CCS 对电路板进行编程,一切都连接并工作正常。
但是,由于某种原因,当我实际尝试使用 pyserial 访问它时,它无法被识别。我跑:
python -m serial.tools.list_ports
我得到:
COM1
COM3
COM4
3 ports found
但是我没有找到 COM5...我的 Tiva 就在那里。我不知道发生了什么事。我不确定发生了什么事...我做错了什么吗?我链接了安装 Pyserial 时遵循的安装说明。还有什么需要做的吗..?
非常感谢
最佳答案
嗯,这可以是任何东西。以下代码对我有用:
def _scan_com_ports(self):
"""
Scan for available COM ports. return a list of tuples (num, name)
"""
available = []
for i in range(10):
try:
s = serial.Serial(i) # if not existing an exception occured
available.append((i, s.portstr))
s.close() # explicit close 'cause of delayed GC in java
if debug:
print("Com:", i + 1)
except serial.SerialException:
if debug:
print("Not to open", i)
# needed to cope with comp witch are not to open
pass
return available
可能搜索很早就放弃了。
关于python - Pyserial COM 端口问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45381558/