List Serial Ports Linux

serial.tools.list_ports¶

Jan 28, 2010  How do I check and configure serial ports under Linux for various purposes such as modem, connecting null modems or connect a dumb terminal? Linux offers various tools. Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1 and so on. Adblock detected 😱 My website Continue reading 'How To Check and Use Serial Ports Under. What is the proper way to get a list of all available serial ports/devices on a Linux system? In other words, when I iterate over all devices in /dev/, how do I tell which ones are serial ports in the classic way, that is, those usually supporting baud rates and RTS/CTS flow control? The solution would be coded in C.

This module can be executed to get a list of ports (python-mserial.tools.list_ports). It also contains the following functions.

serial.tools.list_ports.comports(include_links=False)
Parameters:include_links (bool) – include symlinks under /dev when they pointto a serial port
Returns:a list containing ListPortInfo objects.

The function returns a list of ListPortInfo objects.

Items are returned in no particular order. It may make sense to sort theitems. Also note that the reported strings are different across platformsand operating systems, even for the same device.

Note

Support is limited to a number of operating systems. On somesystems description and hardware ID will not be available(None).

Under Linux, OSX and Windows, extended information will be available forUSB devices (e.g. the ListPortInfo.hwid string contains VID:PID,SER (serial number), LOCATION (hierarchy), which makes them searchablevia grep(). The USB info is also available as attributes ofListPortInfo.

If include_links is true, all devices under /dev are inspected andtested if they are a link to a known serial port device. These entrieswill include LINK in their hwid string. This implies that the samedevice listed twice, once under its original name and once under linkedname.

Platform:Posix (/dev files)
Platform:Linux (/dev files, sysfs)
Platform:OSX (iokit)
Platform:Windows (setupapi, registry)
serial.tools.list_ports.grep(regexp, include_links=False)
Parameters:
  • regexp – regular expression (see stdlib re)
  • include_links (bool) – include symlinks under /dev when they pointto a serial port
Returns:

an iterable that yields ListPortInfo objects, see alsocomports().

Search for ports using a regular expression. Port name,description and hwid are searched (case insensitive). The functionreturns an iterable that contains the same data that comports()generates, but includes only those entries that match the regexp.

List Serial Ports Linux
class serial.tools.list_ports.ListPortInfo

This object holds information about a serial port. It supports indexedaccess for backwards compatibility, as in port,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 by device. Strings are split into groups of numbers andtext so that the order is “natural” (i.e. com1 < com2 <com10).

Command line usage

Help for python-mserial.tools.list_ports:

Linux Mint List Serial Ports

Examples:

  • List all ports with details:

  • List the 2nd port matching a USB VID:PID pattern:

New in version 2.6.

Changed in version 3.0: returning ListPortInfo objects instead of a tuple

serial.tools.miniterm¶

This is a console application that provides a small terminal application.

Miniterm itself does not implement any terminal features such as VT102compatibility. However it may inherit these features from the terminal it is run.For example on GNU/Linux running from an xterm it will support the escapesequences of the xterm. On Windows the typical console window is dumb and doesnot support any escapes. When ANSI.sys is loaded it supports some escapes.

The default is to filter terminal control characters, see --filter fordifferent options.

Miniterm:

List Active Serial Ports Linux

Command line options can be given so that binary data including escapes forterminals are escaped or output as hex.

Miniterm supports RFC 2217 remote serial ports and raw sockets using URL Handlerssuch as rfc2217://<host>:<port> respectively socket://<host>:<port> asport argument when invoking.

Command line options python-mserial.tools.miniterm-h:

Available filters (--filter option):

  • colorize: Apply different colors for received and echo
  • debug: Print what is sent and received
  • default: remove typical terminal control codes from input
  • direct: do-nothing: forward all data unchanged
  • nocontrol: Remove all control codes, incl. CR+LF
  • printable: Show decimal code for all non-ASCII characters and replace most control codes

Arch Linux List Serial Ports

Miniterm supports some control functions while being connected.Typing Ctrl+T Ctrl+H when it is running shows the help text:

Ctrl+T s suspends the connection (port is opened) and reconnects when akey is pressed. This can be used to temporarily access the serial port with another application, without exiting miniterm. If reconnecting fails it isalso possible to exit (Ctrl+]) or change the port (p).

Linux Serial Terminal

Changed in version 2.5: Added Ctrl+T menu and added support for opening URLs.

Python List Serial Ports Linux

Changed in version 2.6: File moved from the examples to serial.tools.miniterm.

List Serial Ports In Linux

Changed in version 3.0: Apply encoding on serial port, convert to Unicode for console.Added new filters, default to stripping terminal control sequences.Added --ask option.