Problems with pyUSB



我一直在尝试用Python编写一个程序,该程序将命令发送到DYMO标签管理器PnP usb设备。我尝试安装pyUSB并尝试pyUSB教程中提供的代码来弄清楚USB通信是如何工作的,但它不起作用。代码来自pyUSB教程:

(我已经改变了idVendor和idProduct来处理我的设备。找到设备,但写入失败)

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')

并给出错误:

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

问题在哪里?

(当然有读函数需要2个参数,只有1给出,但我试图调查,我不知道其他需要的参数是什么)

get_interface()的定义如下:

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.
    """

试着用usb.control.get_interface(dev, interface_number)

来命名它

最新更新