簡體   English   中英

當我嘗試運行此Python程序時,出現回溯錯誤(最近一次調用最近)。 我想知道解決方案

[英]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

這是一個Python程序,它使用python-xBee庫從XBee模塊接收數據。 我已經安裝了xbeepyserial模塊。

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

我不明白問題是什么。 我嘗試了所有操作,但是每次都會出現相同的錯誤。

在Linux中,檢查tty設備( ls -l /dev/ttyUSB0 )的權限,以確保您具有對該設備的讀/寫訪問權限。 請注意,它可能具有不同的名稱。

對於Windows,您是否能夠使用終端仿真器打開COM5並在XBee上發送/接收數據? 當您嘗試在Python中打開它時,還在其他程序中打開它嗎? 一次只能有一個程序可以訪問COM端口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM