Question

I'm using Ruby 1.8 and linux (Ubuntu and SLAX), and i need to write a script in ruby which finds out if some specific usb device is connected to the system and on which USB port (0,1,2, etc). It was done before with the help of HAL (hal-find-by-capability --capability serial), but now i can't use this approach. I was trying to read /var/log/messages file trying to find the number of the usb port, but it appears that this number may not be written in some systems. Other thing i tried is to check /dev folder and search for ttyUSB# file, but it doesn't appear on some system when new device connects to USB. I would appreciate any ideas how to do this.

Was it helpful?

Solution

lsusb is a linux command for displaying your usb hubs and listing the devices that are connected to them. In ruby I believe you'd be able to do something like this:

ls_results = `lsusb`

You should be able to parse that for whatever device you're looking for.

OTHER TIPS

I'm sorry that I couldn't provide you an ruby sample. I had the same problem in C / C++ (QT). You can find my snippet here:

http://www.known-issues.net/cpp/how-to-detect-if-dev-is-a-usb-device.html

You have libusb ruby bindings which allow to control usb devices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top