2013-06-19 56 views
0

我一直在試圖用Python發送命令給DYMO labelmanager PnP USB設備發送命令。我嘗試安裝pyUSB並嘗試使用pyUSB教程中提供的代碼來弄清楚USB通信是如何工作的,但它不起作用。從pyUSB教程代碼: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:\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) 

問題在哪裏?

(也當然有讀取功能需要兩個參數,僅1中給出,但我已經嘗試過調查,我不知道其他人需要理由是什麼)

回答

0

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)

+0

由於調用它,但沒有奏效。現在它提供了一個錯誤:在文件「C:\ Python27 \ lib \ site-packages \ usb \ backend \ libusb01.py」中,第384行,在_check中 raise USBError(errmsg,ret) USBError:[Errno None] libusb0- dll:err [control_msg]發送控制消息失敗,win錯誤:請求不受支持。 – user2496332

+0

這是另一個錯誤,也許你可以問一個不同的問題 – jabaldonedo