Convention for adding parameters to instrument driver + intellisense problems #6353
-
Hello, I noticed that in the Creating Drivers page, the VisaInstrument example with the Weinschel8320 binds the attenuation parameter to the instrument using the self.add_parameter method and assigns the output to an identically named attribute. However, in the source code for the driver here, I see that the parameter is instantiated with the Parameter class directly and then assigned to self.attenuation. When I tried using the self.add_parameter approach, I noticed that the driver breaks, which seems to be because self.add_parameter returns NoneType as per its definition in the InstrumentBase class. I switched to the second approach, directly instantiating with the Parameter class and everything seems fine. As I understand, the purpose of assigning the parameter to an attribute is to allow intellisense to recognize the instrument parameters, but, in both approaches, my intellisense isn't recognizing any of the parameters of my instrument. What is the recommended approach for binding instrument parameters, and are there any fixes to the intellisense problem? For reference, I've attached the current implementation of my instrument driver below. Thanks import qcodes.validators as vals
import logging
from time import sleep
from typing import Any, Optional
from functools import partial
from qcodes.instrument import InstrumentChannel, VisaInstrument
from qcodes.parameters import ( Parameter )
from qcodes.validators import Ints, Numbers
log = logging.getLogger(__name__)
class BarreraDCDAC5764Channel(InstrumentChannel):
"""
Class to hold one of the 8 DC DAC Channels
"""
def __init__(self, parent: "BarreraDCDAC5764", name: str, channel: str) -> None:
"""
Args:
parent: The YokogawaGS820 instance to which the channel is
to be attached.
name: The 'colloquial' name of the channel
channel: The name used by the Yokogawa, i.e. either
'channel1' or 'channel2'
"""
valid_chnls = [f"channel{i}" for i in range(1, 9)]
if channel not in valid_chnls:
raise ValueError(f'{channel} not in channel1, ..., channel8')
super().__init__(parent, name)
self.channel = channel
self._extra_visa_timeout = 5000
self.voltage = Parameter(
name="voltage",
unit="V",
label="Voltage",
get_parser=float,
get_cmd=partial(self._get_set_voltage),
set_cmd=partial(self._get_set_voltage),
vals=Numbers(-10, 10),
instrument=self
)
"Voltage level parameter"
self.offset = Parameter(
name = "offset",
label="Offset",
get_cmd=None,
set_cmd=f"{self.channel}:OFFSET {{}}",
# signed 8 bit integer
vals=Ints(-128, 127),
instrument=self
)
"Offset level settable parameter"
self.step = Parameter(
name="step",
label="Step",
get_cmd=None,
set_cmd=f"{self.channel}:STEP {{}}",
# signed 6 bit integer
vals=Ints(-32, 31),
instrument=self
)
"Step size settable parameter"
def _get_set_voltage(self, voltage: Optional[float] = None) -> Optional[float]:
"""
Get or set the voltage level.
Args:
voltage: If missing, we assume that we are getting the
current level. Else we are setting it
"""
if voltage is not None:
self.write(f'{self.channel}:VOLTAGE {voltage}')
else:
return self.ask(f'{self.channel}:VOLTAGE?')
self.add_parameter
class BarreraDCDAC5764(VisaInstrument):
"""
QCoDeS driver for custom made DC-DAC AD55706 DC generator
Args:
name: What this instrument is called locally.
address: The GPIB or USB address of this instrument
kwargs: kwargs to be passed to VisaInstrument class
terminator: read terminator for reads/writes to the instrument.
"""
def __init__(self, name: str, address: str, terminator: str = "\n", **kwargs: Any
) -> None:
super().__init__(name, address, terminator=terminator, **kwargs)
self.channels: list[BarreraDCDAC5764Channel] = []
for ch in range(1, 9):
ch_name = f"channel{ch}"
channel = BarreraDCDAC5764Channel(self, ch_name, ch_name)
self.add_submodule(ch_name, channel)
self.channels.append(channel)
# Required as Arduino takes around 2 seconds to setup serial
sleep(3)
self.connect_message()
def reset(self) -> None:
"""
Reset DAC to 0V on each channel, and sets offsets/steps to 0
"""
self.write("*RST")
for channel_num in range(8):
inst_chnl = self.channels[channel_num]
inst_chnl.offset(0)
inst_chnl.step(0)
log.debug("Reset Instrument. Re-querying settings...")
self.snapshot(update=True) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Which version of qcodes are you using. The return from add_parameter was added in 0.46.0 |
Beta Was this translation helpful? Give feedback.
Which version of qcodes are you using. The return from add_parameter was added in 0.46.0