Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to run blinky under Ubuntu 12.04 #7

Open
fff opened this issue Mar 27, 2014 · 27 comments
Open

Failed to run blinky under Ubuntu 12.04 #7

fff opened this issue Mar 27, 2014 · 27 comments

Comments

@fff
Copy link

fff commented Mar 27, 2014

$ sudo ruby1.9.3 test.rb
/var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/constants.rb:46:in `raise_error': LIBUSB::ERROR_IO in libusb_submit_transfer (LIBUSB::ERROR_IO)
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/transfer.rb:135:in `submit!'
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/transfer.rb:162:in `submit_and_wait!'
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/dev_handle.rb:390:in `control_transfer'
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/compat.rb:316:in `usb_control_msg'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:35:in `set_colour'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:27:in `off!'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:22:in `warning!'
    from test.rb:5:in `<main>'
[  256.978955] usb 2-1.2: usbfs: process 3627 (ruby1.9.3) did not claim interface 0 before use
$ gem list

*** LOCAL GEMS ***

blinky (0.0.12)
chicanery (0.1.5)
ffi (1.9.3)
libusb (0.2.2)
mini_portile (0.5.3)
nokogiri (1.6.1)
$ dpkg -s libusb-1.0-0-dev
Package: libusb-1.0-0-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 898
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Source: libusb-1.0
Version: 2:1.0.9~rc3-2ubuntu1
Depends: libusb-1.0-0 (= 2:1.0.9~rc3-2ubuntu1), libc6-dev | libc-dev
Description: userspace USB programming library development files
 Library for programming USB applications without the knowledge
 of Linux kernel internals.
Homepage: http://www.linux-usb.org/
Original-Maintainer: Aurelien Jarno <[email protected]>

Not sure what's the cause

@perryn
Copy link
Owner

perryn commented May 8, 2014

Hi there,

Sorry for the delay responding - did you manage to get it working at all?

cheers
Perryn

@fff
Copy link
Author

fff commented May 11, 2014

Not really, we switched to host it in Windows, and it works fine.

@fff fff closed this as completed May 11, 2014
@Aurenkin
Copy link

Hi,

I'm also experiencing this same issue. Sounds like you threw in the towel, fff, but were you able to make any progress before then?

Cheers,

John

@perryn
Copy link
Owner

perryn commented Jul 31, 2014

Hi Aurekin

I'd like to get to the bottom of this - Would you be able to make code changes and try them out on your system?

Perryn

@perryn perryn reopened this Jul 31, 2014
@Aurenkin
Copy link

I'd be happy to. Also not sure if this helps or if I'm going in totally the wrong direction but I noticed in my lsusb output for my build light:

Bus 001 Device 023: ID 0fc5:b080 Delcom Engineering 
Device Descriptor:
 .....removed for brevit....
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
Device Status:     0x0002
  (Bus Powered)
  Remote Wakeup Enabled

Looks like wMaxPacketSize is 8 bytes but libusb is sending:

submit transfer #<LIBUSB::Call::Transfer:0x00000004c72af0> buffer: #<FFI::Pointer address=0x007fd698131dc0> length: 16 status: :TRANSFER_COMPLETED callback: #<FFI::Function address=0x007fd6bf0c00c0> dev_handle: #<FFI::Pointer address=0x007fd6981309e0>

which seems to be 16 bytes?

Again, just messing around and clutching at straws but thought maybe it's useful.

@perryn
Copy link
Owner

perryn commented Jul 31, 2014

heh - no idea :)

In the meantime try adding

begin
    @handle.usb_detach_kernel_driver_np(0)
 rescue LIBUSB::ERROR_NOT_FOUND
     # Already detached
 end
 @handle.set_configuration(device.configurations.first)
 @handle.usb_claim_interface(0)

after line 5 in light.rb?

Also, what version of Ubuntu are you running?

@Aurenkin
Copy link

I'm running 14.04.

I added your code and I'm now getting

