東西我似乎無法找到答案。請記住,我不是專家,所以我可能會錯過簡單的,也許我打印我想要的設備。 我試圖存儲設備版本號(從這裏dvm),關閉USB設備。問題是USB設備有兩列用於報告,功能和輸出。在Python中過濾USB HID列
所以當我打印設備時,我收到兩組打印語句。
#DEF設備(target_usage,target_vendor_id):
hidDevice = False
all_devices = hid.HidDeviceFilter(vendor_id = target_vendor_id).get_devices()
print "\n", all_devices
if len(all_devices) == 0:
# Exit if no devices found, report error.
hidDevice = False
time.sleep(0.2)
print "No devices can be detected, please check device is connected."
sys.exit(1)
return
elif len(all_devices) > 2:
# announce there are more than 1 device connected to prevent conflicting upgrades
hidDevice = True
time.sleep(0.2)
print "Too many devices connected, ensure the only device connected is the device needed to test."
sys.exit(1)
else:
# loop through all devices
for device in all_devices:
try:
device.open()
# print device details
device_name = unicode("=== INFO: Found %s %s (vID=[%04x], pID=[%04x], version number [%04x]) ===" % \
(device.vendor_name, device.product_name, device.vendor_id, device.product_id, device.version_number))
dvm = unicode("%04x" % \
(device.version_number))
print dvm;
print device_name;
finally:
device.close()
hidDevice = True
return hidDevice
#
當這個函數被調用時,它將打印所有的設備,但我結束了以下結果(修改的PID/VIDS等爲隱私問題。)
[HID設備(vID = 0x0000,pID = 0x0000,v = 0x0000);使;型號,路徑:\?\ hid#vid_0000 & pid_0000 & col01#7 0000#{00000000-0000-0000-0000-000000000000},HID設備(vID = 0x0000,pID = 0x0000,v = 0x0000) ;使;模型,路徑:\ \躲在#vid_0000 & pid_0000 & col02#7 0000#{} 00000000-0000-0000-0000-000000000000
的重要組成部分,是COL01和col02。
如何過濾第二枚枚舉的HID設備?