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

yipeiwu_com5年前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 subprocess模块学习总结

一、subprocess以及常用的封装函数运行python的时候,我们都是在创建并运行一个进程。像Linux进程那样,一个进程可以fork一个子进程,并让这个子进程exec另外一个程序。...

Python中import导入上一级目录模块及循环import问题的解决

import上一级目录的模块 python中,import module会去sys.path搜索,sys.path是个列表,并且我们可以动态修改。 要import某个目录的module,...

对pandas进行数据预处理的实例讲解

参加kaggle数据挖掘比赛,就第一个赛题Titanic的数据,学习相关数据预处理以及模型建立,本博客关注基于pandas进行数据预处理过程。包括数据统计、数据离散化、数据关联性分析 引...

Python代码生成视频的缩略图的实例讲解

Reddit 上目前充斥着各种机器人账号,官方也非常支持这种行为,只要不是无意义的发言,机器人多了还能增加活跃度,吸引真人用户一起来各抒己见,比如说每周都有的一个“烦人的星期二”的帖子,...

Python中将字典转换为列表的方法

Python中将字典转换为列表的方法

说明:列表不可以转换为字典 ①转换后的列表为无序列表 a = {'a' : 1, 'b': 2, 'c' : 3} #字典中的key转换为列表 key_value = list(a...