Establish connection to Serial Studio API.
(self)
| 55 | self.disconnect() |
| 56 | |
| 57 | def connect(self) -> None: |
| 58 | """Establish connection to Serial Studio API.""" |
| 59 | if self._socket: |
| 60 | return |
| 61 | |
| 62 | self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 63 | self._socket.settimeout(self.timeout) |
| 64 | try: |
| 65 | self._socket.connect((self.host, self.port)) |
| 66 | except (ConnectionRefusedError, socket.timeout) as e: |
| 67 | raise ConnectionError( |
| 68 | f"Could not connect to Serial Studio at {self.host}:{self.port}. " |
| 69 | f"Ensure Serial Studio is running with API Server enabled." |
| 70 | ) from e |
| 71 | |
| 72 | def disconnect(self) -> None: |
| 73 | """Close the connection.""" |
no outgoing calls