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

termios.error: (5, 'Input/output error') #417

Open
sunbearc22 opened this issue Feb 22, 2019 · 0 comments
Open

termios.error: (5, 'Input/output error') #417

sunbearc22 opened this issue Feb 22, 2019 · 0 comments

Comments

@sunbearc22
Copy link

I am encountering this error when an ESP32 device is unplugged at the usb connector.

Background: Initial serial connection was established using esptool.py, which used pyserial. I wrote a method to do certain actions when connection to the serial port is lost and not break my apprication. Below shows the error msgs:

Traceback (most recent call last):
  File "~/Esp32/test.py", line 291, in _check_connection
    self.esp.flush_input()
  File "~/.local/share/virtualenvs/Esp32-zoIgntnu/bin/esptool.py", line 392, in flush_input
    self._port.flushInput()
  File "~/.local/share/virtualenvs/Esp32-zoIgntnu/lib/python3.6/site-packages/serial/serialutil.py", line 584, in flushInput
    self.reset_input_buffer()
  File "~/.local/share/virtualenvs/Esp32-zoIgntnu/lib/python3.6/site-packages/serial/serialposix.py", line 595, in reset_input_buffer
    termios.tcflush(self.fd, termios.TCIFLUSH)
termios.error: (5, 'Input/output error')

Part of my monitoring method:

    def _check_connection( self ):
        print('\ndef _check_connection( self ):')
        if self._connected: 
            try:
                self.esp.flush_input()
            except SerialException as e:
                self._connected = False
                print( 'SerialException: ', e )
            except TypeError as e:
                self._connected = False
                self.esp._port.close()
                print( 'TypeError: ', e )
            else:
                print( 'Read! ' )
                self.after( 5000, self._check_connection ) # Check connection every 5s.

Assessment: I think both serialposix.py and esptool.py should execute lines 595 and 584, respectively, in a "try-except" statement and raise a SerialException so that users can gracefully handle error relating to disconnected serial port. I have communicated this matter to esptool.py and it's maintainer suggested I alert pyserial maintainer on this issue.

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