Search code examples
rubymacosusbosx-yosemitelibusb

Reading data from USB device (Waterrower S4 Monitor) with libusb and Ruby


I bought a Waterrower which has an S4 Performance Monitor that has a Micro-USB connector on its back and I thought it would be nice to be able to fetch the data that comes from the S4 and do something nice with it.

I do know some Ruby but I'm not at all into talking to hardware. I did find the libusb Ruby binding by Lars Kanis on Github and played around with it:

2.1.0 :001 > require "libusb"
 => true 
2.1.0 :002 > usb = LIBUSB::Context.new
 => #<LIBUSB::Context:0x000001011451c0 @ctx=#<FFI::Pointer address=0x000001032788b0>, @on_pollfd_added=nil, @on_pollfd_removed=nil, @hotplug_callbacks={}> 
2.1.0 :003 > usb.devices
 => [#<LIBUSB::Device 20/9 04d8:000a Microchip Technology Inc. CDC RS-232: WR-S4.2 ? (Comm (00,00))>, #<LIBUSB::Device 20/8 054c:0243 Sony Storage Media 2A08080530914 (MassStorage SCSI Bulk-Only)>, #<LIBUSB::Device 20/1 05ac:025a Apple Inc. Apple Internal Keyboard / Trackpad ? (HID (01,01), HID (00,00), HID (01,02))>, #<LIBUSB::Device 20/129 05ac:8007 ? ? ? (Hi-speed Hub with single TT)>, #<LIBUSB::Device 21/128 05ac:8007 ? ? ? (Hub (00,03))>] 
2.1.0 :004 > wr_s4 = usb.devices(:idVendor => 0x04d8, :idProduct => 0x000a).first
 => #<LIBUSB::Device 20/9 04d8:000a Microchip Technology Inc. CDC RS-232: WR-S4.2 ? (Comm (00,00))> 
2.1.0 :005 > wr_s4
 => #<LIBUSB::Device 20/9 04d8:000a Microchip Technology Inc. CDC RS-232: WR-S4.2 ? (Comm (00,00))>

As you can see I was able to connect to the correct device (named wr_s4).

Now, I've no idea in what kind of format the S4 Monitor is going to send data trough USB and what would be the smartest way to read it.

Any help with the S4 Performance Monitor or getting data out of an USB device with Ruby would be greatly appreciated.

Thanks a lot for your help!


Solution

  • Have you seen the document titled "Water Rower S4 S5 USB Protocol Iss 1.04.doc"?

    Here is the link.

    The github project seems to be similar to what you want to do. It should help out in understanding the usb data.