Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serial.serialutil.PortNotOpenError: Attempting to use a port that is not open #718

Open
gokul6350 opened this issue Sep 24, 2023 · 0 comments

Comments

@gokul6350
Copy link

OS: Ubuntu 22.04.3 LTS x86_64
recently installed pyserial
worked fine with windows but not work in linux
even arduino serial working well
I know that only 1 application can use a serial at a time
i arduino IDE it shows it is connected at /dev/ttyACM0
even i gave all the permission

Exception has occurred: PortNotOpenError
Attempting to use a port that is not open
File "/home/gokul/Desktop/Yolo-ARM/Code/useless/check.py", line 14, in base_turn
connection.write(data.encode())
File "/home/gokul/Desktop/Yolo-ARM/Code/useless/check.py", line 39, in
base_turn(90)
serial.serialutil.PortNotOpenError: Attempting to use a port that is not open

code :

import serial

# Replace '/dev/ttyUSB0' with the appropriate serial port on your Linux system
port = '/dev/ttyACM0'


try:
    connection = serial.Serial(port, 9600)
    print(f"Serial {port} is working well")

    def base_turn(ang):
        rounded_ang = round(ang)
        data = f"b{rounded_ang}"
        connection.write(data.encode())

    def shoulder(ang):
        rounded_ang = round(ang) + 60
        data = f"s{rounded_ang}"
        connection.write(data.encode())

    def elbow(ang):
        rounded_ang = round(ang) + 34
        data = f"e{rounded_ang}"
        connection.write(data.encode())

    def gripper(ang):
        rounded_ang = round(ang)
        data = f"h{rounded_ang}"
        connection.write(data.encode())

except serial.SerialException as e:
    print(f"Failed to open serial port {port}: {e}")

# Add error handling and close the serial connection when done
finally:
    if 'connection' in locals() and connection.is_open:
        connection.close()
        
base_turn(90)        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant