0

I have been trying to make serial work with Python and Pi3, however so far I have been unsuccessful.

When running the Python script, I am getting an error "serial.serialutil.SerialException: Port is already open."

I have already tried all tips in another post that should solve issues with Pi3 and the Bluetooth port. (How do I make serial work on the Raspberry Pi3)

My python script is the following:

import serial
ser = serial.Serial('/dev/serial0', 9600, timeout=1)
ser.open()

ser.write("testing")
try:
    while 1:
        response = ser.readline()
        print response
except KeyboardInterrupt:
    ser.close()

Any suggestions?

Martin
  • 113
  • 1
  • 6

1 Answers1

1

The line ser = serial.Serial('/dev/serial0', 9600, timeout=1) opens the device automatically. When you try to open the device that is already open, python raises an error. Just take out ser.open() and it will work.

jath03
  • 426
  • 1
  • 4
  • 13