LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-03-2014, 01:56 AM   #16
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,655

Rep: Reputation: Disabled

Never worry, LQ works as a resource of knowledge, so when an old thread is amended with added facts it may help others who have problems with similar aspects. Google often digs up old threads.

"usb-devices", huh? I'll go and dig it up tonight at home. Thanks.
 
Old 03-03-2014, 08:28 AM   #17
rtmistler
Senior Member
 
Registered: Mar 2011
Location: Milford, MA. USA
Distribution: MontaVista, Ubuntu, MINT
Posts: 1,085
Blog Entries: 7

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
Agreed, the original question didn't specify what type of device they were trying to use. USB serial shows up one way, USB network adapter shows up another way. Yes, they all show up via the lsusb command, but to really be able to use the device you may need to reference different files.

Most of my experiences are with USB serial. USB network adapters either work or don't and they show up in the list of available networks. Similarly a certain bluetooth device we used either responds to the config request, or it doesn't, but little experience in detecting multiple of either network or bluetooth.

As far as detecting insertion of a hard drive or thumbstick, I've not done that via programming; however I'm sure there are ways, it's all about the files, which is to me a core behavior of Linux.

For serial devices of the category /dev/ttyUSB# I typically use the usbserial file:
Code:
cat /proc/tty/driver/usbserial 
usbserinfo:1.0 driver:2.0
0: module:ftdi_sio name:"FTDI USB Serial Device" vendor:0403 product:6006 num_ports:1 port:1 path:usb-musb-hdrc.1.auto-1.3
1: module:ftdi_sio name:"FTDI USB Serial Device" vendor:0403 product:6001 num_ports:1 port:1 path:usb-musb-hdrc.1.auto-1.4
In this case we have chosen to program one type of device to be a different product ID because we control the manufacture of the device.

Whereas in the case of multiple say STM32 USB serial drivers, we're again fortunate that we have different vendor/product values, so we obtain the list of ttyACM serial devices by looking at the /sys/class/tty tree and grep'ing for ACM, and then create another list by grep'ing for the PRODUCT line from the /sys/class/tty/$ACM_DEVICE/device/uevent file. From that point we have the device to resource mapping. I've found that this does not work with /dev/ttyUSB devices, most of which are FTDI serial devices in our system, they end up not having a PRODUCT line in their uevent file.

This is all in a controlled environment though. The systems will always have certain boards and certain configurations, not known at boot time, but also there won't be added devices of unknown origin which can confuse detection.
 
Old 03-03-2014, 11:16 AM   #18
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,655

Rep: Reputation: Disabled
Hmm.

Do you know how to interpret the output of "usb-devices"? The man page doesn't say...
Code:
...
T:  Bus=06 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0d46 ProdID=3010 Rev=00.40
S:  Manufacturer=KOBIL Systems
S:  Product=KOBIL Class 3 Reader
S:  SerialNumber=SD09B320404
C:  #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=200mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=0b(scard) Sub=00 Prot=00 Driver=(none)
...
I'm at a loss with most of the abbreviations.

<edit>@rtmistler I'm only partly understandig what you write, you are way more of an expert here than I'll ever be. Thanks anyhow </edit>

Last edited by JZL240I-U; 03-03-2014 at 11:26 AM.
 
Old 03-03-2014, 11:22 AM   #19
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,655

Rep: Reputation: Disabled
Slightly off topic: Does anyone here know how to read out the status-register(?) of an USB-device? In particular I want to read the momentary status of the overcurrent-condition bit. Thanks, and sorry for the aside...
 
Old 03-03-2014, 12:27 PM   #20
rtmistler
Senior Member
 
Registered: Mar 2011
Location: Milford, MA. USA
Distribution: MontaVista, Ubuntu, MINT
Posts: 1,085
Blog Entries: 7

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
Quote:
Originally Posted by JZL240I-U View Post
Hmm.

