parameters: (self)
docstring: \
          Open port with current settings. This may throw a SerialException
          if the port cannot be opened.
docstring_summary: \
          Open port with current settings. This may throw a SerialException
          if the port cannot be opened.
docstring_tokens: \ Open port with current settings . This may throw a SerialException if the port cannot be opened .
function: def open(self):
          """\
          Open port with current settings. This may throw a SerialException
          if the port cannot be opened.
          """
          self.logger = None
          self._ignore_set_control_answer = False
          self._poll_modem_state = False
          self._network_timeout = 3
          if self._port is None:
              raise SerialException("Port must be configured before it can be used.")
          if self.is_open:
              raise SerialException("Port is already open.")
          try:
              self._socket = socket.create_connection(self.from_url(self.portstr), timeout=5)  # XXX good value?
              self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
          except Exception as msg:
              self._socket = None
              raise SerialException("Could not open port {}: {}".format(self.portstr, msg))
  
          # use a thread save queue as buffer. it also simplifies implementing
          # the read timeout
          self._read_buffer = Queue.Queue()
          # to ensure that user writes does not interfere with internal
          # telnet/rfc2217 options establish a lock
          self._write_lock = threading.Lock()
          # name the following separately so that, below, a check can be easily done
          mandadory_options = [
              TelnetOption(self, 'we-BINARY', BINARY, WILL, WONT, DO, DONT, INACTIVE),
              TelnetOption(self, 'we-RFC2217', COM_PORT_OPTION, WILL, WONT, DO, DONT, REQUESTED),
          ]
          # all supported telnet options
          self._telnet_options = [
              TelnetOption(self, 'ECHO', ECHO, DO, DONT, WILL, WONT, REQUESTED),
              TelnetOption(self, 'we-SGA', SGA, WILL, WONT, DO, DONT, REQUESTED),
              TelnetOption(self, 'they-SGA', SGA, DO, DONT, WILL, WONT, REQUESTED),
              TelnetOption(self, 'they-BINARY', BINARY, DO, DONT, WILL, WONT, INACTIVE),
              TelnetOption(self, 'they-RFC2217', COM_PORT_OPTION, DO, DONT, WILL, WONT, REQUESTED),
          ] + mandadory_options
          # RFC 2217 specific states
          # COM port settings
          self._rfc2217_port_settings = {
              'baudrate': TelnetSubnegotiation(self, 'baudrate', SET_BAUDRATE, SERVER_SET_BAUDRATE),
              'datasize': TelnetSubnegotiation(self, 'datasize', SET_DATASIZE, SERVER_SET_DATASIZE),
              'parity':   TelnetSubnegotiation(self, 'parity',   SET_PARITY,   SERVER_SET_PARITY),
              'stopsize': TelnetSubnegotiation(self, 'stopsize', SET_STOPSIZE, SERVER_SET_STOPSIZE),
          }
          # There are more subnegotiation objects, combine all in one dictionary
          # for easy access
          self._rfc2217_options = {
              'purge':    TelnetSubnegotiation(self, 'purge',    PURGE_DATA,   SERVER_PURGE_DATA),
              'control':  TelnetSubnegotiation(self, 'control',  SET_CONTROL,  SERVER_SET_CONTROL),
          }
          self._rfc2217_options.update(self._rfc2217_port_settings)
          # cache for line and modem states that the server sends to us
          self._linestate = 0
          self._modemstate = None
          self._modemstate_timeout = Timeout(-1)
          # RFC 2217 flow control between server and client
          self._remote_suspend_flow = False
  
          self.is_open = True
          self._thread = threading.Thread(target=self._telnet_read_loop)
          self._thread.setDaemon(True)
          self._thread.setName('pySerial RFC 2217 reader thread for {}'.format(self._port))
          self._thread.start()
  
          try:    # must clean-up if open fails
              # negotiate Telnet/RFC 2217 -> send initial requests
              for option in self._telnet_options:
                  if option.state is REQUESTED:
                      self.telnet_send_option(option.send_yes, option.option)
              # now wait until important options are negotiated
              timeout = Timeout(self._network_timeout)
              while not timeout.expired():
                  time.sleep(0.05)    # prevent 100% CPU load
                  if sum(o.active for o in mandadory_options) == sum(o.state != INACTIVE for o in mandadory_options):
                      break
              else:
                  raise SerialException(
                      "Remote does not seem to support RFC2217 or BINARY mode {!r}".format(mandadory_options))
              if self.logger:
                  self.logger.info("Negotiated options: {}".format(self._telnet_options))
  
              # fine, go on, set RFC 2271 specific things
              self._reconfigure_port()
              # all things set up get, now a clean start
              if not self._dsrdtr:
                  self._update_dtr_state()
              if not self._rtscts:
                  self._update_rts_state()
              self.reset_input_buffer()
              self.reset_output_buffer()
          except:
              self.close()
              raise
