Factory function to create the appropriate serial interface. Args: port: Serial port path (e.g., "/dev/ttyUSB0", "COM3") baud_rate: Serial baud rate (default: 115200) use_pyserial: If True, use pyserial directly instead of fbuild auto_reconnect: Enable auto-recon
(
port: str,
baud_rate: int = 115200,
use_pyserial: bool = False,
auto_reconnect: bool = True,
verbose: bool = False,
)
| 241 | |
| 242 | |
| 243 | def create_serial_interface( |
| 244 | port: str, |
| 245 | baud_rate: int = 115200, |
| 246 | use_pyserial: bool = False, |
| 247 | auto_reconnect: bool = True, |
| 248 | verbose: bool = False, |
| 249 | ) -> SerialInterface: |
| 250 | """Factory function to create the appropriate serial interface. |
| 251 | |
| 252 | Args: |
| 253 | port: Serial port path (e.g., "/dev/ttyUSB0", "COM3") |
| 254 | baud_rate: Serial baud rate (default: 115200) |
| 255 | use_pyserial: If True, use pyserial directly instead of fbuild |
| 256 | auto_reconnect: Enable auto-reconnect (passed to underlying monitor) |
| 257 | verbose: Enable verbose debug output |
| 258 | |
| 259 | Returns: |
| 260 | SerialInterface implementation (PySerialAdapter or FbuildSerialAdapter) |
| 261 | """ |
| 262 | if use_pyserial: |
| 263 | return PySerialAdapter( |
| 264 | port=port, |
| 265 | baud_rate=baud_rate, |
| 266 | auto_reconnect=auto_reconnect, |
| 267 | verbose=verbose, |
| 268 | ) |
| 269 | else: |
| 270 | return FbuildSerialAdapter( |
| 271 | port=port, |
| 272 | baud_rate=baud_rate, |
| 273 | auto_reconnect=auto_reconnect, |
| 274 | verbose=verbose, |
| 275 | ) |