我有帶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
出現
我的代碼有什麼問題?
如果有任何錯誤的概念是有的,請讓我知道
謝謝!
cfg是一個'int'。 'dev.get_active_configuration()'返回一個整數 – tMC 2011-06-02 15:31:30
但是''cfg [0]'不會拋出異常,它會拋出'index [0]'。看到我的答案。 – senderle 2011-06-02 15:43:01