# Usb

**URL:** <https://www.ruby-forum.com/t/usb/77994>\
**Category:** Ruby\
**Created:** [December 2, 2006, 11:27am UTC](https://www.ruby-forum.com/t/usb/77994 "2006-12-02T11:27:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![javra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@javra](https://www.ruby-forum.com/u/javra)\
**Post date:** [December 2, 2006, 11:27am UTC](https://www.ruby-forum.com/t/usb/77994/1 "2006-12-02T11:27:02Z")

</div>

Hi,  
Is there any programme or library in ruby to drive own hardware via  
USB? Or do I have to implement my own C functions?

---

<div class="post-metadata">

**Author:** ![javra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@javra](https://www.ruby-forum.com/u/javra)\
**Post date:** [December 2, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/usb/77994/2 "2006-12-02T18:31:50Z")

</div>

javra wrote:

> Hi,  
> Is there any programme or library in ruby to drive own hardware via  
> USB? Or do I have to implement my own C functions?

Ruby doesn’t have the sort of close-to-the-hardware functions to do this  
sort of thing, also Ruby programs are “better” when designed to be  
cross-platform, so a driver approach might work out better overall.

---

<div class="post-metadata">

**Author:** ![javra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@javra](https://www.ruby-forum.com/u/javra)\
**Post date:** [December 2, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/usb/77994/3 "2006-12-02T19:15:54Z")

</div>

Paul L. wrote:

> –  
> Paul L.  
> [http://www.arachnoid.com](http://www.arachnoid.com)

javra:

Google for libusb.  
The first two hits are for the \*nix project and the Windows port of it.  
Might help. You’d have to write a Ruby-C extension for it though.  
Might turn out to be easier/faster than writing your own USB driver, if  
that’s what you meant.

HTH  
Vasudev

```auto
Vasudev Ram
Dancing Bison Enterprises
Software products, consulting and training
http://www.dancingbison.com
http://jugad.livejournal.com
http://dancingbison.blogspot.com

```

---

<div class="post-metadata">

**Author:** ![javra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@javra](https://www.ruby-forum.com/u/javra)\
**Post date:** [December 2, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/usb/77994/4 "2006-12-02T19:35:57Z")

</div>

javra:

> Google for libusb.  
> The first two hits are for the \*nix project and the Windows port of it.  
> Might help. You’d have to write a Ruby-C extension for it though.  
> Might turn out to be easier/faster than writing your own USB driver, if  
> that’s what you meant.

Libusb is reasonably easy to use, but a big catch on \*nix is that you  
have to be running as root. Not a good idea for your entire  
application. So I found it easier to write a small C daemon that  
listens to a \*nix domain socket and send through what it gets to the USB  
device using appropriate libusb calls. You could also write some  
Ruby-to-libusb wrappers and then write the daemon in Ruby instead of C  
if you wanted to learn the Ruby-to-C interfaces, but in my view that’s  
adding needless complexity. Depending on the type of USB device the  
amount of device control vs. data that you need to make to talk to it  
can be quite complex. I’m happy to share the daemon source if you send  
me some private mail.

The best way to figure out how to talk to your device is to reverse  
engineer what a manufacturer-provided Windows driver does unless you  
happen to have good device-level USB documentation. You can do this by  
looking at logs snapped by SnoopyPro.
