python输出电脑上所有的串口名的方法

yipeiwu_com6年前Python基础

输出电脑上所有的串口名:

import serial
import serial.tools.list_ports
from easygui import *
 
port_list = list(serial.tools.list_ports.comports())
if len(port_list) <= 0:
  print "The Serial port can't find!"
 
else:
  for i in list(port_list):
 #print i[0] 仅仅输出端口号,像COM1、COM3、COM9

print i[1]

输出一个串口名:

# -*- coding: utf-8 -*
 
import serial
import serial.tools.list_ports
 
port_list = list(serial.tools.list_ports.comports())
 
if len(port_list) <= 0:
  print "The Serial port can't find!"
   
else:
  port_list_0 =list(port_list[0])
 
  port_serial = port_list_0[0]
 
  ser = serial.Serial(port_serial,9600,timeout = 60)
 
  print "check which port was really used >",ser.name

以上这篇python输出电脑上所有的串口名的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 3.x基于Xml数据的Http请求方法

Python 3.x基于Xml数据的Http请求方法

1. 前言 由于公司的一个项目是基于B/S架构与WEB服务通信,使用XML数据作为通信数据,在添加新功能时,WEB端与客户端分别由不同的部门负责,所以在WEB端功能实现过程中,需要自己发...

Jupyter中直接显示Matplotlib的图形方法

Jupyter中直接显示Matplotlib的图形方法

一.使用以下cmd命令生成ipython_config.py 文件 ipython profile create 二.在ipython_config.py中添加以下代码 c....

python运用sklearn实现KNN分类算法

python运用sklearn实现KNN分类算法

KNN(K-Nearest-Neighbours Classiflication)分类算法,供大家参考,具体内容如下 最简单的分类算法,易于理解和实现 实现步骤:通过选取与该点距离最近...

使用Python制作一个打字训练小工具

使用Python制作一个打字训练小工具

一、写在前面   说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU。      别人眼中的程序员:飞快的敲击键盘、酷炫的切...

Python3 Tkinkter + SQLite实现登录和注册界面

Python3 Tkinkter + SQLite实现登录和注册界面

本文实例为大家分享了Python3 Tkinkter + SQLite 实现登录和注册界面,供大家参考,具体内容如下 Ubuntu14 + Python3.4 + Pycharm2018...