Python Forum
Python3 - serial port reload
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python3 - serial port reload
#1
Question 
I am having a problem reading/writing to a serial port after the port has been disconnected. I can successfully connect to my device and communicate with it. Then I execute a voluntary disconnect, I reopen the port but I am unable to write/read. Is it possible to reload the port without restarting the script?

The ttyACM* port has an active symlink connection in /etc/udev/rules.d/99-usb-serial.rules:
SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", SYMLINK+="ttyACM_dev0"
To open the port:
#!/usr/bin/python3 python3
# -*- coding: utf-8 -*-

import serial
global ser0

# open the dev0 serial port
try:
    ser0 = serial.Serial("/dev/ttyACM_dev0")
    ser0.isOpen()
except serial.serialutil.SerialException:
    ser0 = None
else:
    print (ser0.name, 'port opened successfully')
The error usually is like:
Error:
ser1.flushOutput() # Clear output buffer File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 587, in flushOutput self.reset_output_buffer() File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 604, in reset_output_buffer termios.tcflush(self.fd, termios.TCOFLUSH) termios.error: (5, 'Input/output error')
Reply


Messages In This Thread
Python3 - serial port reload - by parovelb - Apr-07-2021, 12:34 PM
RE: Python3 - serial port reload - by Larz60+ - Apr-07-2021, 04:38 PM
RE: Python3 - serial port reload - by parovelb - Apr-07-2021, 07:39 PM
RE: Python3 - serial port reload - by Larz60+ - Apr-07-2021, 10:34 PM
RE: Python3 - serial port reload - by parovelb - Apr-08-2021, 09:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,152 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 476 Mar-19-2024, 09:02 AM
Last Post: zazas321
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,378 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,538 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  python serial port barryjo 2 1,687 Dec-27-2021, 11:09 PM
Last Post: barryjo
  is there a way to mention port range or search for port dynamically with qConnection Creepy 0 1,500 Sep-09-2021, 03:15 PM
Last Post: Creepy
  How to Properly Open a Serial Port in a Function bill_z 2 4,515 Jul-22-2021, 12:54 PM
Last Post: bill_z
  Unable to read from serial port br0kenpixel 1 2,512 Aug-08-2020, 10:03 PM
Last Post: Larz60+
  Read Data from Serial Port PA3040 3 3,213 Feb-16-2020, 04:54 AM
Last Post: PA3040
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,958 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020