(vendor_id, product_id, endpoint)
Opens and returns the HID device

    :param int vendor_id: The vendor id of the device (e.g. ``0x1038``)).
    :param int product_id: The product id of the device (e.g. ``0x1710``).
    :param int endpoint: The number of the endpoint to open on the device (e.g.
                         ``0``).

    :raise DeviceNotFound: The requested device is not plugged to the computer
                           or it does not provide the requested endpoint.
    :raise IOError: The device or its interface cannot be opened (permission
                    issue, device busy,...).

    :rtype: hid.device

    >>> from rivalcfg import usbhid
    >>> usbhid.open_device(0x1038, 0x1702, 0)
    <hid.device at 0x...>
Opens and returns the HID device
Opens and returns the HID device
def open_device(vendor_id, product_id, endpoint):
    """Opens and returns the HID device

    :param int vendor_id: The vendor id of the device (e.g. ``0x1038``)).
    :param int product_id: The product id of the device (e.g. ``0x1710``).
    :param int endpoint: The number of the endpoint to open on the device (e.g.
                         ``0``).

    :raise DeviceNotFound: The requested device is not plugged to the computer
                           or it does not provide the requested endpoint.
    :raise IOError: The device or its interface cannot be opened (permission
                    issue, device busy,...).

    :rtype: hid.device

    >>> from rivalcfg import usbhid
    >>> usbhid.open_device(0x1038, 0x1702, 0)
    <hid.device at 0x...>
    """
    # Instanciate the device (real or fake depending of environment)
    if "RIVALCFG_DRY" in os.environ:
        # Setting a path allows the fake device to be opened even if requested
        # device is not plugged to the computer
        path = b"00:0000:0000"
        device = FakeDevice()
    else:
        path = None
        device = hid.device()

    # Search the device
    for interface in hid.enumerate(vendor_id, product_id):
        if interface["interface_number"] == endpoint:
            path = interface["path"]
            break

    # Open the found device. This can raise an IOError.
    if path:
        device.open_path(path)
        return device

    # No matching device found
    raise DeviceNotFound(
        "Requested device or endpoint not found: %04x:%04x:%02x"
        % (vendor_id, product_id, endpoint)
    )
def open_device ( vendor_id , product_id , endpoint ) : # Instanciate the device (real or fake depending of environment) if "RIVALCFG_DRY" in os . environ : # Setting a path allows the fake device to be opened even if requested # device is not plugged to the computer path = b"00:0000:0000" device = FakeDevice ( ) else : path = None device = hid . device ( ) # Search the device for interface in hid . enumerate ( vendor_id , product_id ) : if interface [ "interface_number" ] == endpoint : path = interface [ "path" ] break # Open the found device. This can raise an IOError. if path : device . open_path ( path ) return device # No matching device found raise DeviceNotFound ( "Requested device or endpoint not found: %04x:%04x:%02x" % ( vendor_id , product_id , endpoint ) )