输出电脑上所有的串口名:
1
2
3
4
5
6
7
8
9
10
|
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): |
1
|
#print i[0] 仅仅输出端口号,像COM1、COM3、COM9 |
print i[1]
输出一个串口名:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# -*- 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输出电脑上所有的串口名的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。