Do you know how to interpret the output of "usb-devices"? The man page doesn't say...
Code:
...
T:  Bus=06 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0d46 ProdID=3010 Rev=00.40
S:  Manufacturer=KOBIL Systems
S:  Product=KOBIL Class 3 Reader
S:  SerialNumber=SD09B320404
C:  #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=200mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=0b(scard) Sub=00 Prot=00 Driver=(none)
...
I'm at a loss with most of the abbreviations.

<edit>@rtmistler I'm only partly understandig what you write, you are way more of an expert here than I'll ever be. Thanks anyhow </edit>
usb-devices is a script, use "which usb-devices" to see where it is, likely it is in /usr/bin, then view the script. It uses functions, if you look at the bottom the script is about 4 lines:
Code:
for device in /sys/bus/usb/devices/usb*
do
	print_device $device 0 0 0
done
And the print_device function, earlier in the file does all the formatting of the output.

Notice that you can perform and ls of the /sys/bus/usb/devices tree to see the device designators for the USB bus and devices. Pretty much these names and numbers appear in your system log as it detects and configures USB devices. There also is a manpage for usb-devices. If that's not installed on your system, here is a reference manpage; usb-devices. Notice also that this command refers you to lsusb(8) as well as usbview(8) - no link found and I don't have usbview on my systems.

But while these shell scripts or commands are useful to the user, and they are intended to be. A main part of Linux is files. Almost every interface is some type of file descriptor or handle. The /proc tree contains all relevant information about processes and drivers. The /sys tree contains all relevant information about your system. These trees are pretty involved; and I'm no expert. I sometimes add a new device to my system, see by using lsusb that it appears and then search for the strings naming that resource in my /proc and /sys tree files. Further if you check your system log prior to inserting the device, insert your device, and then check your system log again, you'll see new entries relevant to what happened when you inserted the device. For instance, say it's either not working, or doesn't get enumerated because your kernel doesn't have a driver for this device. In the case of not having a device, you can see if one is available and then it depends as to whether or not you can load it as a module or have to rebuild your kernel to include that driver as part of it.

So experiment to learn some of that. See what your system log records when you insert a thumbstick and then remove it.

And by the way, your question about a bit in the status register may be answered in the system log, there is a status read and printed there; I'm just not sure if it's the status register you are trying to read. The driver for that resource may read that register and other registers and keep information about that in one of the /proc or /sys files for the device.
 
Old 03-11-2014, 08:28 AM   #21
tekra
Member
 
Registered: Aug 2010
Location: Brisbane, Australia
Distribution: Gentoo, Slackware, PCLOS
Posts: 64
Blog Entries: 1

Rep: Reputation: 2
Since this is a common point of confusion, it's perhaps worth pointing out that the USB bus is designed to be dynamically enumerated - that is, device numbering is never fixed, but is assigned as each device is "discovered" by a kernel daemon.

Fixed devices detected at boot will likely have the same number each time, but if pluggable devices occupy a port earlier in the "discovery chain", all subsequent numbers will be "shifted along".

From the commandline, the easiest way to identify USB buses and devices is by using the lsusb utility - read man lsusb for more info. Within program code there are several options depending on requirements. Every USB device has a unique Vendor:Product number, and this can be cross-referenced to the BuseviceNumber using lsusb, or by accessing one of the dynamic directories such as /sys/bus/usb/.

Dynamic buses require dynamic coding solutions; something of a pain, but a necessary evil of all pluggable systems.
 
Old 03-16-2014, 09:37 AM   #22
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,655

Rep: Reputation: Disabled
Hi rtmistler & tekra,

sorry to come back as late as this but I was out of town and then this and that...

Anyway. I tried to follow the hints and advices in your posts. Problem is, that openSuSE obviously works with a different setup in the directories under /proc and /sys. E.g. there is only /proc/tty/driver/serial (not .../usbserial) which contains no usb-information.

