You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add DriverBase abstract class to eliminate code duplication
Created abstract base class that all drivers inherit from, providing automatic transport management, built-in caching, USB TMC detection, and common helper methods. Migrated all 6 drivers (TenmaPSU, OWONXDM, RigolDHO800, OWONSPM, OwonDGE, OwonOEL) to new architecture, eliminating ~168 lines of duplicate code while maintaining full backward compatibility. Drivers now require no constructor and only implement device-specific methods.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
4. Update `drivers/classes.json` if adding new 3-letter class codes
352
-
5. Add driver instantiation logic to `driver_factory.py` if needed
353
-
6. Create tests in `tests/` using pytest and mock serial communication
356
+
5. Create tests in `tests/` using pytest and mock serial communication
354
357
355
358
**Driver Naming Convention:**
356
359
- **Query methods** (read): prefix with `query_` (e.g., `query_voltage`, `query_current`)
357
360
- **Setter methods** (write): prefix with `set_` (e.g., `set_voltage`, `set_current`)
358
361
- This enables the API's smart resolution: GET `/voltage` → `query_voltage()`, POST `/current/2.5` → `set_current()`
359
362
360
-
Driver should accept `transport: Transport` in constructor and use it for all communication. The Transport interface supports multiple physical transports (SerialTransport for RS232/USB-Serial, with USB TMC and TCP/IP support planned).
361
-
362
-
**Optional Caching:**
363
-
Drivers can use `SimpleCache` to minimize redundant SCPI calls between polling and API requests:
364
-
- Import: `from ...cache import SimpleCache`
365
-
- Initialize in `__init__()`: `self.cache = SimpleCache()`
366
-
- Use in `poll_status()`: Check `self.cache.get(key)` before querying, call `self.cache.set(key, value)` after query
367
-
- Invalidate in `set_*` methods: Call `self.cache.invalidate(key)` when device state changes
363
+
**DriverBase Inheritance:**
364
+
All drivers inherit from `DriverBase` which provides:
365
+
- **Automatic transport management**: Access via `self.t` (no constructor needed)
366
+
- **Built-in caching**: Use `self.cache` (SimpleCache instance automatically created)
367
+
- **Common methods**: `close()`, `is_connected()`, `set_reset()` (with USB TMC auto-detection)
0 commit comments