Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/comet/driver/generic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .instrument import (
InitializeMixin,
BeeperMixin,
ErrorQueueMixin,
RouteTerminalMixin,
Expand All @@ -18,6 +19,7 @@
from .oscilloscope import Oscilloscope, OscilloscopeChannel

__all__ = [
"InitializeMixin",
"BeeperMixin",
"ErrorQueueMixin",
"RouteTerminalMixin",
Expand Down
15 changes: 7 additions & 8 deletions src/comet/driver/generic/instrument.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from abc import ABC, abstractmethod
from typing import Optional
from typing import Any, Mapping, Optional

from ..driver import Driver

__all__ = [
"InstrumentError",
"InitializeMixin",
"IdentifyMixin",
"ResetMixin",
"ClearMixin",
Expand All @@ -16,7 +17,6 @@


class InstrumentError:

def __init__(self, code: int, message: str) -> None:
self.code: int = code
self.message: str = message
Expand All @@ -26,32 +26,32 @@ def __repr__(self) -> str:
return f"{cls_name}({self.code}, {self.message!r})"


class IdentifyMixin(ABC):
class InitializeMixin(ABC):
@abstractmethod
def initialize(self) -> None: ...


class IdentifyMixin(ABC):
@abstractmethod
def identify(self) -> str: ...


class ResetMixin(ABC):

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


class ClearMixin(ABC):

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


class ErrorQueueMixin(ABC):

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


class BeeperMixin(ABC):

BEEPER_ON: bool = True
BEEPER_OFF: bool = False

Expand All @@ -65,7 +65,6 @@ def beeper(self, value: bool) -> None: ...


class RouteTerminalMixin(ABC):

ROUTE_TERMINAL_FRONT: str = "front"
ROUTE_TERMINAL_REAR: str = "rear"

Expand Down
19 changes: 16 additions & 3 deletions src/comet/driver/itk/corvustt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from comet.driver.generic import InstrumentError
from comet.driver.generic import InstrumentError, InitializeMixin
from comet.driver.generic.motion_controller import (
Position,
MotionControllerAxis,
Expand Down Expand Up @@ -65,9 +65,20 @@ def is_moving(self) -> bool:
return bool(int(result) & 0x1)


class CorvusTT(MotionController):
class CorvusTT(InitializeMixin, MotionController):
AXES: list[int] = [1, 2, 3]

def initialize(self) -> None:
# Force host mode
self.resource.write("0 mode")
# Clear clogged control characters from internal buffer.
self.resource.query("version")

def identify(self) -> str:
return self.resource.query("identify").strip()
identity = self.resource.query("identify").strip()
version = self.resource.query("version").strip()
serialno = self.resource.query("getserialno").strip()
return f"{identity} {version} {serialno}"

def reset(self) -> None: ...

Expand All @@ -78,6 +89,8 @@ def next_error(self) -> Optional[InstrumentError]:
return parse_error(response)

def __getitem__(self, index: int) -> CorvusAxis:
if index not in type(self).AXES:
raise IndexError(index)
return CorvusAxis(self.resource, index)

def calibrate(self) -> None:
Expand Down
34 changes: 19 additions & 15 deletions tests/test_driver_itk_corvustt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def driver(resource):


def test_corvus(driver, resource):
resource.buffer = ["Corvus 1 312 1 10F"]
assert driver.identify() == "Corvus 1 312 1 10F"
assert resource.buffer == ["identify"]
resource.buffer = ["\t\x1b1.0"] # terminal buffer control characters
assert driver.initialize() is None
assert resource.buffer == ["0 mode", "version"]

resource.buffer = ["Corvus 1 312 1 10F", "1.0", "123456789"]
assert driver.identify() == "Corvus 1 312 1 10F 1.0 123456789"
assert resource.buffer == ["identify", "version", "getserialno"]

resource.buffer = []
assert driver.calibrate() is None
Expand Down Expand Up @@ -74,29 +78,29 @@ def test_corvus(driver, resource):

def test_corvus_axes(driver, resource):
resource.buffer = []
assert driver[0].calibrate() is None
assert resource.buffer == ["0 ncal"]
assert driver[1].calibrate() is None
assert resource.buffer == ["1 ncal"]

resource.buffer = []
assert driver[1].range_measure() is None
assert resource.buffer == ["1 nrm"]
assert driver[2].range_measure() is None
assert resource.buffer == ["2 nrm"]

resource.buffer = []
assert driver[2].move_absolute(2.4) is None
assert resource.buffer == ["2.400 2 nmove"]
assert driver[3].move_absolute(2.4) is None
assert resource.buffer == ["2.400 3 nmove"]

resource.buffer = []
assert driver[0].move_relative(1.2) is None
assert resource.buffer == ["1.200 0 nrmove"]
assert driver[1].move_relative(1.2) is None
assert resource.buffer == ["1.200 1 nrmove"]

resource.buffer = ["4.200"]
assert driver[1].position == 4.2
assert resource.buffer == ["1 npos"]
assert driver[2].position == 4.2
assert resource.buffer == ["2 npos"]

resource.buffer = ["3"]
assert driver[2].is_moving
assert driver[3].is_moving
assert resource.buffer == ["status"]

resource.buffer = ["2"]
assert not driver[0].is_moving
assert not driver[1].is_moving
assert resource.buffer == ["status"]