Reputation: 557
If I have a USB modem that I am accessing using Python pyserial module, it requires the device to be identified '/dev/ttyACM0 for example. If the modem is attached to a USB hub it no longer appears in /dev/tty...
How do identify it programmatically from my Python code so regardless of whether it has been changed or not, or the machine rebooted I can locate the modem?
Note: I can always see the device using lsusb, but if it is attached to a USB hub it does not appear as /dev/tty... device
Upvotes: 2
Views: 4902
Reputation: 7098
Instead of doing some voodoo in Python, try writing a udev rule which gives your device a much more useful name like /dev/my-serial-thingy
. Using that from Python is way easier.
Upvotes: 1
Reputation: 328754
This sounds like a bug in the linux kernel. If you can, try a more recent version.
If that fails, check the last few lines of the output of dmesg
or in the file /var/log/messages
(the latter depends on your distribution; if that file doesn't exist or doesn't contain what you're looking for, then check the other files in /var/log
; sorting by time with ls -rt
helps).
After identifying the device, you might see a pattern.
Another approach is the major and minor number. If you run ls -l /dev
, you'll see output like this:
crw--w---- 1 root tty 4, 0 2011-12-19 09:15 tty0
The c
means "character device" and the 4, 0
means it's the console device unit 0.
The 4
is the major number which identifies the type of device. See /proc/devices
for a list of major numbers and the respective device drivers.
If you plug in the model directly, note the major number. After plugging it into a hub, try to find devices with the same number.
Upvotes: 1