本文整理汇总了Python中pywinusb.hid.find_all_hid_devices函数的典型用法代码示例。如果您正苦于以下问题:Python find_all_hid_devices函数的具体用法?Python find_all_hid_devices怎么用?Python find_all_hid_devices使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_all_hid_devices函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_vec_usb_footpedal
def find_vec_usb_footpedal():
all_hids = hid.find_all_hid_devices()
for index, device in enumerate(all_hids):
if (device.vendor_id == 0x05f3 and device.product_id == 0x00ff):
print("Found VEC USB Footpedal")
return all_hids[index]
raise Exception("VEC USB Footpedal not found");
示例2: __init__
def __init__(self, button_pressed_func, device_unplugged):
"""
Init Function
:param button_pressed_func: function that will be called after get_btn_press is called
:return:
"""
self.cl = ControllerLinks()
self.wait_for_button = False
self.poll = False
self.last_USB = None
self.data_to_make_link = None
# Hid device stuff
self.devices = hid.find_all_hid_devices()
self.device = None
#return func to notify UI that a key has been captured
self.BPF = button_pressed_func
# Called if the device is unplugged
self.device_unplugged = device_unplugged
#launch thread to generate keys
self.GenerateThread = threading.Thread(target=self.generate_key_events,name="Bob")
self.StopThread = threading.Event()
self.GenerateThread.start()
示例3: __init__
def __init__(self):
self.buttons = [[1,24,0], # 1
[2,40,0], # 2
[3,72,0], # 3
[4,136,0], # 4
[5,8,1], # 5
[6,8,2], # 6
[7,8,4], # 7
[8,8,8], # 8
[9,8,16], # 9
[10,8,32]] # 10
self.down = False
self.hats = [["up",0,0],
["left",6,0],
["right",2,0],
["down",4,0]]
# initialize connection to joystick
all_hids = hid.find_all_hid_devices()
self.jdev = False
for device in all_hids:
if (device.product_name == "Logitech Dual Action"):
self.jdev = device
if not self.jdev:
print "Logitech Dual Action joystick not found."
示例4: main
def main(fn=None):
if fn == None:
devices = []
try:
for device in hid.find_all_hid_devices():
if device.vendor_id != 0x21A1:
continue
if device.product_name == 'Brain Waves':
devices.append(device)
device.open()
device.set_raw_data_handler(sample_handler)
elif device.product_name == 'EPOC BCI':
print 'foo'
devices.append(device)
device.open()
device.set_raw_data_handler(bci_handler)
while True:#device.is_plugged() and count < 1000:
time.sleep(0.1)
finally:
for device in devices:
device.close()
else:
for line in file(fn, 'r').readlines():
data = [0] + [int(x, 16) for x in line.strip().split(' ')]
sample_handler(data)
示例5: getAllConnectedInterface
def getAllConnectedInterface(vid, pid):
"""
returns all the connected devices which matches PyWinUSB.vid/PyWinUSB.pid.
returns an array of PyWinUSB (Interface) objects
"""
all_devices = hid.find_all_hid_devices()
# find devices with good vid/pid
all_mbed_devices = []
for d in all_devices:
if (d.vendor_id == vid) and (d.product_id == pid):
all_mbed_devices.append(d)
boards = []
for dev in all_mbed_devices:
try:
dev.open(shared=False)
report = dev.find_output_reports()
if len(report) == 1:
new_board = PyWinUSB()
new_board.report = report[0]
new_board.vendor_name = dev.vendor_name
new_board.product_name = dev.product_name
new_board.vid = dev.vendor_id
new_board.pid = dev.product_id
new_board.device = dev
new_board.device.set_raw_data_handler(new_board.rx_handler)
boards.append(new_board)
except Exception as e:
logging.error("Receiving Exception: %s", e)
dev.close()
return boards
示例6: get_available_devices
def get_available_devices():
devices = []
if WINDOWS:
try:
for device in hid.find_all_hid_devices():
if device.product_name == 'Emotiv RAW DATA':
devices.append(device.device_path)
finally:
pass
else:
serials = {}
for name in os.listdir("/sys/class/hidraw"):
realInputPath = os.path.realpath("/sys/class/hidraw/" + name)
path = '/'.join(realInputPath.split('/')[:-4])
try:
if os.path.isfile(path + "/manufacturer"):
with open(path + "/manufacturer", 'r') as f:
manufacturer = f.readline()
if "emotiv" in manufacturer.lower():
with open(path + "/serial", 'r') as f:
serial = f.readline().strip()
if serial not in serials:
serials[serial] = []
serials[serial].append(name)
except IOError as e:
print("Couldn't open file: %s" % e)
for serial, names in serials.items():
device_path = '/dev/'+names[1]
devices.append(device_path)
return devices
示例7: __init__
def __init__(self, **kwds):
"""
Define arrays for translating joystick events and find the joystick HID.
"""
super().__init__(self, **kwds)
self.buttons = [[1,24,0], # 1
[2,40,0], # 2
[3,72,0], # 3
[4,136,0], # 4
[5,8,1], # 5
[6,8,2], # 6
[7,8,4], # 7
[8,8,8], # 8
[9,8,16], # 9
[10,8,32]] # 10
self.down = False
self.hats = [["up",0,0],
["left",6,0],
["right",2,0],
["down",4,0]]
# initialize connection to joystick
all_hids = hid.find_all_hid_devices()
self.jdev = False
for device in all_hids:
if (device.product_name == "Logitech Dual Action"):
self.jdev = device
if not self.jdev:
print("Logitech Dual Action joystick not found.")
示例8: get_available_devices
def get_available_devices(cls):
devices = OrderedDict()
if WINDOWS:
try:
for device in hid.find_all_hid_devices():
print "device : ", device
if (device.product_name == 'Emotiv RAW DATA' or device.product_name == 'EPOC BCI'):
devices['Emotiv '+device.serial_number] = get_info(device)
finally:
pass
else:
serials = { }
for name in os.listdir("/sys/class/hidraw"):
realInputPath = os.path.realpath("/sys/class/hidraw/" + name)
path = '/'.join(realInputPath.split('/')[:-4])
try:
with open(path + "/manufacturer", 'r') as f:
manufacturer = f.readline()
if "emotiv" in manufacturer.lower():
with open(path + "/serial", 'r') as f:
serial = f.readline().strip()
if serial not in serials:
serials[serial] = [ ]
serials[serial].append(name)
except IOError as e:
print "Couldn't open file: %s" % e
for serial, names in serials.items():
device_path = '/dev/'+names[1]
info = get_info(device_path)
devices['Emotiv '+device_path] = info
return devices
示例9: getAllConnectedInterface
def getAllConnectedInterface(board_id = None):
"""
returns all the connected CMSIS-DAP devices
"""
all_devices = hid.find_all_hid_devices()
# find devices with good vid/pid
all_mbed_devices = []
for d in all_devices:
if (d.product_name.find("CMSIS-DAP") >= 0):
all_mbed_devices.append(d)
boards = []
for dev in all_mbed_devices:
try:
dev.open(shared=False)
report = dev.find_output_reports()
if (len(report) == 1):
new_board = PyWinUSB()
new_board.report = report[0]
new_board.vendor_name = dev.vendor_name
new_board.product_name = dev.product_name
new_board.serial_number = dev.serial_number
new_board.vid = dev.vendor_id
new_board.pid = dev.product_id
new_board.device = dev
new_board.device.set_raw_data_handler(new_board.rx_handler)
boards.append(new_board)
except Exception as e:
logging.error("Receiving Exception: %s", e)
dev.close()
return boards
示例10: setupWin
def setupWin(self):
devices = []
try:
for device in hid.find_all_hid_devices():
if device.vendor_id != 0x21A1:
continue
if device.product_name == 'Brain Waves':
devices.append(device)
device.open()
self.serialNum = device.serial_number
device.set_raw_data_handler(self.handler)
elif device.product_name == 'EPOC BCI':
devices.append(device)
device.open()
self.serialNum = device.serial_number
device.set_raw_data_handler(self.handler)
elif device.product_name == '00000000000':
devices.append(device)
device.open()
self.serialNum = device.serial_number
device.set_raw_data_handler(self.handler)
gevent.spawn(self.setupCrypto, self.serialNum)
gevent.spawn(self.updateStdout)
while self._goOn:
try:
gevent.sleep(0)
except KeyboardInterrupt:
self._goOn = False
for device in devices:
device.close()
finally:
for device in devices:
device.close()
示例11: setup_windows
def setup_windows(self):
"""
Setup for headset on the Windows platform.
"""
devices = []
try:
for device in hid.find_all_hid_devices():
is_emotiv = False
if "Emotiv" in device.vendor_name:
is_emotiv = True
if "Emotiv" in device.product_name:
is_emotiv = True
if "EPOC" in device.product_name:
is_emotiv = True
if "Brain Waves" in device.product_name:
is_emotiv = True
if device.product_name == '00000000000':
is_emotiv = True
if "EEG Signals" in device.product_name:
is_emotiv = True
if is_emotiv:
devices.append(device)
if len(devices) > 0:
device = devices[1]
device.open()
self.serial_number = device.serial_number
device.set_raw_data_handler(self.handler)
crypto = gevent.spawn(self.setup_crypto, self.serial_number)
console_updater = gevent.spawn(self.update_console)
while self.running:
try:
gevent.sleep(DEVICE_POLL_INTERVAL)
except KeyboardInterrupt:
self.running = False
else:
print("Could not find device")
print("-------------------------")
for device in hid.find_all_hid_devices():
print(device.vendor_name)
print(device.product_name)
print(device.vendor_id)
print(device.product_id)
print(device.serial_number)
print("-------------------------")
print("Please include this information if you open a new issue.")
except Exception, ex:
print(ex.message)
示例12: raw_test
def raw_test():
GRAND_PIANO = 0
CHURCH_ORGAN = 19
global instrument
instrument = GRAND_PIANO
pygame.init()
pygame.midi.init()
global midi_out
port = pygame.midi.get_default_output_id()
print ("using output_id :%s:" % port)
midi_out = pygame.midi.Output(port, 0)
midi_out.set_instrument(instrument)
# simple test
# browse devices...
all_hids = hid.find_all_hid_devices()
if all_hids:
# while True:
print("Choose a device to monitor raw input reports:\n")
print("0 => Exit")
for index, device in enumerate(all_hids):
device_name = unicode("{0.vendor_name} {0.product_name}" \
"(vID=0x{1:04x}, pID=0x{2:04x})"\
"".format(device, device.vendor_id, device.product_id))
print("{0} => {1}".format(index+1, device_name))
if 'DJ' in device_name:
print "DETECTED DJ DECK"
index_option = index+1
# print("\n\tDevice ('0' to '%d', '0' to exit?) " \
# "[press enter after number]:" % len(all_hids))
# index_option = raw_input()
# if index_option.isdigit() and int(index_option) <= len(all_hids):
# invalid
# break;
int_option = int(index_option)
global prevdata
prevdata=[0,0,0,8,128,128,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,224,13,11];
if int_option:
device = all_hids[int_option-1]
try:
device.open()
#set custom raw data handler
device.set_raw_data_handler(sample_handler)
print("\nWaiting for data...\nPress any (system keyboard) key to stop...")
while device.is_plugged():
#just keep the device opened to receive events
sleep(600)
return
finally:
device.close()
else:
print("There's not any non system HID class device available")
示例13: show_hids
def show_hids(self):
all_hids = hid.find_all_hid_devices()
if all_hids:
self.logText.append( "Available HID devices:" )
for hid_device in all_hids:
self.logText.append( " vId={0:04X}, pId= {1:04X}".format(
hid_device.vendor_id, hid_device.product_id ))
else:
self.logText.append( "No HID USB devices attached now" )
示例14: detect_device
def detect_device():
all_hids = hid.find_all_hid_devices()
pads = []
for hids in all_hids:
tmp = 1
matchObj = re.match(r'HID\\VID_0B43&PID_0003', hids.instance_id, re.M)
if matchObj:
pads.append(hids)
return pads
示例15: get_devices
def get_devices(self):
"""
Called to get the usb devices on the machine
:return: List of the HIDDevices
"""
self.devices = hid.find_all_hid_devices()
device_names = []
for device in self.devices:
device_names.append(device.product_name)
return tuple(device_names)