好的,我现在有了解决方案,我会发布它,但是我有一个问题…当我运行代码时,有时它会说设备正忙,它会产生一个错误,当它工作时。。。它会等待一个中断,但是如果你移动鼠标,它会在屏幕上保持静止,但会产生一个中断。同样可以说,点击一个按钮,它会产生一个中断,但鼠标将保持静止,要再次使用它,你需要把它从usb中取出,然后再放进去。在import usb.core
import usb.util
#import usb
# find our device
dev = usb.core.find(find_all=True)
#the second device it finds is my mouse
device = dev[2]
#print device
#physical device call: 5
#usb HID call: 3
_name = usb.util.get_string(device, 19, 1)
print _name
#we take the first configuration of the device
device.set_configuration()
print "Config set..."
#we access the configuration we've found
cfg = device.get_active_configuration()
#we access the intherface with number 0 and alternate setting with number 0
interface_number = cfg[(0,0)].bInterfaceNumber
alternate_setting = usb.control.get_interface(device,interface_number)
#we find the alterng settings for interface_number and altering_setting
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number,\
bAlternateSetting = alternate_setting)
#Finds the first IN endpoint
ep = usb.util.find_descriptor(
intf,
# match the first IN endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN
)
#inorder for you to detect a state from the device, it has to be(for mouse, moved,
#clicked)
#otherwise it generates error
#make use of the error, if the mouse isn't pushed, do nothing and wait, if pushed...
#print the state
#and exit from the loop
print "Waiting for signal..."
#device.detach_kernel_driver(0)
#click of the scroll button has array('B', [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#0, 0]) signal
while True:
try:
print ep.read(16)
print "Received!"
break
except:
continue
#assert ep is not 0
#_name=device.ctrl_transfer(bmRequestType=33, bRequest=11, wValue=0x0300)
#print _name
所以我猜它会先删除鼠标的驱动程序,然后它会和设备对话,然后我点击一个按钮就会产生中断,然后……我怎么能说,再次使用你的驱动程序并结束程序……因为每次重新插入usb鼠标是不公正的。在