Skip to content

Commit

Permalink
Correct the rest (types)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSasser committed Mar 19, 2021
1 parent 08ffea7 commit 14d57f7
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 143 deletions.
8 changes: 4 additions & 4 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ds2000's documentation!
=======================

The `RIGOL DS2000(A)` Series is a fairly cheap, sub $600, entry-level
The ``RIGOL DS2000(A)`` Series is a fairly cheap, sub $600, entry-level
oscilloscope family with many bells and whistles. This Python package uses
the `LXI` capabilities of the scope to make it remote controllable from
within Python without ever needing to touch any `SCPI` command. You will be able
to use any function of your oscilloscope with a python interface. It wraps
the ``LXI`` capabilities of the scope to make it remote controllable from
within Python without ever needing to touch any ``SCPI`` command. You will be
able to use any function of your oscilloscope with a python interface. It wraps
every command and puts it in a logical high-level interface for you.

.. toctree::
Expand Down
7 changes: 4 additions & 3 deletions ds2000/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
except (ImportError, NotImplementedError):
debug("Driver: VXI11 is not installed.")

# TODO:
try:
from .visa.pyvisa import PYVISA

Expand Down Expand Up @@ -111,9 +112,9 @@ def __enter__(self) -> DS2000:

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
_: Optional[Type[BaseException]], # exc_type
__: Optional[BaseException], # exc_val
___: Optional[TracebackType], # exc_tb
) -> None:
self.instrument.disconnect()

Expand Down
4 changes: 4 additions & 0 deletions ds2000/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def check_level(level: float, scale: float, offset: float):
)


# TODO: Simplify
def get_examples(doc: Optional[str]) -> Optional[Tuple[Example, ...]]:
"""Extract the examples of a docstring."""
# If ther is no "doc", return an empty list
Expand Down Expand Up @@ -179,7 +180,10 @@ def get_examples(doc: Optional[str]) -> Optional[Tuple[Example, ...]]:
"detected"
)
return None
return __create_example(lines)


def __create_example(lines: List[str]) -> Optional[Tuple[Example, ...]]:
examples: List[Example] = []
question: Optional[str] = None
answer: Optional[str] = None
Expand Down
4 changes: 2 additions & 2 deletions ds2000/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ def set_menu_display_time(self, time: int = -1) -> None:
elif time in Display.MENU_DISPLAY_TIME:
self.instrument.say(f":DISPlay:GRADing:TIME {time}")

def data(self) -> bytearray: # Screenshot bitmap raw data stream
"""Read the bitmap data stream of the image currently displayed.
def data(self) -> bytearray: # noqa: C901
r"""Read the bitmap data stream of the image currently displayed.
**Rigol Programming Guide**
Expand Down
6 changes: 4 additions & 2 deletions ds2000/func/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from logging import debug

from ds2000.math.format import get_prefix
from ds2000.waveform import Preamble


try:
Expand Down Expand Up @@ -44,7 +46,7 @@ def simple_plot(inst, title: str = "", recorded: bool = False) -> None:
waveform on the screen. None
"""
# TODO: Add offset
p = inst.waveform.preamble()
p: Preamble = inst.waveform.preamble()
t_scale = inst.timebase.get_scale()
c_scale = inst.channel1.get_scale()
inst.waveform.channel(1) # TODO: Check for active channels; make argument.
Expand All @@ -56,7 +58,7 @@ def simple_plot(inst, title: str = "", recorded: bool = False) -> None:

# Get data for x-/y-Axis
df = (
(inst.waveform.data(recorded) - p.y_ref - p.get_y_origin)
(inst.waveform.data(recorded) - p.y_ref - p.y_origin)
* p.y_inc
* 10.0 ** (-get_prefix(c_scale).divisor)
) # y
Expand Down
10 changes: 5 additions & 5 deletions ds2000/ieee.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __init__(self, dev):
super(IEEE, self).__init__(dev)

def idn(self) -> str:
"""Get the ID chars of the device_address as Instrument Tuple.
r"""Get the ID chars of the device_address as Instrument Tuple.
**Rigol Programming Guide**
**Syntax**
\\*IDN?
*IDN?
**Description**
Expand All @@ -53,20 +53,20 @@ def idn(self) -> str:
**Example**
\\*IDN?
*IDN?
The query returns RIGOL TECHNOLOGIES,DS2202,DS2xxx,00.00.01. Instrument
"""
return self.instrument.ask("*IDN?")

def rst(self):
"""Restore the instrument to the default values.
r"""Restore the instrument to the default values.
**Rigol Programming Guide**
**Syntax**
\\*RST
*RST
**Description**
Expand Down
1 change: 1 addition & 0 deletions ds2000/math/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


class Prefixed(NamedTuple):

"""Get value, prefix, divisor and a preformatted string of a value."""

value: float
Expand Down
2 changes: 1 addition & 1 deletion ds2000/trigger/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def set_usb(self) -> None:
"""
self.instrument.say(":TRIGger:MODE USB")

def status(self) -> TriggerModeEnum:
def status(self) -> TriggerModeEnum: # noqa: C901
"""Query the current trigger type.
**Rigol Programming Guide**
Expand Down
2 changes: 1 addition & 1 deletion ds2000/trigger/nth_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def set_negative(self) -> None:
:TRIGger:NEDGe:SLOPe NEGative
The query returns NEG.
"""
self.instrument.say(f":TRIGger:NEDGe:SLOPe NEGative")
self.instrument.say(":TRIGger:NEDGe:SLOPe NEGative")

def status(self) -> SlopeEnum:
"""Query the current edge type of Nth edge trigger.
Expand Down
2 changes: 0 additions & 2 deletions ds2000/trigger/pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from ds2000.common import check_level
from ds2000.enums import ChannelEnum
from ds2000.enums import TriggerPulseWhenEnum

# ToDo: Shorter function names!!!
from ds2000.errors import DS2000StateError


Expand Down
4 changes: 2 additions & 2 deletions ds2000/trigger/runt.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def set_channel_1(self) -> None:
:TRIGger:RUNT:SOURce CHANnel2
The query returns CHAN2.
"""
self.instrument.say(f":TRIGger:RUNT:SOURce CHANnel1")
self.instrument.say(":TRIGger:RUNT:SOURce CHANnel1")

def set_channel_2(self) -> None:
"""Select the trigger source of runt trigger.
Expand Down Expand Up @@ -97,7 +97,7 @@ def set_channel_2(self) -> None:
:TRIGger:RUNT:SOURce CHANnel2
The query returns CHAN2.
"""
self.instrument.say(f":TRIGger:RUNT:SOURce CHANnel2")
self.instrument.say(":TRIGger:RUNT:SOURce CHANnel2")

def status(self) -> ChannelEnum:
"""Query the current trigger source of runt trigger.
Expand Down
2 changes: 0 additions & 2 deletions ds2000/trigger/slope.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from ds2000.common import channel_as_enum
from ds2000.common import check_input
from ds2000.common import check_level

# ToDo: shorter method names.
from ds2000.enums import ChannelEnum
from ds2000.enums import SlopeEnum
from ds2000.enums import TriggerSlopeWhenEnum
Expand Down
2 changes: 0 additions & 2 deletions ds2000/visa/debug_driver/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from __future__ import annotations

from logging import debug
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union
Expand Down
8 changes: 4 additions & 4 deletions ds2000/visa/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def write(self, msg: str) -> None:
pass

@abstractmethod
def read_raw(self):
def read_raw(self) -> Optional[bytes]:
"""Read binary data from the instrument."""
pass

Expand All @@ -96,9 +96,9 @@ def __enter__(self) -> VISABase:

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
_: Optional[Type[BaseException]], # exc_type
__: Optional[BaseException], # exc_val
___: Optional[TracebackType], # exc_tb
) -> None:
"""Connect to the Instrument with the `with` statement."""
self.disconnect()
Expand Down
100 changes: 54 additions & 46 deletions ds2000/visa/pyvisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,67 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations

# from logging import debug
# from logging import error
from typing import Optional

# import pyvisa
# from .driver import InstrumentInfo
from .driver import VISABase


# import vxi11


__author__: str = "Michael Sasser"
__email__: str = "[email protected]"

raise NotImplementedError()


class PYVISA(VISABase):
pass


# def connect(self):
# """Connect to the instrument."""
# self.__instrument = vxi11.Instrument(self.address)
# self.info = InstrumentInfo(*self.ask("*IDN?").split(","))
#
# def disconnect(self):
# """Disconnect from the instrument."""
# self.__instrument.close()
#
# def ask(self, msg: str) -> str:
# """Write and read afterwards from a instrument."""
# answer: Optional[str] = None
# try:
# answer = self.__instrument.ask(msg)
# except vxi11.vxi11.Vxi11Exception as e:
# # TODO: Raise before first release.
# error(f"Error while asking: {e}")
# finally:
# debug(f'Asked: "{msg}", Answered: "{answer}"')
# return answer
#
# def write(self, msg: str) -> None:
# """Write to the instrument but don't wait for a response."""
# try: # Probably just for development
# self.__instrument.write(msg)
# except vxi11.vxi11.Vxi11Exception as e:
# # TODO: Raise before first release.
# error(f"Error while writing: {e}")
# finally:
# debug(f'Written: "{msg}"')
#
# def read_raw(self) -> bytes:
# """Read binary data from the instrument."""
# msg: Optional[bytes] = None
# try:
# msg = self.__instrument.read_raw()
# except vxi11.vxi11.Vxi11Exception as e:
# # TODO: Raise before first release.
# error(f"Error while writing: {e}")
# return msg
def connect(self) -> None:
"""Connect to the instrument."""
pass
# self.__instrument = vxi11.Instrument(self.address)
# self.info = InstrumentInfo(*self.ask("*IDN?").split(","))

def disconnect(self) -> None:
"""Disconnect from the instrument."""
pass
# self.__instrument.close()

def communicate(self, msg: str) -> Optional[str]:
"""Write and read afterwards from a instrument."""
pass
# answer: Optional[str] = None
# try:
# answer = self.__instrument.ask(msg)
# except vxi11.vxi11.Vxi11Exception as e:
# # TODO: Raise before first release.
# error(f"Error while asking: {e}")
# finally:
# debug(f'Asked: "{msg}", Answered: "{answer}"')
# return answer

def write(self, msg: str) -> None:
"""Write to the instrument but don't wait for a response."""
pass
# try: # Probably just for development
# self.__instrument.write(msg)
# except vxi11.vxi11.Vxi11Exception as e:
# # TODO: Raise before first release.
# error(f"Error while writing: {e}")
# finally:
# debug(f'Written: "{msg}"')

def read_raw(self) -> Optional[bytes]:
"""Read binary data from the instrument."""
pass
# msg: Optional[bytes] = None
# try:
# msg = self.__instrument.read_raw()
# except vxi11.vxi11.Vxi11Exception as e:
# # TODO: Raise before first release.
# error(f"Error while writing: {e}")
# return msg


# vim: set ft=python :
Loading

0 comments on commit 14d57f7

Please sign in to comment.