光了海量存储的领导

问题描述:

我有带LED光了海量存储的领导

我想点亮和关闭使用USB数据包嗅探工具USBlyzer的领导

USB大容量stroage,

我可以得到原数据

其请求信息是批量或中断反FER和I/O停止

,并在USB属性部分

我可以得到信息,如

端点描述符81 1在,本体512个字节

bDescriptorType 05h Endpoint 

bEndpointAddress 81h 1 In 

端点描述符02 2 In,批量,512字节

bDescriptorType 05h Endpoint 

bEndpointAddress 02h 2 Out 

我用pytho制作了一个python代码ñ2.7的libusb-win32的彬1.2.4.0,pyusb-1.0.0-A1

完整的源代码是在这里

import usb.core 
import usb.util 

# find our device 
dev = usb.core.find(idVendor=0x1516, idProduct=0x8628) 

# was it found? 
if dev is None: 
    raise ValueError('Device not found') 

dev.set_configuration() 
# get an endpoint instance 
cfg = dev.get_active_configuration() 
interface_number = cfg[0].bInterfaceNumber 
alternate_setting = usb.control.get_interface(interface_number) 
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = \ 
           ineterface_number, bAlternateSetting = alternate_setting) 
ep = usb.util.find_descriptor(intf,custom_match = \ 
            lambda e: \ 
             usb.util.endpoint_direction(e.bEndpointAddress) == \ 
             usb.util.ENDPOINT_OUT) 
# set the active configuration. With no arguments, the first 
# configuration will be the active one 


assert ep is not None 

ep.write(0x2,0x55) 
ep.write(0x2,0x53) 
ep.write(0x2,0x42) 
ep.write(0x2,0x43) 
ep.write(0x2,0x58) 
ep.write(0x2,0x66) 
ep.write(0x2,0x93) 
ep.write(0x2,0x88) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x06) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 
ep.write(0x2,0x00) 

但是当我尝试执行它,

Traceback (most recent call last): 
    File "C:\Documents and Settings\kty1104\Desktop\usb2.py", line 14, in <module> 
    interface_number = cfg[0].bInterfaceNumber 
    File "C:\Python27\lib\site-packages\usb\core.py", line 447, in __getitem__ 
    return Interface(self.device, index[0], index[1], self.index) 
TypeError: 'int' object is not subscriptable 

出现

我的代码有什么问题?

如果有任何错误的概念是有的,请让我知道

谢谢!

+0

cfg是一个'int'。 'dev.get_active_configuration()'返回一个整数 – tMC 2011-06-02 15:31:30

+1

但是''cfg [0]'不会抛出异常,它会抛出'index [0]'。看到我的答案。 – senderle 2011-06-02 15:43:01

我对pyusb一无所知,但是我对错误信息的解释是,与其他人的观点相反,cfg不是一个整数,而是它需要一个非整数索引。我这样说是因为异常的__getitem__功能,这只能是cfg__getitem__抛出,因为这是一个__getitem__调用将在该行进行的唯一地方

interface_number = cfg[0].bInterfaceNumber 

现在如果cfg是一个int,它不会有__getitem__。问题是cfg__getitem__似乎预计能够下标它接收到的index,如中间两个参数index[0], index[1]所示。既然你通过了cfg一个整数,这是不可能的。


tutorial

您还可以使用标 运营商访问描述 随机,这样的:

>>> # access the second configuration 
>>> cfg = dev[1] 
>>> # access the first interface 
>>> intf = cfg[(0,0)] 
>>> # third endpoint 
>>> ep = intf[2] 

正如你所看到的该指数是基于零的。可是等等!有 东西在我访问 的接口方式怪异......是的,你是对的, 在 配置下标操作者接受的 两个项目的序列,第一个是 接口的索引, 第二个,备用设置。所以, 要访问第一个接口,但其0​​第二个替代设置,我们写入 cfg [(0,1)]。

+0

官方文档建议迭代对象,例如'for cff:'中的intf。 http://pyusb.sourceforge.net/docs/1.0/tutorial.html – ulidtko 2011-06-02 15:46:35

+0

@ulidtko,是的,我看到了,但我希望能有更详细的类参考来确认我的猜测。该教程是唯一可用的文档吗? – senderle 2011-06-02 15:59:53

+0

恐怕是这样。我也找不到任何类别参考。尽管如此,正如您所指出的那样,本教程包含有关索引的解释:接口索引必须是一对整数。 – ulidtko 2011-06-02 16:07:42