【发布时间】:2014-08-14 18:25:24
【问题描述】:
嘿, 是的,我正在编写一个 python3 程序,它应该将文件的内容发送到 LPC1758。 为了测试,我将在 USB 上方写一个简单的字符串。我用 libusb1.0 ....
但是每次我变成同样的错误,即使我将“dev”重命名为“device”,错误也是一样的。 --> AttributeError: 'MainWindow' 对象没有属性 'dev'
class MainWindow(QtGui.QMainWindow, form_class):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.pb_send.clicked.connect(self.pb_send_clicked)
self.pb_open.clicked.connect(self.pb_open_clicked)
self.pb_exit.clicked.connect(self.pb_exit_clicked)
# SEND button event handler
def pb_send_clicked(self):
send = "Yo Man"
bulk_out_ep = 0x05
bulk_in_ep = 0x82
interface = 0
length = 30
dev = usb.core.find(idVendor= 0xfefe, idProduct= 0x0001)
cfg = usb.control.get_configuration(dev) # get current configuration
print(dev)
if dev is None:
self.USB_label.setText("Device not found !!!")
raise ValueError('Device not found')
else:
self.USB_label.setText("Device found")
found = 1
if(cfg != 1): # check if device is configured
usb.DeviceHandle.setConfiguration(self, 1)
usb.util.claim_interface(dev, interface)
usb.DeviceHandle.bulkWrite(self,bulk_out_ep,send)
print("wrote to estick")
readData = usb.DeviceHandle.bulkRead(self, bulk_in_ep, length)
print("read from estick: "+ readData)
usb.util.release_interface(dev, interface)
这是 Stacktrace 显示的内容:
Traceback (most recent call last):
File "/home/user/workspace_Qt/ESS_project/ess_project.py", line 93, in pb_send_clicked
readData = usb.DeviceHandle.bulkRead(self,endpoint=bulk_in_ep,size=length)
File "/usr/lib/python3.3/usb/legacy.py", line 159, in bulkRead
return self.dev.read(endpoint, size, self.__claimed_interface, timeout)
AttributeError: 'MainWindow' object has no attribute 'dev'
【问题讨论】:
-
我不认为错误来自提供的代码,因为我在这段代码中看不到任何可能导致上述错误的内容。请通过查看
stacktrace并找到错误的行号,确保您从这段代码中得到了该错误。 -
这是我的堆栈跟踪输出的内容:
回溯(最后一次调用):
文件“/home/hummer/workspace_Qt/ESS_project/ess_project.py”,第 93 行,在 pb_send_clicked
readData = usb.DeviceHandle.bulkRead(self,endpoint=bulk_in_ep,size=length)
文件“/usr/lib/python3.3/usb/legacy.py”,第 159 行,在bulkRead
return self.dev.read(endpoint, size, self.__claimed_interface, timeout)
AttributeError: 'MainWindow' object has no attribute 'dev'
我不知道这是什么意思。 ..
标签: python-3.x pyqt4 pycharm xubuntu