ActionController::RoutingError (undefined local variable or method `device' for #<Blinky::Light:0x000000049fc8e8>):
  app/controllers/light_controller.rb:7:in `<class:LightController>'
  app/controllers/light_controller.rb:5:in `<top (required)>'

Sounds like it might relate to light.rb:11 (@handle.set_configuration(device.configurations.first))

Also as an aside, I'm a Melb based TWer, just started at the beginning of the year. I'm working with Ranjeet and he mentioned that he knew you when we came across this project. Small world!

@perryn
Copy link
Owner

perryn commented Jul 31, 2014

doh

In that case, instead of calling device.open in LightFactory and constructing Light with the result, you'll need to construct Light with the device and call open to obtain the handle.

@Aurenkin
Copy link

Working like a charm, now. Posting my light_factory.rb and light.rb for reference:

light_factory.rb

module Blinky
  class LightFactory

    def self.detect_lights plugins, recipes
      lights = []
      found_devices = [] 
      USB.devices.each do |device| 
        found_devices << device  
        matching_recipe = recipes[device.idVendor][device.idProduct] 
        if matching_recipe
          lights << Light.new(device, matching_recipe, plugins)
        end
      end
      raise NoSupportedDevicesFound.new found_devices if lights.empty?
      lights
    end

  end
end

light.rb

module Blinky
  class Light

    def initialize device, recipe, plugins
      @handle = device.open
      begin
        @handle.usb_detach_kernel_driver_np(0)
      rescue LIBUSB::ERROR_NOT_FOUND
         # Already detached
      end
      @handle.set_configuration(device.configurations.first)
      @handle.usb_claim_interface(0)
      self.extend(recipe)   
      plugins.each do |plugin|
        self.extend(plugin)
      end    
      self.init      
    end

    def where_are_you?
      5.times do
        failure!
        sleep(0.5)
        success!
        sleep(0.5)
      end
      off!      
    end

  end
end

@perryn
Copy link
Owner

perryn commented Jul 31, 2014

awesome, now we just need to make sure it still works on other platforms

@Aurenkin
Copy link

Sounds like a plan. I can check it on a Mac and possibly a Windows machine if that would help?

@perryn
Copy link
Owner

perryn commented Jul 31, 2014

it would, but I bet it wont work ;)

@RReichert
Copy link

had the same issue with my linux x64 machine, with the patch you guys figured out, its now working like a charm. thanks

@Aurenkin
Copy link

Just tested the fix on a windows machine and it seems to work just fine. Haven't had a chance to test on OSX yet but hopefully will sometime today.

@perryn
Copy link
Owner

perryn commented Aug 5, 2014

hey @Aurenkin did you get anywhere?

@Aurenkin
Copy link

Aurenkin commented Aug 5, 2014

I didn't get around to testing on OSX yet but thanks for reminding me, I should be able to borrow a Macbook today to test it out.

@Aurenkin
Copy link

Sorry for taking so long to get to this! Finally put OSX back on my mac and tested today. Unfortunately it looks like with the code changes we made, it doesn't work for mac :( . Let me know if you want me to test anything else out.

@perryn
Copy link
Owner

perryn commented Oct 7, 2014

hey @Aurenkin are you interested in helping out further on this?

@Aurenkin
Copy link

Aurenkin commented Oct 7, 2014

Yeah for sure, I don't know if I have access to a build light anymore
though but I will see if I can dig one up.

On 7 October 2014 14:50, Perryn Fowler [email protected] wrote:

hey @Aurenkin https://github.com/Aurenkin are you interested in helping
out further on this?


Reply to this email directly or view it on GitHub
#7 (comment).

@holmesjr
Copy link

FWIW I'm having the same issue on a Raspberry Pi running Raspbian.

@perryn
Copy link
Owner

perryn commented Dec 16, 2014

hi @holmesjr - did you try the patch described above?

@holmesjr
Copy link

First thing tomorrow, I'll give it a go and report the results. I can then test on a Mac to see if it still works there.

@holmesjr
Copy link

OK, the patch makes things work once. After that the same error pops up. These were run immediately one after the other.

irb(main):002:0> blinky = Blinky.new
=> #<Blinky::Blinky:0xb955dea8 @recipes={4037=>{4643=>Blinky::DelcomEngineering::VisualIndicator::GenerationI, 45184=>Blinky::DelcomEngineering::VisualIndicator::GenerationII}, 10168=>{493=>Blinky::ThingM::Blink1}, 7476=>{4=>Blinky::DreamCheeky::WebmailNotifier}}, @plugins=[Blinky::TestCiServer, Blinky::CCTrayServer], @lights=[#<Blinky::Light:0xb9b6c098 @handle=#<USB::DevHandle:0xb9b8f120 @dev=#<LIBUSB::DevHandle:0xb9b8f138 @device=#<LIBUSB::Device 1/13 0fc5:b080 Delcom Products Inc. USB IO Controller ? (HID (00,00))>, @pHandle=#<FFI::Pointer address=0xb9b72eb0>, @interrupt_transfer=nil, @control_transfer=nil, @bulk_transfer=nil>>>]>
irb(main):003:0> blinky.lights[0].success!
=> 8

irb(main):004:0> blinky.lights[0].success!
LIBUSB::ERROR_NO_DEVICE: LIBUSB::ERROR_NO_DEVICE in libusb_submit_transfer
        from /home/pi/.gem/ruby/2.1.3/gems/libusb-0.2.2/lib/libusb/constants.rb:46:in `raise_error'
        from /home/pi/.gem/ruby/2.1.3/gems/libusb-0.2.2/lib/libusb/transfer.rb:135:in `submit!'
        from /home/pi/.gem/ruby/2.1.3/gems/libusb-0.2.2/lib/libusb/transfer.rb:162:in `submit_and_wait!'
        from /home/pi/.gem/ruby/2.1.3/gems/libusb-0.2.2/lib/libusb/dev_handle.rb:390:in `control_transfer'
        from /home/pi/.gem/ruby/2.1.3/gems/libusb-0.2.2/lib/libusb/compat.rb:316:in `usb_control_msg'
        from /home/pi/Documents/Projects/blinky/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:35:in `set_colour'
        from /home/pi/Documents/Projects/blinky/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:27:in `off!'
        from /home/pi/Documents/Projects/blinky/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:7:in `success!'
        from (irb):4
        from /home/pi/.rubies/ruby-2.1.3/bin/irb:11:in '<main>' 

@holmesjr
Copy link

Hmm, saying it worked was slightly optimistic. While it returned without an error, the light flashed instead of actually showing the chosen status. I've run the latest from git against the same light on a Mac (without the changes above) and the correct behaviour is observed.

scottatron added a commit to scottatron/blinky that referenced this issue Jan 2, 2015
@plaa
Copy link

plaa commented May 19, 2015

I had the same problem when trying to control a 904008 light on a Raspberry Pi running Raspbian. After @Aurenkin's patch setting the lights worked. However something goes wrong later on when running .watch_test_server - not sure is it related with this patch or not.

During the "WARNING" state the light blinks yellow and dmesg shows that the device is disconnected / reconnected very often during the warning blinking, which probably causes the issue of no device being found when trying to re-control it.

pi@raspberrypi ~ $ sudo ruby blinky-test.rb 
BUILDING!
-
BUILD FAILED!
-
BUILDING!
-
WARNING!
-
BUILDING!
/var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/constants.rb:46:in `raise_error': LIBUSB::ERROR_NO_DEVICE in libusb_submit_transfer (LIBUSB::ERROR_NO_DEVICE)
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/transfer.rb:135:in `submit!'
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/transfer.rb:162:in `submit_and_wait!'
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/dev_handle.rb:390:in `control_transfer'
    from /var/lib/gems/1.9.1/gems/libusb-0.2.2/lib/libusb/compat.rb:316:in `usb_control_msg'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:35:in `set_colour'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:27:in `off!'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb:17:in `building!'
    from /var/lib/gems/1.9.1/gems/blinky-0.0.12/lib/ci_server_plugins/test_server_plugin.rb:25:in `watch_test_server'
    from blinky-test.rb:5:in `<main>'

@plaa
Copy link

plaa commented May 19, 2015

The blinking / reconnecting problem was due to the Delcom pulling too much current from the Raspi port. Putting an active USB hub in between solved that problem. But the patch was necessary for it to work.

@flaccid
Copy link

flaccid commented Mar 2, 2016

I have also just run into this on current Raspbian on RPi 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants