Skip to content

Commit

Permalink
Merge pull request #81 from hephy-dd/refactored_mixins
Browse files Browse the repository at this point in the history
Restructured driver mixins
  • Loading branch information
arnobaer authored Aug 28, 2024
2 parents be1e9da + 6cce180 commit a66a40d
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 180 deletions.
5 changes: 4 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Base classes `PowerSupply` and `PowerSupplyChannel`.
- Generic base classes `PowerSupply` and `PowerSupplyChannel` and `LightSource`.
- Rhode&Schwarz NGE100 power supply (#77).
- Photonic F3000 LED light source (#75).

### Removed
- Dropped support for Python 3.8

## [1.0.0] - 2024-03-26

### Added
Expand Down
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ ignore_missing_imports = True

[mypy-schema.*]
ignore_missing_imports = True

[tool:pytest]
filterwarnings = ignore::DeprecationWarning
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [
]
readme = "README.md"
license = {text = "GPLv3"}
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"PyVISA",
"PyVISA-py",
Expand Down
19 changes: 17 additions & 2 deletions src/comet/driver/generic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .instrument import (
InstrumentError,
BeeperMixin,
ErrorQueueMixin,
RouteTerminalMixin,
InstrumentError,
Instrument,
)
from .source_meter_unit import SourceMeterUnit
Expand All @@ -13,4 +13,19 @@
MotionController,
MotionControllerAxis,
)
from .light_source import LightSource
from .light_source import LightSource

__all__ = [
"BeeperMixin",
"ErrorQueueMixin",
"RouteTerminalMixin",
"InstrumentError",
"Instrument",
"SourceMeterUnit",
"Electrometer",
"LCRMeter",
"SwitchingMatrix",
"MotionController",
"MotionControllerAxis",
"LightSource",
]
12 changes: 4 additions & 8 deletions src/comet/driver/generic/electrometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ class Electrometer(Instrument):
# Measurements

@abstractmethod
def measure_voltage(self) -> float:
...
def measure_voltage(self) -> float: ...

@abstractmethod
def measure_current(self) -> float:
...
def measure_current(self) -> float: ...

@abstractmethod
def measure_resistance(self) -> float:
...
def measure_resistance(self) -> float: ...

@abstractmethod
def measure_charge(self) -> float:
...
def measure_charge(self) -> float: ...
64 changes: 34 additions & 30 deletions src/comet/driver/generic/instrument.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from abc import ABC, abstractmethod
from typing import List, Iterable, Optional, Tuple
from typing import Optional

from ..driver import Driver

__all__ = [
"InstrumentError",
"BeeperMixin",
"IdentifyMixin",
"ResetMixin",
"ClearMixin",
"ErrorQueueMixin",
"BeeperMixin",
"RouteTerminalMixin",
"Instrument",
]
Expand All @@ -23,55 +26,56 @@ def __repr__(self) -> str:
return f"{cls_name}({self.code}, {self.message!r})"


class BeeperMixin(ABC):
class IdentifyMixin(ABC):

BEEPER_ON: bool = True
BEEPER_OFF: bool = False
@abstractmethod
def identify(self) -> str: ...


class ResetMixin(ABC):

@property # type: ignore
@abstractmethod
def beeper(self) -> bool:
...
def reset(self) -> None: ...


class ClearMixin(ABC):

@beeper.setter # type: ignore
@abstractmethod
def beeper(self, value: bool) -> None:
...
def clear(self) -> None: ...


class ErrorQueueMixin(ABC):

@abstractmethod
def next_error(self) -> Optional[InstrumentError]:
...
def next_error(self) -> Optional[InstrumentError]: ...


class RouteTerminalMixin(ABC):
class BeeperMixin(ABC):

ROUTE_TERMINAL_FRONT: str = "front"
ROUTE_TERMINAL_REAR: str = "rear"
BEEPER_ON: bool = True
BEEPER_OFF: bool = False

@property # type: ignore
@property
@abstractmethod
def route_terminal(self) -> str:
...
def beeper(self) -> bool: ...

@route_terminal.setter # type: ignore
@beeper.setter
@abstractmethod
def route_terminal(self, route_terminal: str) -> None:
...
def beeper(self, value: bool) -> None: ...


class Instrument(ErrorQueueMixin, Driver):
class RouteTerminalMixin(ABC):

@abstractmethod
def identify(self) -> str:
...
ROUTE_TERMINAL_FRONT: str = "front"
ROUTE_TERMINAL_REAR: str = "rear"

@property
@abstractmethod
def reset(self) -> None:
...
def route_terminal(self) -> str: ...

@route_terminal.setter
@abstractmethod
def clear(self) -> None:
...
def route_terminal(self, route_terminal: str) -> None: ...


class Instrument(IdentifyMixin, ResetMixin, ClearMixin, ErrorQueueMixin, Driver): ...
33 changes: 13 additions & 20 deletions src/comet/driver/generic/lcr_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,29 @@

class LCRMeter(Instrument):

@property # type: ignore
@property
@abstractmethod
def function(self) -> str:
...
def function(self) -> str: ...

@function.setter # type: ignore
@function.setter
@abstractmethod
def function(self, function: str) -> None:
...
def function(self, function: str) -> None: ...

@property # type: ignore
@property
@abstractmethod
def amplitude(self) -> float:
...
def amplitude(self) -> float: ...

@amplitude.setter # type: ignore
@amplitude.setter
@abstractmethod
def amplitude(self, level: float) -> None:
...
def amplitude(self, level: float) -> None: ...

@property # type: ignore
@property
@abstractmethod
def frequency(self) -> float:
...
def frequency(self) -> float: ...

@frequency.setter # type: ignore
@frequency.setter
@abstractmethod
def frequency(self, frequency: float) -> None:
...
def frequency(self, frequency: float) -> None: ...

@abstractmethod
def measure_impedance(self) -> Tuple[float, float]:
...
def measure_impedance(self) -> Tuple[float, float]: ...
61 changes: 21 additions & 40 deletions src/comet/driver/generic/motion_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,88 +15,69 @@ def __init__(self, resource, index: int) -> None:
self.index: int = index

@abstractmethod
def calibrate(self) -> None:
...
def calibrate(self) -> None: ...

@abstractmethod
def range_measure(self) -> None:
...
def range_measure(self) -> None: ...

@property
@abstractmethod
def is_calibrated(self) -> bool:
...
def is_calibrated(self) -> bool: ...

@abstractmethod
def move_absolute(self, value: float) -> None:
...
def move_absolute(self, value: float) -> None: ...

@abstractmethod
def move_relative(self, value: float) -> None:
...
def move_relative(self, value: float) -> None: ...

@property
@abstractmethod
def position(self) -> float:
...
def position(self) -> float: ...

@property
@abstractmethod
def is_moving(self) -> bool:
...
def is_moving(self) -> bool: ...


class MotionController(Instrument):

@abstractmethod
def __getitem__(self, index: int) -> MotionControllerAxis:
...
def __getitem__(self, index: int) -> MotionControllerAxis: ...

@abstractmethod
def calibrate(self) -> None:
...
def calibrate(self) -> None: ...

@abstractmethod
def range_measure(self) -> None:
...
def range_measure(self) -> None: ...

@property
@abstractmethod
def is_calibrated(self) -> bool:
...
def is_calibrated(self) -> bool: ...

@abstractmethod
def move_absolute(self, position: Position) -> None:
...
def move_absolute(self, position: Position) -> None: ...

@abstractmethod
def move_relative(self, position: Position) -> None:
...
def move_relative(self, position: Position) -> None: ...

@abstractmethod
def abort(self) -> None:
...
def abort(self) -> None: ...

@abstractmethod
def force_abort(self) -> None:
...
def force_abort(self) -> None: ...

@property
@abstractmethod
def position(self) -> Position:
...
def position(self) -> Position: ...

@property
@abstractmethod
def is_moving(self) -> bool:
...
def is_moving(self) -> bool: ...

@property # type: ignore
@property
@abstractmethod
def joystick_enabled(self) -> bool:
...
def joystick_enabled(self) -> bool: ...

@joystick_enabled.setter # type: ignore
@joystick_enabled.setter
@abstractmethod
def joystick_enabled(self, value: bool) -> None:
...
def joystick_enabled(self, value: bool) -> None: ...
15 changes: 9 additions & 6 deletions src/comet/driver/generic/power_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ def __init__(self, resource, channel: int) -> None:
OUTPUT_ON: bool = True
OUTPUT_OFF: bool = False

@property # type: ignore
@property
@abstractmethod
def enabled(self) -> bool: ...

@enabled.setter # type: ignore
@enabled.setter
@abstractmethod
def enabled(self, state: bool) -> None: ...

# Voltage source

@property # type: ignore
@property
@abstractmethod
def voltage_level(self) -> float: ...

@voltage_level.setter # type: ignore
@voltage_level.setter
@abstractmethod
def voltage_level(self, level: float) -> None: ...

# Current source
@property # type: ignore

@property
@abstractmethod
def current_limit(self) -> float: ...

@current_limit.setter # type: ignore
@current_limit.setter
@abstractmethod
def current_limit(self, level: float) -> None: ...

Expand All @@ -55,6 +57,7 @@ def measure_power(self) -> float: ...


class PowerSupply(Instrument):

@abstractmethod
def __getitem__(self, channel: int) -> PowerSupplyChannel: ...

Expand Down
Loading

0 comments on commit a66a40d

Please sign in to comment.