#NEWLINE# def open( self ) : #NEWLINE# #INDENT# '        Open port with current settings. This may throw a SerialException\n        if the port cannot be opened.' #NEWLINE# if ( self . _port is None ) : #NEWLINE# #INDENT# raise SerialException ( 'Port must be configured before it can be used.' ) #NEWLINE# #UNINDENT# if self . is_open : #NEWLINE# #INDENT# raise SerialException ( 'Port is already open.' ) #NEWLINE# #UNINDENT# self . fd = None #NEWLINE# try : #NEWLINE# #INDENT# self . fd = os . open ( self . portstr , ( ( os . O_RDWR | os . O_NOCTTY ) | os . O_NONBLOCK ) ) #NEWLINE# #UNINDENT# except OSError as msg : #NEWLINE# #INDENT# self . fd = None #NEWLINE# raise SerialException ( msg . errno , 'could not open port {}: {}' . format ( msg . _port , msg ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . _reconfigure_port ( force_update = True ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . close ( self . fd ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# self . fd = None #NEWLINE# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . is_open = True #NEWLINE# #UNINDENT# if ( not self . _dsrdtr ) : #NEWLINE# #INDENT# self . _update_dtr_state ( ) #NEWLINE# #UNINDENT# if ( not self . _rtscts ) : #NEWLINE# #INDENT# self . _update_rts_state ( ) #NEWLINE# #UNINDENT# self . reset_input_buffer ( )