Created
January 8, 2023 16:53
-
-
Save kourbou/6b10a65c885853d36a96ee8438a3989e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from serial import Serial | |
| class ExpoVoltageController: | |
| vid: int = 0x2341 | |
| pid: int = 0x0058 | |
| sid: str = "8E4E27AB515146544E4B2020FF090D2F" | |
| def __init__(self, port: str, verbose: bool = False) -> None: | |
| self.serial = Serial(port, baudrate=115200, timeout=10) | |
| @classmethod | |
| def discover(cls, verbose: bool = False) -> ExpoVoltageController: | |
| from serial.tools.list_ports import comports # type: ignore | |
| for port in comports(): | |
| assert port.vid and port.pid and port.serial_number | |
| if ( | |
| port.vid == cls.vid | |
| and port.pid == cls.pid | |
| and port.serial_number == cls.sid | |
| ): | |
| return cls(port.device, verbose) | |
| raise RuntimeError("Failed to discover voltage controller with specified ids.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment