2017-07-28 136 views
1

我在Windows 7上使用Pyserial 2.6,我试图连接到Tiva C Series Launchpad。它在设备管理器下列为COM5,并且我已经成功下载并安装了所有必要的驱动程序。我使用TI的CCS对板进行编程,并且所有连接都可以正常工作。Pyserial COM端口问题

但是,由于某些原因,当我实际尝试使用pyserial访问它时,它不被识别。我运行:

python -m serial.tools.list_ports 

我得到:

COM1 
COM3 
COM4 
3 ports found 

但我不觉得COM5 ......这是我的全凭静脉麻醉的。我不知道发生了什么事。我不知道发生了什么...有什么我做错了吗?我链接了安装Pyserial的安装说明。还有什么需要做的..?

非常感谢你

+1

设备管理器中列出了哪些端口?命令行告诉你有关[可用的COM端口](https://superuser.com/questions/835848/how-to-view-serial-com-ports-but-not-through-device-manager)?什么'serial.tools.list_ports.comports()'给你建议[这里](https://stackoverflow.com/a/29813811/3991125) – albert

回答

1

那么这可以是任何东西。下面的代码对我的作品:

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 

也许搜索年初放弃对。

+0

有趣...当我运行这段代码时,什么也没有发生。什么都不输出到屏幕......有趣.. –

+0

@JohnLexus你有设置调试吗?你是否构建了调用测试代码来打印返回值? – starturtle