Skip to content
Merged
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
25 changes: 17 additions & 8 deletions src/qcodes/instrument_drivers/Keysight/KtMAwg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from typing_extensions import Unpack


class KeysightM9336AAWGChannel(InstrumentChannel):
_ch_type = bytes | ctypes.Array[ctypes.c_char]


class KeysightM9336AAWGChannel(InstrumentChannel["KeysightM9336A"]):
"""
Represent the three channels of the Keysight KTM Awg driver.
The channels can be independently controlled and programmed with
Expand Down Expand Up @@ -135,6 +138,12 @@ def __init__(
)
"""Parameter digital_gain"""

@property
def root_instrument(self) -> "KeysightM9336A":
root_instrument = super().root_instrument
assert isinstance(root_instrument, KeysightM9336A)
return root_instrument

def load_waveform(self, filename: str) -> None:
path = ctypes.create_string_buffer(filename.encode("ascii"))
self._awg_handle = ctypes.c_int32(-1)
Expand Down Expand Up @@ -341,7 +350,7 @@ def get_errors(self) -> dict[int, str]:
return error_dict

# Generic functions for reading/writing different attributes
def _get_vi_string(self, attr: int, ch: bytes = b"") -> str:
def _get_vi_string(self, attr: int, ch: _ch_type = b"") -> str:
s = ctypes.create_string_buffer(self._default_buf_size)
status = self._dll.KtMAwg_GetAttributeViString(
self._session, ch, attr, self._default_buf_size, s
Expand All @@ -350,7 +359,7 @@ def _get_vi_string(self, attr: int, ch: bytes = b"") -> str:
raise ValueError(f"Driver error: {status}")
return s.value.decode("utf-8")

def _get_vi_bool(self, attr: int, ch: bytes = b"") -> bool:
def _get_vi_bool(self, attr: int, ch: _ch_type = b"") -> bool:
s = ctypes.c_uint16(0)
status = self._dll.KtMAwg_GetAttributeViBoolean(
self._session, ch, attr, ctypes.byref(s)
Expand All @@ -359,13 +368,13 @@ def _get_vi_bool(self, attr: int, ch: bytes = b"") -> bool:
raise ValueError(f"Driver error: {status}")
return bool(s)

def _set_vi_bool(self, attr: int, value: bool, ch: bytes = b"") -> None:
def _set_vi_bool(self, attr: int, value: bool, ch: _ch_type = b"") -> None:
v = ctypes.c_uint16(1) if value else ctypes.c_uint16(0)
status = self._dll.KtMAwg_SetAttributeViBoolean(self._session, ch, attr, v)
if status:
raise ValueError(f"Driver error: {status}")

def _get_vi_real64(self, attr: int, ch: bytes = b"") -> float:
def _get_vi_real64(self, attr: int, ch: _ch_type = b"") -> float:
s = ctypes.c_double(0)
status = self._dll.KtMAwg_GetAttributeViReal64(
self._session, ch, attr, ctypes.byref(s)
Expand All @@ -375,19 +384,19 @@ def _get_vi_real64(self, attr: int, ch: bytes = b"") -> float:
raise ValueError(f"Driver error: {status}")
return float(s.value)

def _set_vi_real64(self, attr: int, value: float, ch: bytes = b"") -> None:
def _set_vi_real64(self, attr: int, value: float, ch: _ch_type = b"") -> None:
v = ctypes.c_double(value)
status = self._dll.KtMAwg_SetAttributeViReal64(self._session, ch, attr, v)
if status:
raise ValueError(f"Driver error: {status}")

def _set_vi_int(self, attr: int, value: int, ch: bytes = b"") -> None:
def _set_vi_int(self, attr: int, value: int, ch: _ch_type = b"") -> None:
v = ctypes.c_int32(value)
status = self._dll.KtMAwg_SetAttributeViInt32(self._session, ch, attr, v)
if status:
raise ValueError(f"Driver error: {status}")

def _get_vi_int(self, attr: int, ch: bytes = b"") -> int:
def _get_vi_int(self, attr: int, ch: _ch_type = b"") -> int:
v = ctypes.c_int32(0)
status = self._dll.KtMAwg_GetAttributeViInt32(
self._session, ch, attr, ctypes.byref(v)
Expand Down
10 changes: 6 additions & 4 deletions src/qcodes/instrument_drivers/Lakeshore/lakeshore_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qcodes.instrument.channel import ChannelTuple


class LakeshoreBaseOutput(InstrumentChannel):
class LakeshoreBaseOutput(InstrumentChannel["LakeshoreBase"]):
MODES: ClassVar[dict[str, int]] = {}
RANGES: ClassVar[dict[str, int]] = {}

Expand Down Expand Up @@ -475,9 +475,11 @@ def wait_until_set_point_reached(
)

active_channel_id = self.input_channel()
active_channel_name_on_instrument = self.root_instrument.input_channel_parameter_values_to_channel_name_on_instrument[
active_channel_id
]
active_channel_name_on_instrument = (
self.parent.input_channel_parameter_values_to_channel_name_on_instrument[
active_channel_id
]
)
active_channel = getattr(
self.root_instrument, active_channel_name_on_instrument
)
Expand Down
11 changes: 7 additions & 4 deletions src/qcodes/instrument_drivers/Minicircuits/Base_SPDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import re
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Generic, TypeVar

from qcodes.instrument import (
ChannelList,
Expand All @@ -19,11 +19,13 @@

log = logging.getLogger(__name__)

_TINSTR = TypeVar("_TINSTR", bound="MiniCircuitsSPDTBase")

class MiniCircuitsSPDTSwitchChannelBase(InstrumentChannel):

class MiniCircuitsSPDTSwitchChannelBase(InstrumentChannel[_TINSTR], Generic[_TINSTR]):
def __init__(
self,
parent: Instrument,
parent: _TINSTR,
name: str,
channel_letter: str,
**kwargs: Unpack[InstrumentBaseKWArgs],
Expand Down Expand Up @@ -89,7 +91,8 @@ def add_channels(self) -> None:
channel = self.CHANNEL_CLASS(self, f"channel_{c}", c)
channels.append(channel)
self.add_submodule(c, channel)
self.add_submodule("channels", channels.to_channel_tuple())
self.channels = self.add_submodule("channels", channels.to_channel_tuple())
"""Channel list containing all channels of the switch"""

def all(self, switch_to: int) -> None:
for c in self.channels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from qcodes.parameters import Parameter


class MiniCircuitsRCSP4TChannel(InstrumentChannel):
class MiniCircuitsRCSP4TChannel(InstrumentChannel["MiniCircuitsRCSP4T"]):
def __init__(
self,
parent: IPInstrument,
parent: "MiniCircuitsRCSP4T",
name: str,
channel_letter: str,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
"""Parameter switch"""

def _set_switch(self, switch: int) -> None:
if len(self._parent.channels) > 1:
if len(self.parent.channels) > 1:
current_switchstate = int(self.ask("SWPORT?"))
mask = 0xF << (4 * (1 - self.channel_number))
current_switchstate = current_switchstate & mask
Expand Down Expand Up @@ -111,7 +111,8 @@ def __init__(
channel = MiniCircuitsRCSP4TChannel(self, f"channel_{c}", c)
channels.append(channel)
self.add_submodule(f"channel_{c}", channel)
self.add_submodule("channels", channels.to_channel_tuple())
self.channels = self.add_submodule("channels", channels.to_channel_tuple())
"""ChannelTuple of channels"""

self.connect_message()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
)


class MiniCircuitsUsbSPDTSwitchChannel(MiniCircuitsSPDTSwitchChannelBase):
class MiniCircuitsUsbSPDTSwitchChannel(
MiniCircuitsSPDTSwitchChannelBase["MiniCircuitsUsbSPDT"]
):
def _set_switch(self, switch: int) -> None:
self._parent.switch.Set_Switch(self.channel_letter, switch - 1)
self.parent.switch.Set_Switch(self.channel_letter, switch - 1)

def _get_switch(self) -> int:
status = self._parent.switch.GetSwitchesStatus(self._parent.address)[1]
status = self.parent.switch.GetSwitchesStatus(self._parent.address)[1]
return int(f"{status:04b}"[-1 - self.channel_number]) + 1


Expand Down
9 changes: 6 additions & 3 deletions src/qcodes/instrument_drivers/stahl/stahl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def inner(*args: Any) -> Any:
return inner


class StahlChannel(InstrumentChannel):
class StahlChannel(InstrumentChannel["Stahl"]):
acknowledge_reply = chr(6)

def __init__(
self,
parent: VisaInstrument,
parent: "Stahl",
name: str,
channel_number: int,
**kwargs: "Unpack[InstrumentBaseKWArgs]",
Expand Down Expand Up @@ -215,7 +215,10 @@ def __init__(
self.add_submodule(name, channel)
channels.append(channel)

self.add_submodule("channel", channels)
self.channels: ChannelList[StahlChannel] = self.add_submodule(
"channel", channels
)
"""ChannelList of channels"""

self.temperature: Parameter = self.add_parameter(
"temperature",
Expand Down
Loading