0
votes

Something I can't seem to find the answer for. Please bare in mind I am not an expert so I may be missing simple, perhaps how I'm printing the device I want. I am trying to store a device version number (dvm from herein), off a USB device. The problem is the USB device has two columns for reporting, feature and output.

So when I print the device I receive two sets of print statements.

#

def device(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
#

When this function is called it will print all devices but I end up with the following result (Modified pids/vids etc for privacy issues.)

[HID device (vID=0x0000, pID=0x0000, v=0x0000); Make; Model, Path: \?\hid#vid_0000&pid_0000&col01#7&00000000&1&0000#{00000000-0000-0000-0000-000000000000}, HID device (vID=0x0000, pID=0x0000, v=0x0000); Make; Model, Path: \?\hid#vid_0000&pid_0000&col02#7&00000000&1&0000#{00000000-0000-0000-0000-000000000000}

The important part is the col01 and col02.

How can I filter that second enumerated HID device out?

1

1 Answers

0
votes

Included the following code.

for report in device.find_output_reports(): 
                    if target_usage in report:
                        # add to target list
                        Targets.append(device)

            finally:
                device.close()

        for item in Targets:        

            try:
                item.open(output_only = True)
                dvm = unicode("%04x" % \
                (device.version_number))
                print dvm
            finally:
                item.close()

Problem resolved.