QCoDeS / Qcodes_contrib_drivers

A collection of community-contributed QCoDeS drivers for instruments
https://qcodes.github.io/Qcodes_contrib_drivers/
MIT License
46 stars 84 forks source link

National Instruments DAQ driver does not have a setpoint #363

Open mapmen opened 1 month ago

mapmen commented 1 month ago

Hi,

I'm trying to use the NIDAQ driver provided in qcodes_contrib_drivers.drivers.NationalInstruments.DAQ with a USB-6001 NI DAQ. When I try to use the datasaver , like this:

with context_meas.run() as datasaver:
    for set_v in pwm_0:
        daq_ao_2.set('voltage_0',set_v)
        get_v = daq_ai.get('voltage')
        datasaver.add_result((daq_ao_2.voltage_0, set_v),(daq_ai.voltage,get_v))
    dataset = datasaver.dataset

I get the following error: "daq_ai_0_voltage is an <class 'qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQAnalogInputVoltages'> without setpoints. Cannot handle this."

How can I add a setpoint to the measurement?

thangleiter commented 1 week ago

You have to tell daq_ai.voltages the setpoints. Unfortunatley the driver seems a bit outdated and you cannot do this when the parameter is constructed but rather have to set it after the fact.

A MWE:

import tempfile
import nidaqmx
from qcodes_contrib_drivers.drivers.NationalInstruments import DAQ
from qcodes.dataset import initialise_or_create_database_at
from qcodes import new_experiment

daq_ai = DAQ.DAQAnalogInputs('daq_ai', 'Dev2',
                             rate=1e3, channels={'1': 1},
                             task=nidaqmx.Task(),
                             samples_to_read=10)
daq_ao_0 = DAQ.DAQAnalogOutputs('daq_ao_0', 'Dev2', channels={'0': 0})

# <--- This line is important
daq_ai.voltage.setpoints = (np.arange(1), np.arange(10))
# --->

initialise_or_create_database_at(tempfile.mktemp())
exp = new_experiment('foo', 'bar')

context_meas = Measurement()
context_meas.register_parameter(daq_ao_0.voltage_0)
context_meas.register_parameter(daq_ai.voltage, setpoints=(daq_ao_0.voltage_0,))

pwm_0 = 0.1 * np.random.randn(10)
# OP's code
with context_meas.run() as datasaver:
    for set_v in pwm_0:
        daq_ao_0.set('voltage_0', set_v)
        get_v = daq_ai.get('voltage')
        datasaver.add_result((daq_ao_0.voltage_0, set_v), (daq_ai.voltage, get_v))
    dataset = datasaver.dataset