简体   繁体   中英

Getting error “serial.serialutil.SerialException: [Errno 2] could not open port /dev/rfcomm0” with pyserial

I want to communicate with my serial port in python. I installed pyserial for linux:

import thread
import serial
PORT = '/dev/rfcomm0'
BAUDRATE = 921600
TIMEOUT = 1  
port = serial.Serial(port=PORT, baudrate=BAUDRATE, timeout=TIMEOUT)
port.open()
...
port.close()

It gives the following error:

Traceback (most recent call last):
  File "/home/dnaphone/PycharmProjects/test/BluetoothClient.py", line 12, in <module>
    port = serial.Serial(port=PORT, baudrate=BAUDRATE, timeout=TIMEOUT)
  File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 182, in __init__
    self.open()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 247, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/rfcomm0: [Errno 2] No such file or directory: '/dev/rfcomm0'

only you have to do this:

sudo chmod 777 /dev/rfcomm0 

it has already solved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM