Skip to content

Commit

Permalink
Add types to tektronix drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed May 18, 2024
1 parent b6665f1 commit ae551fc
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 98 deletions.
35 changes: 24 additions & 11 deletions src/qcodes/instrument_drivers/tektronix/AWG5014.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
from collections.abc import Sequence
from io import BytesIO
from time import localtime, sleep
from typing import Any, ClassVar, Literal, NamedTuple, Optional, Union, cast
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
Literal,
NamedTuple,
Optional,
Union,
cast,
)

import numpy as np
from pyvisa.errors import VisaIOError

from qcodes import validators as vals
from qcodes.instrument import VisaInstrument
from qcodes.instrument import VisaInstrument, VisaInstrumentKWArgs

if TYPE_CHECKING:
from typing_extensions import Unpack

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -135,25 +147,26 @@ class TektronixAWG5014(VisaInstrument):
'DC_OUTPUT_LEVEL_N': 'd', # V
}

default_timeout = 180

def __init__(
self,
name: str,
address: str,
timeout: int = 180,
num_channels: int = 4,
**kwargs: Any):
self,
name: str,
address: str,
*,
num_channels: int = 4,
**kwargs: "Unpack[VisaInstrumentKWArgs]",
):
"""
Initializes the AWG5014.
Args:
name: name of the instrument
address: GPIB or ethernet address as used by VISA
timeout: visa timeout, in secs. long default (180)
to accommodate large waveforms
num_channels: number of channels on the device
**kwargs: kwargs are forwarded to base class.
"""
super().__init__(name, address, timeout=timeout, **kwargs)
super().__init__(name, address, **kwargs)

self._address = address
self.num_channels = num_channels
Expand Down
21 changes: 15 additions & 6 deletions src/qcodes/instrument_drivers/tektronix/AWG5208.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
from typing import Any
from typing import TYPE_CHECKING

from .AWG70000A import AWG70000A

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class TektronixAWG5208(AWG70000A):
"""
The QCoDeS driver for Tektronix AWG5208
"""

def __init__(self, name: str, address: str,
timeout: float = 10, **kwargs: Any) -> None:
default_timeout = 10

def __init__(
self,
name: str,
address: str,
**kwargs: "Unpack[VisaInstrumentKWArgs]",
) -> None:
"""
Args:
name: The name used internally by QCoDeS in the DataSet
address: The VISA resource name of the instrument
timeout: The VISA timeout time (in seconds).
**kwargs: kwargs are forwarded to base class.
"""

super().__init__(name, address, num_channels=8,
timeout=timeout, **kwargs)
super().__init__(name, address, num_channels=8, **kwargs)


class AWG5208(TektronixAWG5208):
Expand Down
32 changes: 24 additions & 8 deletions src/qcodes/instrument_drivers/tektronix/AWG70000A.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
from broadbean.sequence import InvalidForgedSequenceError, fs_schema

from qcodes import validators as vals
from qcodes.instrument import ChannelList, Instrument, InstrumentChannel, VisaInstrument
from qcodes.instrument import (
ChannelList,
Instrument,
InstrumentBaseKWArgs,
InstrumentChannel,
VisaInstrument,
VisaInstrumentKWArgs,
)
from qcodes.parameters import create_on_off_val_mapping

if TYPE_CHECKING:
from collections.abc import Mapping, Sequence

from typing_extensions import Unpack

log = logging.getLogger(__name__)

##################################################
Expand Down Expand Up @@ -157,16 +166,23 @@ class Tektronix70000AWGChannel(InstrumentChannel):
Class to hold a channel of the AWG.
"""

def __init__(self, parent: Instrument, name: str, channel: int) -> None:
def __init__(
self,
parent: Instrument,
name: str,
channel: int,
**kwargs: Unpack[InstrumentBaseKWArgs],
) -> None:
"""
Args:
parent: The Instrument instance to which the channel is
to be attached.
name: The name used in the DataSet
channel: The channel number, either 1 or 2.
**kwargs: Forwarded to base class.
"""

super().__init__(parent, name)
super().__init__(parent, name, **kwargs)

self.channel = channel

Expand Down Expand Up @@ -413,27 +429,27 @@ class AWG70000A(VisaInstrument):
subclasses of this general class.
"""

default_terminator = "\n"
default_timeout = 10

def __init__(
self,
name: str,
address: str,
num_channels: int,
timeout: float = 10,
**kwargs: Any,
**kwargs: Unpack[VisaInstrumentKWArgs],
) -> None:
"""
Args:
name: The name used internally by QCoDeS in the DataSet
address: The VISA resource name of the instrument
timeout: The VISA timeout time (in seconds)
num_channels: Number of channels on the AWG
**kwargs: kwargs are forwarded to base class.
"""

self.num_channels = num_channels

super().__init__(name, address, timeout=timeout, terminator='\n',
**kwargs)
super().__init__(name, address, **kwargs)

# The 'model' value begins with 'AWG'
self.model = self.IDN()['model'][3:]
Expand Down
17 changes: 13 additions & 4 deletions src/qcodes/instrument_drivers/tektronix/AWG70002A.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from typing import Any
from typing import TYPE_CHECKING

from .AWG70000A import AWG70000A

if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.instrument import VisaInstrumentKWArgs


class TektronixAWG70002A(AWG70000A):
"""
Expand All @@ -10,8 +15,13 @@ class TektronixAWG70002A(AWG70000A):
All the actual driver meat is in the superclass AWG70000A.
"""

default_timeout = 10

def __init__(
self, name: str, address: str, timeout: float = 10, **kwargs: Any
self,
name: str,
address: str,
**kwargs: "Unpack[VisaInstrumentKWArgs]",
) -> None:
"""
Args:
Expand All @@ -21,8 +31,7 @@ def __init__(
**kwargs: kwargs are forwarded to base class.
"""

super().__init__(name, address, num_channels=2,
timeout=timeout, **kwargs)
super().__init__(name, address, num_channels=2, **kwargs)


class AWG70002A(TektronixAWG70002A):
Expand Down
Loading

0 comments on commit ae551fc

Please sign in to comment.