Reputation: 1
This is a Python program to receive the data from an XBee module using the python-xBee library. I have installed both the xbee
and pyserial
modules.
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.
Upvotes: 0
Views: 4770
Reputation: 11694
In Linux, check the permissions on the tty device (ls -l /dev/ttyUSB0
) to ensure that you have read/write access to it. 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? Do you still have it open in another program when you're trying to open it in Python? Only one program can access a COM port at a time.
Upvotes: 1