photons.equipment.nidaq module

DAQ from National Instruments.

class photons.equipment.nidaq.Timing(**kwargs)[source]

Bases: object

Do not instantiate this class directly. Use NIDAQ.timing().

add_to(task)[source]

Add the timing configuration to a task.

Parameters:

task (Task) – The task to add the timing configuration to.

Return type:

None

property rate: float

Returns the sample rate (in Hz).

property sample_mode: AcquisitionType

Returns the sample mode.

property samples_per_channel: int

Returns the number of samples per channel to acquire or generate.

class photons.equipment.nidaq.Trigger(**kwargs)[source]

Bases: object

Do not instantiate this class directly. Use NIDAQ.trigger().

add_to(task)[source]

Add this trigger to a task.

Parameters:

task (Task) – The task to add the trigger event to.

Return type:

None

class photons.equipment.nidaq.NIDAQ(record, **kwargs)[source]

Bases: BaseEquipment

DAQ from National Instruments.

Parameters:
  • record (EquipmentRecord) – The equipment record.

  • **kwargs – Keyword arguments. Can be specified as attributes of an XML element in a configuration file (with the tag of the element equal to the alias of record).

connection: ConnectionNIDAQ
counts_changed: SignalInstance
WAIT_INFINITELY = -1.0
analog_in(channel, *, config='DIFF', duration=None, maximum=10, minimum=-10, nsamples=1, timeout=10, timing=None, trigger=None, wait=True)[source]

Read the voltage(s) of the analog-input channel(s).

Parameters:
  • channel (int | str) – The analog-input channel number(s), e.g., channel=0, channel=’0:7’.

  • config (int | str) – Specifies the input terminal configuration for the channel, see TerminalConfiguration.

  • duration (float) – The number of seconds to read voltages for. If specified then this value is used instead of nsamples.

  • maximum (float) – The maximum voltage that is expected to be measured.

  • minimum (float) – The minimum voltage that is expected to be measured.

  • nsamples (int) – The number of samples per channel to read. If a duration is also specified then that value is used instead of nsamples.

  • timeout (float) – The maximum number of seconds to wait for the task to finish. Set to -1 to wait forever.

  • timing (Timing) – The timing settings to use. See timing().

  • trigger (Trigger) – The trigger settings to use. See trigger().

  • wait (bool) – Whether to wait for the task to finish. If enabled then also closes the task when it is finished.

Return type:

tuple[ndarray | Task, float]

Returns:

If wait is True then the voltage(s) of the requested analog-input channel(s) and the time interval between samples (i.e., dt) are returned. Otherwise, the analog-input task, which has not been started yet and the time interval between samples are returned. Not starting the task allows one to register a callback before starting the task.

Examples

Read the value of a single analog-input channel

>>> daq.analog_in(0)
(array([-0.48746041]), 0.001)
>>> daq.analog_in(6, nsamples=5)
(array([-0.44944232, -0.45040888, -0.45137544, -0.45556387, -0.45298637]), 0.001)

Read the values of multiple analog-input channels

>>> daq.analog_in('0:3', nsamples=4)
(array([[ 0.03512726,  0.03770475,  0.03867132,  0.03512726],
       [-0.1675285 ,  0.17527869, -0.17171693,  0.17237901],
       [ 0.08248878,  0.12243999,  0.00741916,  0.07991128],
       [ 0.08861033,  0.09859814,  0.05832474,  0.06831254]]), 0.001)
analog_out(channel, voltage, *, auto_start=True, timeout=10, timing=None, trigger=None, wait=True)[source]

Write the voltage(s) to the analog-output channel(s).

Parameters:
  • channel (int | str) – The analog-output channel number(s), e.g., channel=0, channel=’0:1’.

  • voltage (float | list[float] | list[list[float]] | ndarray) – The voltage(s) to output.

  • auto_start (bool) – Whether to automatically start the task.

  • timeout (float) – The maximum number of seconds to wait for the task to finish. Set to -1 to wait forever.

  • timing (Timing) – The timing settings to use. See timing().

  • trigger (Trigger) – The trigger settings to use. See trigger().

  • wait (bool) – Whether to wait for the task to finish. If enabled then also closes the task when it is finished.

Return type:

Task

Returns:

The analog-output task.

Examples

Write to a single analog-output channel

>>> daq.analog_out(0, 1.123)

Write to multiple analog-output channels

>>> daq.analog_out('0:1', [0.2, -1.2])
>>> daq.analog_out('0:1', [[0.2, 0.1, 0.], [-0.1, 0., 0.1]])
analog_out_read(channel, **kwargs)[source]

Read the output voltage(s) from the analog-output channel(s).

Parameters:
  • channel (int | str) – The analog-output channel number(s), e.g., channel=0, channel=’0:1’.

  • **kwargs – All keyword arguments are passed to analog_in().

Return type:

tuple[ndarray | Task, float]

Returns:

If wait is True then the voltage(s) of the requested analog-output channel(s) and the time interval between samples (i.e., dt) are returned. Otherwise, the analog-output task, which has not been started yet and the time interval between samples are returned. Not starting the task allows one to register a callback before starting the task.

Examples

Read a single value from an analog-output channel

>>> daq.analog_out_read(0)
(array([-1.09800537]), 0.001)

Read multiple values from multiple analog-output channels

>>> daq.analog_out_read('0:1', nsamples=4)
(array([[-1.09832756, -1.09736099, -1.09800537, -1.09736099],
       [ 0.21168585,  0.21233022,  0.21200803,  0.21168585]]), 0.001)
close_all_tasks()[source]

Close all tasks.

Return type:

None

count_edges(pfi, duration, *, nsamples=1, rising=True)[source]

Count the number of edges per second.

Parameters:
  • pfi (int) – The PFI terminal number.

  • duration (float) – The number of seconds to count edges for.

  • nsamples (int) – The number of times to count edges for duration seconds.

  • rising (bool) – Whether to count rising edges, otherwise count falling edges.

Return type:

Samples

Returns:

The number of edges per second.

digital_in(lines, *, port=1)[source]

Read the state of the digital-input channel(s).

Parameters:
  • lines (int | str) – The line number(s) (e.g., line=1, line=’0:7’, line=’/Dev1/port0/line0:7,/Dev1/port1/line0:3’).

  • port (int) – The port number.

Return type:

bool | list[bool]

Returns:

Whether the requested digital input channel(s) are HIGH or LOW.

Examples

Read the state of a single digital-input channel (P1.0)

>>> daq.digital_in(0)
False

Read the state of a single digital-input channel (P0.2)

>>> daq.digital_in(2, port=0)
True

Read the state of multiple digital-input channels (P1.0-7)

>>> daq.digital_in('0:7')
[False, False, True, False, False, False, False, True]
digital_out(lines, state, *, auto_start=True, port=1, timeout=10, timing=None, trigger=None, wait=True)[source]

Write the state of digital-output channels(s).

Parameters:
  • lines (int | str) – The line number(s) (e.g., line=1, line=’0:7’, line=’/Dev1/port0/line0:7,/Dev1/port1/line0:3’).

  • state (bool | list[bool] | list[list[bool]]) – Whether to set the specified line(s) to HIGH or LOW.

  • auto_start (bool) – Whether to automatically start the task.

  • port (int) – The port number.

  • timeout (float) – The maximum number of seconds to wait for the task to finish. Set to -1 to wait forever.

  • timing (Timing) – The timing settings to use. See timing().

  • trigger (Trigger) – The trigger settings to use. See trigger().

  • wait (bool) – Whether to wait for the task to finish. If enabled then also closes the task when it is finished.

Return type:

Task

Returns:

The digital-output task.

Examples

Set the state of a single digital-output channel (P1.0)

>>> daq.digital_out(0, True)

Set multiple digital-output channels to be in the same state (P2.0-7)

>>> daq.digital_out('0:7', False, port=2)

Set the state of multiple digital-output channels (P1.2-4)

>>> daq.digital_out('2:4', [False, True, True])
digital_out_read(lines, *, port=1)[source]

Read the state of digital-output channel(s).

Parameters:
  • lines (int | str) – The line number(s) (e.g., line=1, line=’0:7’, line=’/Dev1/port0/line0:7,/Dev1/port1/line0:3’).

  • port (int) – The port number.

Return type:

bool | list[bool]

Returns:

Whether the requested digital-output channel(s) are HIGH or LOW.

Examples

Read the state of a single digital-output channel (P1.0)

>>> daq.digital_out_read(0)
True

Read the state of a single digital-output channel (P0.5)

>>> daq.digital_out_read(5, port=0)
False

Read the state of multiple digital-output channels (P1.0-7)

>>> daq.digital_out_read('0:7')
[False, True, True, False, True, False, False, False]
edge_separation(start, stop, *, maximum=1.0, minimum=1e-07, nsamples=10, start_edge='RISING', stop_edge='FALLING', timeout=10)[source]

Get the duration, in seconds, between two edges.

Parameters:
  • start (int) – The PFI terminal number to use for the start time, t=0.

  • stop (int) – The PFI terminal number to use for the stop time, t=dt. Can be same as start provided that start_edge and stop_edge are different values.

  • maximum (float) – The maximum time, in seconds, between the start-stop edges that is expected.

  • minimum (float) – The minimum time, in seconds, between the start-stop edges that is expected.

  • nsamples (int) – The number of start-stop samples to acquire.

  • start_edge (int | str) – Specifies on which edge to start each measurement. See Edge for allowed values.

  • stop_edge (int | str) – Specifies on which edge to stop each measurement. See Edge for allowed values.

  • timeout (float) – The maximum number of seconds to wait for the task to finish. Set to -1 to wait forever.

Return type:

Samples

Returns:

The duration(s), in seconds, between the start-stop edges.

function_generator(channel, *, amplitude=1, duty=0.5, frequency=1000, offset=0, nsamples=1000, phase=0, preview=False, symmetry=1.0, trigger=None, waveform='sine')[source]

Generate a waveform.

Parameters:
  • channel (int | str) – The analog-output channel number(s), e.g., channel=0, channel=’0:1’.

  • amplitude (float) – The zero-to-peak amplitude of the waveform to generate in volts. Zero and negative values are valid.

  • duty (float) – The duty cycle of the square wave. Must be in the interval [0, 1]. Only used if waveform is square.

  • frequency (float) – The frequency of the waveform to generate, in Hz.

  • offset (float) – The voltage offset of the waveform to generate.

  • nsamples (int) – The number of voltage samples per waveform period.

  • phase (float) – The phase of the waveform, in degrees.

  • preview (bool) – Whether to return a ndarray of a single period of the waveform voltages.

  • symmetry (float) – The symmetry of the ramp. Corresponds to the ratio of the rising portion of the ramp to the ramp period. For example, a symmetry of 0.5 corresponds to a triangle wave. Must be in the interval [0, 1]. Only used if waveform is ramp.

  • trigger (Trigger) – The trigger settings to use. See trigger().

  • waveform (str) – Specifies the kind of waveform to generate. Can be: sine, square, ramp, triangle, sawtooth.

Return type:

Task | ndarray

Returns:

The analog-output task or a single period of the waveform if preview is True.

info()[source]

Returns the driver information about the NIDAQ board.

Return type:

dict[str, int]

pulse(pfi, duration, *, ctr=1, delay=0, npulses=1, state=True, timeout=-1, wait=True)[source]

Generate one (or more) digital pulse(s).

If state is True then the pfi terminal will output 0V for delay seconds, generate npulses +5V pulse(s) (each with a width of duration seconds) and then remain at 0V when the task is done.

If state is False then the pfi terminal will output +5V for delay seconds, generate npulses 0V pulse(s) (each with a width of duration seconds) and then remain at +5V when the task is done.

Parameters:
  • pfi (int) – The PFI terminal number to output the pulse(s) from.

  • duration (float) – The duration (width) of each pulse, in seconds.

  • ctr (int) – The counter terminal number to use for timing.

  • delay (float) – The number of seconds to wait before generating the first pulse.

  • npulses (int) – The number of pulses to generate.

  • state (bool) – Whether to generate HIGH or LOW pulse(s).

  • timeout (float) – The maximum number of seconds to wait for the task to finish. Set to -1 to wait forever.

  • wait (bool) – Whether to wait for the task to finish. If enabled then also closes the task when it is finished.

Return type:

Task

Returns:

The task.

Examples

Generate a single HIGH pulse for 0.1 seconds from PFI2

>>> daq.pulse(2, 0.1)
storm(camera, sequence)[source]

Create a task for STORM/PALM acquisition.

For example, for a 4-frame sequence controlling two lasers:

sequence = {
  'port0/line0': [True, False, False, False],
  'port0/line1': [False, True, True, True]
}
Parameters:
  • camera (int) – The PFI terminal number that the camera’s Fire signal is connect to.

  • sequence (dict) – The keys are the digital-output terminals that turn the laser pulses on/off and the values represent the state of the lasers in each frame.

Return type:

Task

Returns:

The task.

timing(*, finite=True, pfi=None, rate=1000, rising=True)[source]

Configure and return the sample clock to add to a task.

Parameters:
  • finite (bool) – Whether to acquire/generate a continuous or a finite number of samples.

  • pfi (int) – The PFI terminal number to use as the external sample clock. If not specified then uses the default onboard clock of the device.

  • rate (float) – The sampling rate in Hz. If you specify an external sample clock (i.e., a value for pfi) then set the rate to be the maximum expected rate of the external clock.

  • rising (bool) – Whether to acquire/generate samples on the rising or falling edge of the sample clock.

Return type:

Timing

Returns:

The timing instance.

trigger(source, *, delay=0, hysteresis=0, level=None, retriggerable=False, rising=True)[source]

Configure and return a trigger to add to a task.

Parameters:
  • source (int | str) – Either a PFI or an AI channel number or a terminal name to use as the trigger source.

  • delay (float) – The time (in seconds) between the trigger event and when to acquire/generate samples. Can be < 0 to acquire/generate samples before the trigger event (only if the NIDAQ task supports it).

  • hysteresis (float) – A hysteresis level (in volts). Only applicable for an analog trigger.

  • level (float) – The voltage level to use for the trigger signal. Whether this value is set decides whether the trigger source is from a digital or an analog channel. If None then channel refers to a PFI channel (a digital trigger), otherwise, channel refers to an AI channel (an analog trigger).

  • retriggerable (bool) – Whether the task can be retriggered.

  • rising (bool) – Whether to use the rising or falling edge(slope) of the digital(analog) trigger signal.

Return type:

Trigger

Returns:

The trigger instance.

staticMetaObject = PySide6.QtCore.QMetaObject("NIDAQ" inherits "BaseEquipment": Methods:   #4 type=Signal, signature=counts_changed(PyObject), parameters=PyObject )
static time_array(n, dt)[source]

Create an array based on a sampling time.

Parameters:
  • n (int | ndarray) – The number of samples. If an array of voltage samples is passed in, then the returned time array will have the appropriate size.

  • dt (float) – The sampling time.

Return type:

ndarray

Returns:

The array (e.g., [0, dt, 2*dt, 3*dt, …, (n-1)*dt]).

static wait_until_done(*tasks, timeout=10.0)[source]

Wait until all tasks are done and then close each task.

Parameters:
  • tasks (Task) – The task(s) to wait for.

  • timeout (float) – The number of seconds to wait for each task to finish. Set to -1 to wait forever.

Return type:

None