这是一个Python程序,用于使用 python-xBee 库从XBee模块接收数据。我已经安装了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()
但是当我运行这个以及任何带有串口的程序时,这就是我得到的错误:
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
我不明白问题所在。我尝试了所有的东西,但每次都会出现同样的错误。
答案 0 :(得分:1)
在Linux中,检查tty设备(ls -l /dev/ttyUSB0
)上的权限,以确保您具有对它的读/写访问权限。请注意,它可能具有不同的名称。
对于Windows,您是否能够使用终端仿真程序打开COM5
并在XBee上发送/接收数据?当你试图用Python打开它时,你还在另一个程序中打开它吗?一次只能有一个程序访问COM端口。