function_tokens: def open ( self ) : self . logger = None self . _ignore_set_control_answer = False self . _poll_modem_state = False self . _network_timeout = 3 if self . _port is None : raise SerialException ( "Port must be configured before it can be used." ) if self . is_open : raise SerialException ( "Port is already open." ) try : self . _socket = socket . create_connection ( self . from_url ( self . portstr ) , timeout = 5 ) # XXX good value? self . _socket . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , 1 ) except Exception as msg : self . _socket = None raise SerialException ( "Could not open port {}: {}" . format ( self . portstr , msg ) ) # use a thread save queue as buffer. it also simplifies implementing # the read timeout self . _read_buffer = Queue . Queue ( ) # to ensure that user writes does not interfere with internal # telnet/rfc2217 options establish a lock self . _write_lock = threading . Lock ( ) # name the following separately so that, below, a check can be easily done mandadory_options = [ TelnetOption ( self , 'we-BINARY' , BINARY , WILL , WONT , DO , DONT , INACTIVE ) , TelnetOption ( self , 'we-RFC2217' , COM_PORT_OPTION , WILL , WONT , DO , DONT , REQUESTED ) , ] # all supported telnet options self . _telnet_options = [ TelnetOption ( self , 'ECHO' , ECHO , DO , DONT , WILL , WONT , REQUESTED ) , TelnetOption ( self , 'we-SGA' , SGA , WILL , WONT , DO , DONT , REQUESTED ) , TelnetOption ( self , 'they-SGA' , SGA , DO , DONT , WILL , WONT , REQUESTED ) , TelnetOption ( self , 'they-BINARY' , BINARY , DO , DONT , WILL , WONT , INACTIVE ) , TelnetOption ( self , 'they-RFC2217' , COM_PORT_OPTION , DO , DONT , WILL , WONT , REQUESTED ) , ] + mandadory_options # RFC 2217 specific states # COM port settings self . _rfc2217_port_settings = { 'baudrate' : TelnetSubnegotiation ( self , 'baudrate' , SET_BAUDRATE , SERVER_SET_BAUDRATE ) , 'datasize' : TelnetSubnegotiation ( self , 'datasize' , SET_DATASIZE , SERVER_SET_DATASIZE ) , 'parity' : TelnetSubnegotiation ( self , 'parity' , SET_PARITY , SERVER_SET_PARITY ) , 'stopsize' : TelnetSubnegotiation ( self , 'stopsize' , SET_STOPSIZE , SERVER_SET_STOPSIZE ) , } # There are more subnegotiation objects, combine all in one dictionary # for easy access self . _rfc2217_options = { 'purge' : TelnetSubnegotiation ( self , 'purge' , PURGE_DATA , SERVER_PURGE_DATA ) , 'control' : TelnetSubnegotiation ( self , 'control' , SET_CONTROL , SERVER_SET_CONTROL ) , } self . _rfc2217_options . update ( self . _rfc2217_port_settings ) # cache for line and modem states that the server sends to us self . _linestate = 0 self . _modemstate = None self . _modemstate_timeout = Timeout ( - 1 ) # RFC 2217 flow control between server and client self . _remote_suspend_flow = False self . is_open = True self . _thread = threading . Thread ( target = self . _telnet_read_loop ) self . _thread . setDaemon ( True ) self . _thread . setName ( 'pySerial RFC 2217 reader thread for {}' . format ( self . _port ) ) self . _thread . start ( ) try : # must clean-up if open fails # negotiate Telnet/RFC 2217 -> send initial requests for option in self . _telnet_options : if option . state is REQUESTED : self . telnet_send_option ( option . send_yes , option . option ) # now wait until important options are negotiated timeout = Timeout ( self . _network_timeout ) while not timeout . expired ( ) : time . sleep ( 0.05 ) # prevent 100% CPU load if sum ( o . active for o in mandadory_options ) == sum ( o . state != INACTIVE for o in mandadory_options ) : break else : raise SerialException ( "Remote does not seem to support RFC2217 or BINARY mode {!r}" . format ( mandadory_options ) ) if self . logger : self . logger . info ( "Negotiated options: {}" . format ( self . _telnet_options ) ) # fine, go on, set RFC 2271 specific things self . _reconfigure_port ( ) # all things set up get, now a clean start if not self . _dsrdtr : self . _update_dtr_state ( ) if not self . _rtscts : self . _update_rts_state ( ) self . reset_input_buffer ( ) self . reset_output_buffer ( ) except : self . close ( ) raise