unable to open port with pySerial - serial.Serial

530 Views Asked by At

I have a few serial ports that I am trying to open with python (ipython in particular). Running python 3.8.8 in Scientific Linu 7.9. I run it with the lines

import serial
ser = serial.Serial('/dev/ttyr00', baudrate=57600, timeout=1)

and I receive the following error

SerialException: [Errno 6] could not open port /dev/ttyr00: [Errno 6] No such device or address: '/dev/ttyr00'

I don't really understand. If I run ls -lart | grep ttyr in /dev I get enter image description here so it is showing up.

I have tried running sudo chmod 666 /dev/ttyr00 based on the answers of this thread, but that was hopeful rather than expecting it to work (note I don't get the "Permission denied" error that OP does).

Any thoughts? I've had this issue before, but I can't recall how I solved it. I think I went into some file and changed something... I use two other ttyr ports, 2 and 3, and I'm getting the same issues with them.

1

There are 1 best solutions below

1
MRX On

If you are using Linux:

To determine the required port, follow these steps:

Run the following command twice. First, make sure the board or dongle is unplugged, and then run it again after plugging it in. The port that appears the second time is the one you need:

ls /dev/tty*

If the above command does not work, you can try the following:

  1. Ensure that the currently logged-in user has read and write access to the USB serial port. On most Linux distributions, this can be achieved by adding the user to the dialout group. Execute the following command:

    sudo usermod -a -G dialout $USER

If you are using MacOS:

Perform the same procedure as mentioned above, but use the following command instead:

ls /dev/cu.*