Skip to content

Commit

Permalink
Abstract Instrument PowerSupply: Move Channel inside class, add to doc
Browse files Browse the repository at this point in the history
  • Loading branch information
trappitsch committed Jan 24, 2022
1 parent d6553c1 commit 234e49f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 91 deletions.
7 changes: 7 additions & 0 deletions doc/source/apiref/instrument.rst
Expand Up @@ -28,6 +28,13 @@ Instrument Base Classes
:members:
:undoc-members:

:class:`PowerSupply` - Abstract class for power supply instruments
==================================================================

.. autoclass:: instruments.abstract_instruments.PowerSupply
:members:
:undoc-members:

:class:`Oscilloscope` - Abstract class for oscilloscope instruments
===================================================================

Expand Down
5 changes: 1 addition & 4 deletions instruments/abstract_instruments/__init__.py
Expand Up @@ -9,10 +9,7 @@
from .electrometer import Electrometer
from .function_generator import FunctionGenerator
from .oscilloscope import Oscilloscope
from .power_supply import (
PowerSupplyChannel,
PowerSupply,
)
from .power_supply import PowerSupply

from .optical_spectrum_analyzer import (
OSAChannel,
Expand Down
137 changes: 67 additions & 70 deletions instruments/abstract_instruments/power_supply.py
Expand Up @@ -12,79 +12,76 @@
# CLASSES #####################################################################


class PowerSupplyChannel(metaclass=abc.ABCMeta):

"""
Abstract base class for power supply output channels.
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""

# PROPERTIES #

@property
@abc.abstractmethod
def mode(self):
"""
Gets/sets the output mode for the power supply channel. This is an
abstract method.
:type: `~enum.Enum`
"""

@mode.setter
@abc.abstractmethod
def mode(self, newval):
pass

@property
@abc.abstractmethod
def voltage(self):
"""
Gets/sets the output voltage for the power supply channel. This is an
abstract method.
:type: `~pint.Quantity`
"""

@voltage.setter
@abc.abstractmethod
def voltage(self, newval):
pass

@property
@abc.abstractmethod
def current(self):
"""
Gets/sets the output current for the power supply channel. This is an
abstract method.
:type: `~pint.Quantity`
"""

@current.setter
@abc.abstractmethod
def current(self, newval):
pass

@property
@abc.abstractmethod
def output(self):
class PowerSupply(Instrument, metaclass=abc.ABCMeta):
class Channel(metaclass=abc.ABCMeta):
"""
Gets/sets the output status for the power supply channel. This is an
abstract method.
Abstract base class for power supply output channels.
:type: `bool`
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""

@output.setter
@abc.abstractmethod
def output(self, newval):
pass


class PowerSupply(Instrument, metaclass=abc.ABCMeta):
# PROPERTIES #

@property
@abc.abstractmethod
def mode(self):
"""
Gets/sets the output mode for the power supply channel. This is an
abstract method.
:type: `~enum.Enum`
"""

@mode.setter
@abc.abstractmethod
def mode(self, newval):
pass

@property
@abc.abstractmethod
def voltage(self):
"""
Gets/sets the output voltage for the power supply channel. This is an
abstract method.
:type: `~pint.Quantity`
"""

@voltage.setter
@abc.abstractmethod
def voltage(self, newval):
pass

@property
@abc.abstractmethod
def current(self):
"""
Gets/sets the output current for the power supply channel. This is an
abstract method.
:type: `~pint.Quantity`
"""

@current.setter
@abc.abstractmethod
def current(self, newval):
pass

@property
@abc.abstractmethod
def output(self):
"""
Gets/sets the output status for the power supply channel. This is an
abstract method.
:type: `bool`
"""

@output.setter
@abc.abstractmethod
def output(self, newval):
pass

"""
Abstract base class for power supply instruments.
Expand All @@ -104,7 +101,7 @@ def channel(self):
This is an abstract method.
:rtype: `PowerSupplyChannel`
:rtype: `PowerSupply.Channel`
"""
raise NotImplementedError

Expand Down
6 changes: 3 additions & 3 deletions instruments/glassman/glassmanfr.py
Expand Up @@ -34,20 +34,20 @@
from struct import unpack
from enum import Enum

from instruments.abstract_instruments import PowerSupply, PowerSupplyChannel
from instruments.abstract_instruments import PowerSupply
from instruments.units import ureg as u
from instruments.util_fns import assume_units

# CLASSES #####################################################################


class GlassmanFR(PowerSupply, PowerSupplyChannel):
class GlassmanFR(PowerSupply, PowerSupply.Channel):

"""
The GlassmanFR is a single output power supply.
Because it is a single channel output, this object inherits from both
PowerSupply and PowerSupplyChannel.
PowerSupply and PowerSupply.Channel.
This class should work for any of the Glassman FR Series power supplies
and is also likely to work for the EJ, ET, EY and FJ Series which seem
Expand Down
4 changes: 2 additions & 2 deletions instruments/hp/hp6624a.py
Expand Up @@ -7,7 +7,7 @@

from enum import Enum

from instruments.abstract_instruments import PowerSupply, PowerSupplyChannel
from instruments.abstract_instruments import PowerSupply
from instruments.units import ureg as u
from instruments.util_fns import ProxyList, unitful_property, bool_property

Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(self, filelike):

# INNER CLASSES #

class Channel(PowerSupplyChannel):
class Channel(PowerSupply.Channel):
"""
Class representing a power output channel on the HP6624a.
Expand Down
6 changes: 3 additions & 3 deletions instruments/hp/hp6652a.py
Expand Up @@ -10,20 +10,20 @@

from instruments.units import ureg as u

from instruments.abstract_instruments import PowerSupply, PowerSupplyChannel
from instruments.abstract_instruments import PowerSupply
from instruments.util_fns import unitful_property, bool_property


# CLASSES #####################################################################


class HP6652a(PowerSupply, PowerSupplyChannel):
class HP6652a(PowerSupply, PowerSupply.Channel):

"""
The HP6652a is a single output power supply.
Because it is a single channel output, this object inherits from both
PowerSupply and PowerSupplyChannel.
PowerSupply and PowerSupply.Channel.
According to the manual, this class MIGHT be usable for any HP power supply
with a model number HP66XYA, where X is in {4,5,7,8,9} and Y is a digit(?).
Expand Down
4 changes: 2 additions & 2 deletions instruments/hp/hpe3631a.py
Expand Up @@ -36,7 +36,7 @@

from instruments.units import ureg as u

from instruments.abstract_instruments import PowerSupply, PowerSupplyChannel
from instruments.abstract_instruments import PowerSupply
from instruments.generic_scpi import SCPIInstrument
from instruments.util_fns import (
int_property,
Expand All @@ -50,7 +50,7 @@
# CLASSES #####################################################################


class HPe3631a(PowerSupply, PowerSupplyChannel, SCPIInstrument):
class HPe3631a(PowerSupply, PowerSupply.Channel, SCPIInstrument):

"""
The HPe3631a is a three channels voltage/current supply.
Expand Down
2 changes: 1 addition & 1 deletion instruments/tests/test_abstract_inst/test_power_supply.py
Expand Up @@ -26,7 +26,7 @@ def ps(monkeypatch):
@pytest.fixture
def ps_ch(monkeypatch):
"""Patch and return Power Supply Channel class for access."""
inst = ik.abstract_instruments.PowerSupplyChannel
inst = ik.abstract_instruments.PowerSupply.Channel
monkeypatch.setattr(inst, "__abstractmethods__", set())
return inst

Expand Down
9 changes: 3 additions & 6 deletions instruments/yokogawa/yokogawa7651.py
Expand Up @@ -10,10 +10,7 @@

from instruments.units import ureg as u

from instruments.abstract_instruments import (
PowerSupply,
PowerSupplyChannel,
)
from instruments.abstract_instruments import PowerSupply
from instruments.abstract_instruments import Instrument
from instruments.util_fns import assume_units, ProxyList

Expand All @@ -35,12 +32,12 @@ class Yokogawa7651(PowerSupply, Instrument):

# INNER CLASSES #

class Channel(PowerSupplyChannel):
class Channel(PowerSupply.Channel):

"""
Class representing the only channel on the Yokogawa 7651.
This class inherits from `PowerSupplyChannel`.
This class inherits from `PowerSupply.Channel`.
.. warning:: This class should NOT be manually created by the user. It
is designed to be initialized by the `Yokogawa7651` class.
Expand Down

0 comments on commit 234e49f

Please sign in to comment.