Question about how to get list of available serial devices ...
martin.pitt at ubuntu.com
Sun Sep 8 02:20:12 PDT 2013
Marcus Priesch [2013-07-22 14:39 +0200]:
> i have a software written in python that needs to know the list of
> available serial devices on the system, including on-board serial
> devices and USB serial adapters.
> in the past i used hal for this and got nice results like this (lshal output):
You get pretty much the same information with libudev these days,
which is the recommended interface not just for enumerating the
current hardware, but also to get notified about any hardware changes.
For C programs you'd just use libudev (or libgudev for GObject-y
stuff), for Python you have the choice between pyudev
(http://pyudev.readthedocs.org/en/latest/) or using GUdev through
>>> from gi.repository import GUdev
>>> client = GUdev.Client.new(subsystems=['tty'])
>>> devs = client.query_by_subsystem('tty')
Then you can iterate over devs and call stuff like .get_device_file()
or .get_property('ID_SERIAL') on those.
Martin Pitt | http://www.piware.de
Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org)
More information about the devkit-devel