Open port with current settings. This may throw a SerialException if the port cannot be opened.
(self)
| 54 | thus usable with jython and the appropriate java extension.""" |
| 55 | |
| 56 | def open(self): |
| 57 | """Open port with current settings. This may throw a SerialException |
| 58 | if the port cannot be opened.""" |
| 59 | if self._port is None: |
| 60 | raise SerialException("Port must be configured before it can be used.") |
| 61 | if self._isOpen: |
| 62 | raise SerialException("Port is already open.") |
| 63 | if type(self._port) == type(''): # strings are taken directly |
| 64 | portId = comm.CommPortIdentifier.getPortIdentifier(self._port) |
| 65 | else: |
| 66 | portId = comm.CommPortIdentifier.getPortIdentifier(device(self._port)) # numbers are transformed to a comport id obj |
| 67 | try: |
| 68 | self.sPort = portId.open("python serial module", 10) |
| 69 | except Exception, msg: |
| 70 | self.sPort = None |
| 71 | raise SerialException("Could not open port: %s" % msg) |
| 72 | self._reconfigurePort() |
| 73 | self._instream = self.sPort.getInputStream() |
| 74 | self._outstream = self.sPort.getOutputStream() |
| 75 | self._isOpen = True |
| 76 | |
| 77 | def _reconfigurePort(self): |
| 78 | """Set communication parameters on opened port.""" |
nothing calls this directly
no test coverage detected