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

yipeiwu_com7年前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 音频生成器的实现示例

Python 音频生成器的实现示例

使用Python生成不同声音的音频 第一步先去百度AI中注册账号,在控制台中创建语音技术应用,获取AppID,API Key,Secret Key 第二步 引用 from tkin...

Python Socket实现简单TCP Server/client功能示例

本文实例讲述了Python Socket实现简单TCP Server/client功能。分享给大家供大家参考,具体如下: 网络上关于socket的介绍文章数不胜数。自己记录下学习的点点滴...

python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法

python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法

1. test.txt文件,数据以逗号分割,第一个数据为x坐标,第二个为y坐标,数据如下:1.1,2 2.1,2 3.1,3 4.1,5 40,38 42,41 43,42 2....

对Python闭包与延迟绑定的方法详解

Python闭包可能会在面试或者是工作中经常碰到,而提到Python的延迟绑定,肯定就离不开闭包的理解,今天总结下 关于闭包的概念以及一个延迟绑定的面试题。 Python闭包 1、什么是...

python读取.mat文件的数据及实例代码

首先导入scipy的包 from scipy.io import loadmat 然后读取 m = loadmat("F:/__identity/activity/论文/data/D00...