Paul, you are right:

in /sys/bus/usb-serial you will find only UART-over-USB devices, which are 
named /dev/ttyUSB%d

/dev/ttyACM%d are instead "real" modems, conforming to the USB "Communication 
Device Class
Abstract Control Model" (USB CDC ACM).  (This means that they should respond to 
AT commands, and so on...)

My "one liner" will never catch the ttyACM devices, but only the ttyUSB ones. 
Of course, multi-port devices have a many-to-one mapping between tty devices 
and USB bus/dev numbers, so this should rise no concern.

To recap:

/sys/bus/usb/devices:           symlinks to USB devices
/sys/bus/usb-serial/devices:    symlinks to UART-over-USB devices
/sys/class/tty:                         symlinks to serial (tty) devices

I would suggest starting the search in /sys/class/tty or /sys/bus/usb/devices, 
and not in /sys/devices, but of course this would require to change your logic 
in order to follow symlinks.

S.

On 07 Oct 2014, at 04:26, Paul Alfille <paul.alfi...@gmail.com> wrote:

> Hi Stefano,
> 
> /sys/bus/usb-serial/devices doesn't seem to pick up ttyACM? devices, but does 
> discover some devices I missed.
> 
> Actually the two methods give quite different results on my machine:
> 
> #-----tty2usb output = 6 devices--------------
> 
> paul@hz tty2usb-code$ ./tty2usb 
> List tty -> USB pairings
> TTY=ttyACM0bus=1dev=10USB=04D8:F897
> TTY=ttyUSB0bus=3dev=3USB=0403:6001
> TTY=ttyUSB1bus=1dev=6USB=0403:6001
> TTY=ttyUSB2bus=3dev=14USB=0711:0230
> TTY=ttyUSB7bus=1dev=7USB=1A86:7523
> TTY=ttyUSB8bus=1dev=4USB=10C4:EA60
> 
> #----- /sys/bus/usb-serial/devices gives USB0-8 and no ACM0 and repeated USB 
> addresses --------------------
> 
> paul@hz tty2usb-code$  for i in /sys/bus/usb-serial/devices/*; do echo 
> TTY=$(basename $i) bus=$(< $i/../../busnum) dev=$(< $i/../../devnum) USB=$(< 
> $i/../../idVendor):$(< $i/../../idProduct); done
> TTY=ttyUSB0 bus=3 dev=3 USB=0403:6001
> TTY=ttyUSB1 bus=1 dev=6 USB=0403:6001
> TTY=ttyUSB2 bus=3 dev=14 USB=0711:0230
> TTY=ttyUSB3 bus=3 dev=9 USB=06cd:010a
> TTY=ttyUSB4 bus=3 dev=9 USB=06cd:010a
> TTY=ttyUSB5 bus=3 dev=9 USB=06cd:010a
> TTY=ttyUSB6 bus=3 dev=9 USB=06cd:010a
> TTY=ttyUSB7 bus=1 dev=7 USB=1a86:7523
> TTY=ttyUSB8 bus=1 dev=4 USB=10c4:ea60
> 
> #----- lsusb shows -------------------------
> 
> paul@hz tty2usb-code$ lsusb | sort 
> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
> Bus 001 Device 003: ID 1a40:0201 Terminus Technology Inc. FE 2.1 7-port Hub
> Bus 001 Device 004: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART 
> Bridge / myAVR mySmartUSB light
> Bus 001 Device 005: ID 0957:0718 Agilent Technologies, Inc. 
> Bus 001 Device 006: ID 0403:6001 Future Technology Devices International, Ltd 
> FT232 USB-Serial (UART) IC
> Bus 001 Device 007: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
> Bus 001 Device 008: ID 047d:1003 Kensington Orbit TrackBall
> Bus 001 Device 009: ID 077d:0410 Griffin Technology PowerMate
> Bus 001 Device 010: ID 04d8:f897 Microchip Technology, Inc. 
> Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
> Bus 002 Device 003: ID 0409:005a NEC Corp. HighSpeed Hub
> Bus 002 Device 004: ID 046d:c408 Logitech, Inc. Marble Mouse (4-button)
> Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 003 Device 002: ID 05e3:0608 Genesys Logic, Inc. Hub
> Bus 003 Device 003: ID 0403:6001 Future Technology Devices International, Ltd 
> FT232 USB-Serial (UART) IC
> Bus 003 Device 004: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
> Bus 003 Device 005: ID 05e3:0608 Genesys Logic, Inc. Hub
> Bus 003 Device 006: ID 08bb:2904 Texas Instruments PCM2904 Audio Codec
> Bus 003 Device 007: ID 0409:0050 NEC Corp. 7-port hub
> Bus 003 Device 008: ID 0c45:1700 Microdia 
> Bus 003 Device 009: ID 06cd:010a Keyspan USA-49W serial adapter
> Bus 003 Device 011: ID 07a6:8515 ADMtek, Inc. AN8515 Ethernet
> Bus 003 Device 012: ID 0451:2036 Texas Instruments, Inc. TUSB2036 Hub
> Bus 003 Device 013: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
> Bus 003 Device 014: ID 0711:0230 Magic Control Technology Corp. MCT-232 
> Serial Port
> Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> 
> It turns out the truth is somewhere in between. The keyspan 4-port serial 
> adapter was getting excluded by my logic, but is you were finding it 
> completely correctly. The ACM device is a valid 1-wire Bus Master (Hobby 
> Boards) that gets missed by your script.
> 
> I'll fix up tty2usb but still use the current algorithm unless you can help 
> me with ACM devices.
> 
> Paul
>  
> 
> (disclaimer: I'm no linux kernel expert, so my post may turn out to be 
> inaccurate).
> 
> 
> AFAIK sysfs is a linux kernel feature, independent of the availability of 
> udevd, so navigating /sys/ is the "canonical" way of obtaining info on kernel 
> objects and attributes. (And yes, it is the kernel that enumerates USB 
> devices and then notifies udevd)
> 
> However Tiger is right, the search heuristics should be more accurate/simple.
> 
> On my linux system I have
> 
> $ tree /sys/bus/usb/devices 
> /sys/bus/usb/devices
> |-- 1-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-0:1.0
> |-- 1-5 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-5
> |-- 1-5.2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5.2
> |-- 1-5.2:1.0 -> 
> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5.2/1-5.2:1.0
> |-- 1-5:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0
> |-- 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0
> |-- 3-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3/3-0:1.0
> |-- 3-2 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3/3-2
> |-- 3-2:1.0 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3/3-2/3-2:1.0
> |-- 4-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.2/usb4/4-0:1.0
> |-- usb1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1
> |-- usb2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2
> |-- usb3 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3
> `-- usb4 -> ../../../devices/pci0000:00/0000:00:1d.2/usb4
> 
> and
> 
> $ tree /sys/bus/usb-serial/devices 
> /sys/bus/usb-serial/devices
> `-- ttyUSB0 -> 
> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5.2/1-5.2:1.0/ttyUSB0
> 
> 
> So a possible alternative way of finding the pairing could be:
> 
> foreach symlink in /sys/bus/usb-serial/devices
>       navigate upwards the symlink until the relevant info (busnum, devnum, 
> idProduct, idVendor, etc.) is found
> 
> For example I would code this in bash as
> 
> $ for i in /sys/bus/usb-serial/devices/*; do echo TTY=$(basename $i) bus=$(< 
> $i/../../busnum) dev=$(< $i/../../devnum) USB=$(< $i/../../idVendor):$(< 
> $i/../../idProduct); done
> TTY=ttyUSB0 bus=1 dev=10 USB=0403:6001
> 
> 
> (Please note that for navigating upwards I do not break the path but just add 
> '/..')
> 
> 
> Bye
>  
> Stefano
> 
> 
> On 06 Oct 2014, at 13:45, Der Tiger <der.tiger.o...@arcor.de> wrote:
> 
>> Hi,
>> 
>>> 1. Recursively search /sys/devices for "busnum" (which seems to
>>> indicate a USB device)
>> Which, IMHO, would suggest devd or udevd to be required, since the
>> enumeration is done by the daemon.
> 
> 
> ------------------------------------------------------------------------------
> Slashdot TV.  Videos for Nerds.  Stuff that Matters.
> http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________
> Owfs-developers mailing list
> Owfs-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/owfs-developers
> 
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk_______________________________________________
> Owfs-developers mailing list
> Owfs-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/owfs-developers

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to