Ruby libusb:停止错误 [英] Ruby libusb: Stall error

查看:41
本文介绍了Ruby libusb:停止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在玩 PS2 游戏 Buzz 的控制器.我已经成功地使用 libusb 来轮询和读取按钮,一切都很愉快.

So I've been playing with the controllers for the PS2 game, Buzz. I've successfully used libusb to poll and read the buttons, and all is merry and bright.

问题是,我很想使用内置灯向使用它们的人发出信号(特别是向他们展示谁先嗡嗡作响).我知道有灯,我知道 PS2 能够随意打开和关闭它们,而且我知道 有人用 python 管理它.所以我开始用 Ruby 中的 libusb 实现他们的代码.

The trouble is, I'd love to use the in-built lights to signal the folks who're using them (specifically to show them who has buzzed first). I know there's lights, I know that the PS2 was able to turn them on and off at will, and I know that someone has managed it with python. So I set out to implement their code with libusb in Ruby.

我已经复制了他们正在进行的 SET_CONFIGURATION 调用,但我不断收到此错误:

I've reproduced the SET_CONFIGURATION call they're making but I keep getting this error:

/home/ajfaraday/.rvm/gems/ruby-2.2.1/gems/libusb-0.5.0/lib/libusb/dev_handle.rb:539:in `submit_transfer': 
error TRANSFER_STALL (LIBUSB::ERROR_PIPE)

我在网上找不到关于此错误是什么的任何材料,除了这是一个 USB 管道错误,libusb 正在将其转换为 TRANSFER_STALL.

I can't find any material online about what this error is, except that it's a USB pipe error which is being translated to TRANSFER_STALL by libusb.

我也在 python 中用上面论坛的特定行写了它,我得到了一些看起来像同样的错误:

I also wrote it out in python, with the specific line from the forum above, and I got something that looks like the same error:

usb.core.USBError: [Errno 32] Pipe error

所以我不知道自己做错了什么.我设法对成功响应 (\x00) 进行了相反的调用 (GET_CONFIGURATION).

So I'm at a loss to find out what I'm doing wrong. I've managed to make the opposite call (GET_CONFIGURATION) to a successful response (\x00).

这是我的复制脚本(取决于 libusb gem):

Here's my reproduction script (depends on the libusb gem):

require 'libusb'

usb_context = LIBUSB::Context.new
device = usb_context.devices(
  idVendor: 0x054c, idProduct: 0x0002
).first
handle = device.open

puts 'get configuration:'
x = handle.control_transfer(
  :bmRequestType => "10000000".to_i(2),
  :bRequest => 8,
  :wValue => 0,
  :wIndex => 0,
  :dataIn => 1
)  
puts x.inspect

puts 'set configuration:'
x = handle.control_transfer(
  :bmRequestType => "00000000".to_i(2),
  :bRequest => 9,
  :wValue => 0,
  :wIndex => 0,
  :dataOut => "\x00\xFF\xFF\xFF\xFF"
)
puts x.inspect

这是它的输出:

get configuration:
"\x00"
set configuration:
/home/ajfaraday/.rvm/gems/ruby-2.2.1/gems/libusb-0.5.0/lib/libusb/dev_handle.rb:539:in `submit_transfer': error TRANSFER_STALL (LIBUSB::ERROR_PIPE)
    from /home/ajfaraday/.rvm/gems/ruby-2.2.1/gems/libusb-0.5.0/lib/libusb/dev_handle.rb:515:in `control_transfer'
    from sketches/raw_script.rb:22:in `<main>'

看起来管道错误意味着我发送的设置或数据有问题,但我找不到任何地方.

It looks like the pipe error means there's something wrong with the setup or data I'm sending out, but I can't find out anywhere what it is.

我试过了:

如果有任何帮助,我将不胜感激.这真的应该是可能的,我知道它已经完成了.

I'd be very grateful of any assistance. This really should be possible, and I know it's been done.

推荐答案

Libusb 提供了两个名为 libusb_set_configurationlibusb_get_configuration 的函数.你应该尝试使用它们而不是滚动你自己的控制转移来做同样的事情.它们记录在此处:

Libusb provides two functions named libusb_set_configuration and libusb_get_configuration. You should try to use those instead of rolling your own control transfers to do the same thing. They are documented here:

http://libusb.sourceforge.net/api-1.0/group__dev.html

您可以查看您正在使用的 Ruby libusb 绑定的源代码或文档,以了解如何从 Ruby 调用它们.

You can check the source code or documentation of the Ruby libusb binding you are using to figure out how to call them from Ruby.

此外,设置配置是对 USB 设备执行的半不寻常的事情.您应该确保操作系统上的驱动程序尚未将设备置于正确的配置中.也许你不需要设置配置.

Also, setting a configuration is a semi-unusual thing to do to a USB device. You should make sure the drivers on your operating system do not already put the device into the correct configuration. Maybe you don't need to set the configuration.

此外,如果此控制器是 HID,则 hidapi 库可能更适合比 libusb.

Also, if this controller is an HID, the hidapi library might be a better fit than libusb.

这篇关于Ruby libusb:停止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