PySerial学习系列1--serial.tools

来源:互联网 发布:如何做淘宝详情页 编辑:程序博客网 时间:2024/06/05 20:41

PySerial中Tools工具获取计算机上所有的Port口

   import serial.tools.list_ports后调用serial.tools.list_ports.comports()接口返回计算机上所有的port口信息(当然正对windows用户来讲,也可以调用serial.tools.list_ports_windows.comports()接口),返回的是一个serial.tools.list_ports.ListPortInfo类的列表,该类具体信息:


class serial.tools.list_ports.ListPortInfo

This object holds information about a serial port. It supports indexedaccess for backwards compatibility, as inport, desc,hwid = info.

device

Full device name/path, e.g. /dev/ttyUSB0. This is also theinformation returned as first element when accessed by index.

name

Short device name, e.g. ttyUSB0.

description

Human readable description or n/a. This is also the informationreturned as second element when accessed by index.

hwid

Technical description or n/a. This is also the informationreturned as third element when accessed by index.

USB specific data, these are all None if it is not an USB device (or theplatform does not support extended info).

vid

USB Vendor ID (integer, 0...65535).

pid

USB product ID (integer, 0...65535).

serial_number

USB serial number as a string.

location

USB device location string (“<bus>-<port>[-<port>]...”)

manufacturer

USB manufacturer string, as reported by device.

product

USB product string, as reported by device.

interface

Interface specific description, e.g. used in compound USB devices.

Comparison operators are implemented such that the ListPortInfo objectscan be sorted bydevice. Strings are split into groups of numbers andtext so that the order is “natural” (i.e.com1 < com2 <com10).


——