0

I have been trying to make a program with Python which sends commands to a DYMO labelmanager PnP usb device. I tried installing pyUSB and tried the code provided in pyUSB tutorial to figure out a bit how the USB communicating works, but it doesn't work. Code from pyUSB tutorial:

(I have changed the idVendor and idProduct to cope with my device. It finds the device but writing fails)

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0x0922, idProduct=0x1001)

# was it found?
if dev is None:
    raise ValueError('Device not found')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
interface_number = cfg[(0,0)].bInterfaceNumber
alternate_setting = usb.control.get_interface(interface_number)
intf = usb.util.find_descriptor(
    cfg, bInterfaceNumber = interface_number,
    bAlternateSetting = alternate_setting
)

ep = usb.util.find_descriptor(
    intf,
    # match the first OUT endpoint
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_OUT
)

assert ep is not None

# write the data
ep.write('test')

and it gives an error:

Traceback (most recent call last):
  File "C:\Python27\proc\labelprinttest.py", line 18, in <module>
    alternate_setting = usb.control.get_interface(interface_number)
TypeError: get_interface() takes exactly 2 arguments (1 given)

where is the problem?

(well of course there reads that the function takes 2 arguments and only 1 is given, but I have tried to investigate and I have no idea what the other needed argument is)

user2496332
  • 29
  • 1
  • 2

1 Answers1

0

The definition of get_interface() is as follows:

def get_interface(dev, bInterfaceNumber):
    r"""Get the current alternate setting of the interface.

    dev is the Device object to which the request will be
    sent to.
    """

So, try to call it using usb.control.get_interface(dev, interface_number)

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
  • Thanks, but didn't work. Now it gives an error: File "C:\Python27\lib\site-packages\usb\backend\libusb01.py", line 384, in _check raise USBError(errmsg, ret) USBError: [Errno None] libusb0-dll:err [control_msg] sending control message failed, win error: The request is not supported. – user2496332 Jun 19 '13 at 10:56