

def open(self):
    'Open port with current settings. This may throw a SerialException\n           if the port cannot be opened.'
    if (self._port is None):
        raise SerialException('Port must be configured before it can be used.')
    if self._isOpen:
        raise SerialException('Port is already open.')
    port = self.portstr
    try:
        if (port.upper().startswith('COM') and (int(port[3:]) > 8)):
            port = ('\\\\.\\' + port)
    except ValueError:
        pass
    self.hComPort = win32.CreateFile(port, (win32.GENERIC_READ | win32.GENERIC_WRITE), 0, None, win32.OPEN_EXISTING, (win32.FILE_ATTRIBUTE_NORMAL | win32.FILE_FLAG_OVERLAPPED), 0)
    if (port.hComPort == win32.INVALID_HANDLE_VALUE):
        self.hComPort = None
        raise SerialException(('could not open port %s: %s' % (self.portstr, ctypes.WinError())))
    win32.SetupComm(self.hComPort, 4096, 4096)
    self._orgTimeouts = win32.COMMTIMEOUTS()
    win32.GetCommTimeouts(self.hComPort, ctypes.byref(self._orgTimeouts))
    self._rtsState = win32.RTS_CONTROL_ENABLE
    self._dtrState = win32.DTR_CONTROL_ENABLE
    self._reconfigurePort()
    win32.PurgeComm(self.hComPort, (((win32.PURGE_TXCLEAR | win32.PURGE_TXABORT) | win32.PURGE_RXCLEAR) | win32.PURGE_RXABORT))
    self._overlappedRead = win32.OVERLAPPED()
    self._overlappedRead.hEvent = win32.CreateEvent(None, 1, 0, None)
    self._overlappedWrite = win32.OVERLAPPED()
    self._overlappedWrite.hEvent = win32.CreateEvent(None, 0, 0, None)
    self._isOpen = True

dataset/ETHPy150Open Robot-Will/Stino/stino/pyarduino/base/pyserial/serialwin32.py Win32Serial.open/VarMisuse@144/245 `self`->`port`