[英]I get an error of traceback (most recent call last) when I try to run this Python program. I want to know the solution to this
This is a Python program to receive the data from an XBee module using the python-xBee library. 这是一个Python程序,它使用python-xBee库从XBee模块接收数据。 I have installed both the xbee
and pyserial
modules. 我已经安装了xbee
和pyserial
模块。
import serial
from xbee import XBee
serial_port = serial.Serial('/dev/ttyUSB0', 9600)
xbee = XBee(serial_port)
while True:
try:
print xbee.wait_read_frame()
except KeyboardInterrupt:
break
serial_port.close()
But when I run this and any kind of program with serial port, this is the error I am getting: 但是,当我运行此程序以及任何带有串行端口的程序时,这是我得到的错误:
Traceback (most recent call last):
File "C:/Users/Manurajeev/PycharmProjects/untitled/one.py", line 4, in
<module>
serial_port = serial.Serial('/dev/ttyUSB0', 9600)
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 31, in
__init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Python27\lib\site-packages\serial\serialutil.py", line 240, in
__init__
self.open()
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 62, in
open
raise SerialException("could not open port {!r}:
{!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port '/dev/ttyUSB0':
WindowsError(3, 'The system cannot find the path specified.')
Process finished with exit code 1
I don't understand what the problem is. 我不明白问题是什么。 I tried everything, but the same error keeps popping up every time. 我尝试了所有操作,但是每次都会出现相同的错误。
In Linux, check the permissions on the tty device ( ls -l /dev/ttyUSB0
) to ensure that you have read/write access to it. 在Linux中,检查tty设备( ls -l /dev/ttyUSB0
)的权限,以确保您具有对该设备的读/写访问权限。 Note that it might have a different name. 请注意,它可能具有不同的名称。
For Windows, have you been able to open COM5
with a terminal emulator and send/receive data on the XBee? 对于Windows,您是否能够使用终端仿真器打开COM5
并在XBee上发送/接收数据? Do you still have it open in another program when you're trying to open it in Python? 当您尝试在Python中打开它时,还在其他程序中打开它吗? Only one program can access a COM port at a time. 一次只能有一个程序可以访问COM端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.