开发者

Find out if USB device is connected. Ruby in Linux

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