我需要使用Python通过USB发送数据,我使用PyUSB(http://sourceforge.net/apps/trac/PyUSB/)
我寻找可用的USB端口,并尝试发送消息:devList = usb.core.find(find_all=True)
for dev in devList:
for cfg in dev:
for intf in cfg:
sys.stdout.write('\t' + str(intf.bInterfaceNumber) + ',' + str(intf.bAlternateSetting) + '\n')
for ep in intf:
sys.stdout.write('\t\t' + str(ep.bEndpointAddress) + '\n')
if ep.bEndpointAddress:
try:
dev.write(ep.bEndpointAddress, 'test', intf.bInterfaceNumber)
except Exception:
print "\t\terror : dev.write("+str(ep.bEndpointAddress)+", 'test', "+str(intf.bInterfaceNumber)+")"
结果是:0,0
129
error : dev.write(129, 'test', 0)
0,1
129
error : dev.write(129, 'test', 0)
0,0
136
error : dev.write(136, 'test', 0)
10
error : dev.write(10, 'test', 0)
1,0
139
error : dev.write(139, 'test', 1)
13
error : dev.write(13, 'test', 1)
如果不尝试接球,它会:usb.core.USBError: [Errno None] usb_claim_interface: could not claim interface 0, invalid configuration 0
怎么了?有没有一种通过usb与python通信的最佳方式?因为我刚找到这个库