Gahh . Right now, working on my desktop pc, I did a crosscheck to verify the findings from my netbook. There is an empty document which yields the following information with:
Code:
cat /proc/tty/driver/usbserial
usbserinfo:1.0 driver:2.0
0: module:option name:&quot;GSM modem (1-port)&quot; vendor:12d1 product:1001 num_ports:1 port:1 path:usb-0000:00:12.2-2
1: module:option name:&quot;GSM modem (1-port)&quot; vendor:12d1 product:1001 num_ports:1 port:1 path:usb-0000:00:12.2-2
2: module:option name:&quot;GSM modem (1-port)&quot; vendor:12d1 product:1001 num_ports:1 port:1 path:usb-0000:00:12.2-2
But it doesn't find either card reader nor usb-stick nor the printer. What the...?!?

The /dev/ttyUSB? files are also there, all in the group dialout.

Well, I chucked out the obviously faulty extension card. The normal ports don't show up then.

Code:
ls /sys/bus/usb/devices
1-0:1.0  1-2:1.0  1-2:1.2  3-0:1.0  3-4:1.0  4-1      4-5      5-0:1.0  5-1:1.0  7-0:1.0  9-0:1.0  usb2  usb4  usb6  usb8
1-2      1-2:1.1  2-0:1.0  3-4      4-0:1.0  4-1:1.0  4-5:1.0  5-1      6-0:1.0  8-0:1.0  usb1     usb3  usb5  usb7  usb9
I Can't see a device tree here, again it's hard to interpret what I see.

BTW. thanks for explaining the script, that I understood .

Watching the log I use "tail -f /var/log/messages" it'll append any new log entries.

I found no USB-related status messages in the logs.

And yes, I understand that devices are numbered dynamically and why.

What I would really like to see is an application which draws a map of the USB-topology (tree, net, whatever...) with numbers and names of the devices, so one can understand the structure.

Thank you for your input and patience.

Last edited by JZL240I-U; 03-17-2014 at 02:05 AM.
 
Old 03-17-2014, 07:52 AM   #23
rtmistler
Senior Member
 
Registered: Mar 2011
Location: Milford, MA. USA
Distribution: MontaVista, Ubuntu, MINT
Posts: 1,085
Blog Entries: 7

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
The card reader and a USB stick are not going to be identified in the usbserial file, that's solely for USB serial devices, like FT232 devices which actually appear as a serial port /dev/ttyUSB in your /dev tree and can have properties like baud rate, parity, and stop bits set so they can be used as a COM port.

If there are no messages appearing in your system log when you insert/remove a thumbstick then there are two possibilities which I can think of (1) your level of system logging is set very high and I believe that to be either a kernel compile option or also a command line option which you can boot with, or not. For instance if "quiet" or some form of "quiet" is in your boot line, that would explain some of that, and (2) tail -f /var/log/messages isn't your system log. I don't have a /var/log/messages on some systems, so I use the dmesg(8) command.
 
Old 03-17-2014, 08:44 AM   #24
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,655

Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
The card reader and a USB stick are not going to be identified in the usbserial file, that's solely for USB serial devices, like FT232 devices which actually appear as a serial port /dev/ttyUSB in your /dev tree and can have properties like baud rate, parity, and stop bits set so they can be used as a COM port.
Ahh. That's new for me. Thanks for the explanation.

Quote:
Originally Posted by rtmistler View Post
If there are no messages appearing in your system log when you insert/remove a thumbstick ...
That is a misunderstanding. I do get messages with that "tail"-command. There is no message in the "cat /proc/tty/driver/usbserial" output (above you explained why).

Quote:
Originally Posted by rtmistler View Post
...so I use the dmesg(8) command.
Only it doesn't stay active like tail does, appending any new entry in the log.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB drive not working properly, read only device? (USB key storage device) Arodef Linux - Hardware 14 01-01-2010 07:32 AM
Printing Problem with Epson Stylus Color 440 connected to usb port entm Linux - Hardware 1 07-16-2007 06:16 AM
cannot find usb port of my connected printer kpachopoulos Debian 1 08-10-2006 07:29 AM
Installing Linux on External hard drive connected by USB port omidiora Linux - Newbie 1 04-29-2006 09:51 AM
HP Deskjet (USB) & CUPS & Slackware 9.1: Unable to open USB device "usb:/dev/usb/lp0&qu arnostienen Slackware 2 01-29-2004 03:22 PM


All times are GMT -5. The time now is 03:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration