API documentation

opendaq.daq module

Main functions used to communicate with the device. See usage.rst for additional info.

class opendaq.daq.CMD[source]

Bases: enum.IntEnum

AIN = 1
AIN_ALL = 4
AIN_CFG = 2
BURST_CREATE = 21
CAPTURE_INIT = 14
CAPTURE_STOP = 15
CHANNEL_CFG = 22
CHANNEL_DESTROY = 57
CHANNEL_FLUSH = 45
CHANNEL_SETUP = 32
COUNTER_INIT = 41
EEPROM_READ = 31
EEPROM_WRITE = 30
ENABLE_CRC = 55
ENCODER_INIT = 50
ENCODER_STOP = 51
EXTERNAL_CREATE = 20
GET_CALIB = 36
GET_CAPTURE = 16
GET_COUNTER = 42
GET_ENCODER = 52
GET_STATE_CHANNEL = 35
GET_TRIGGER_MODE = 34
ID_CONFIG = 39
LED_W = 18
PIO = 3
PIO_DIR = 5
PORT = 7
PORT_DIR = 9
PWM_DUTY = 12
PWM_INIT = 10
PWM_STOP = 11
RESET = 27
RESET_CALIB = 38
SET_ANALOG = 24
SET_CALIB = 37
SET_DAC = 13
SIGNAL_LOAD = 23
SPISW_CONFIG = 26
SPISW_SETUP = 28
SPISW_TRANSFER = 29
STREAM_CREATE = 19
STREAM_DATA = 25
STREAM_START = 64
STREAM_STOP = 80
TRIGGER_SETUP = 33
WAIT_MS = 17
class opendaq.daq.DAQ(port, debug=False)[source]

Bases: object

This class represents an OpenDAQ device.

clear_experiments()[source]

Delete the whole experiment list.

close()[source]

Close the serial port.

conf_adc(pinput=8, ninput=0, gain=0, nsamples=20)[source]

Configure the analog-to-digital converter.

Get the parameters for configure the analog-to-digital converter.

Parameters:
  • pinput – Positive input [1:8].
  • ninput – Negative input.
  • gain – Analog gain.
  • nsamples – Number of samples per data point [0-255).
Raises:

ValueError

create_burst(*args, **kwargs)[source]

Create Burst experiment.

See the DAQBurst class constructor for more info.

create_external(mode, clock_input, *args, **kwargs)[source]

Create External experiment.

See the DAQExternal class constructor for more info.

create_stream(mode, *args, **kwargs)[source]

Create Stream experiment.

See the DAQStream class constructor for more info.

enable_crc(on)[source]

Enable/Disable the cyclic redundancy check.

Parameters:on – Enable/disable CRC checking (bool).
flush()[source]

Flush internal buffers.

flush_channel(number)[source]

Flush the channel.

Parameters:number – Number of DataChannel to flush.
Returns:ValueError
get_adc_calib()[source]

Get the ADC calibration.

Returns:List of ADC calibration registers
get_capture(mode)[source]

Get Capture reading for the period length.

Parameters:mode – Period length (0: Low cycle, 1: High cycle, 2: Full period)
Returns:
  • mode
  • period: The period length in microseconds
Raises:ValueError
get_counter(reset)[source]

Get the counter value.

Parameters:reset – reset the counter after perform reading (boolean).
get_dac_calib()[source]

Get the DAC calibration.

Returns:List of DAC calibration registers
get_encoder()[source]

Get current encoder relative position.

Returns:Position: The actual encoder value.
get_info()[source]

Read device information.

Returns:[hardware_version, firmware_version, device_id]
get_state_ch(number)[source]

Get state of the DataChannel.

Parameters:number – Number of the DataChannel.
Raises:ValueError
init_capture(period)[source]

Start Capture Mode around a given period.

Parameters:period – Estimated period of the wave (in microseconds).
Raises:ValueError
init_counter(edge)[source]

Initialize the edge counter and configure which edge increments the count.

Parameters:edge – high-to-low (False) or low-to-high (True).
init_encoder(resolution)[source]

Start Encoder function.

Parameters:resolution – Maximum number of ticks per round [0:65535].
Raises:ValueError
init_pwm(duty, period)[source]

Start PWM output with a given period and duty cycle.

Parameters:
  • duty – High time of the signal [0:1023](0 always low, 1023 always high).
  • period – Period of the signal (microseconds) [0:65535].
Raises:

ValueError

is_measuring

True if any experiment is going on.

open()[source]

Open the serial port.

read_adc()[source]

Read data from ADC and return the raw value.

Returns:Raw ADC value.
read_all(nsamples=20, gain=0)[source]

Read data from all analog inputs

Parameters:
  • nsamples – Number of samples per data point [0-255] (default=20)
  • gain – Analog gain (default=1)
Returns:

Values[0:7]: List of the analog reading on each input

read_analog()[source]

Read data from ADC in volts.

Returns:Voltage value.
read_eeprom(pos)[source]

Read a byte from the EEPROM.

Parameters:
  • val – value to write.
  • pos – position in memory.
Raises:

ValueError

read_pio(number)[source]

Read PIO input value (0: low, 1: high).

Parameters:number – PIO number.
Returns:Read value.
Raises:ValueError
read_port()[source]

Read all PIO values.

Returns:Binary value of the port.
remove_experiment(experiment)[source]

Delete a single experiment.

Parameters:experiment – reference of the experiment to remove.
Raises:ValueError
send_command(command, ret_fmt=None)[source]

Build a command packet, send it to the openDAQ and process the response.

Parameters:
  • command – Command string.
  • ret_fmt – Payload format of the response using python ‘struct’ format characters. I ret_fmt is None, no response is expected.
Returns:

Command ID and arguments of the response.

Raises:

LengthError: The legth of the response is not the expected.

serial_str
set_adc_calib(regs)[source]

Set the ADC calibration.

Parameters:regs – A list of CalibReg objects.
Raises:ValueError, IndexError
set_analog(volts, number=1)[source]

Set DAC output (volts). Set the output voltage of the DAC.

Parameters:volts – DAC output value in volts.
Raises:ValueError
set_dac(raw, number=1)[source]

Set DAC output (raw value). Set the raw value of the DAC.

“param raw: Raw ADC value. :raises: ValueError

set_dac_calib(regs)[source]

Set the DAC calibration.

Parameters:regs – A list of CalibReg objects.
Raises:ValueError, IndexError
set_id(id)[source]

Identify openDAQ device.

Parameters:id – id number of the device [000:999]
Raises:ValueError
set_led(color, number=1)[source]

Choose LED status. LED switch on (green, red or orange) or switch off.

Parameters:color – LED color (use LedColor).
Raises:ValueError
set_pio(number, value)[source]

Write PIO output value. Set the value of the PIO terminal (0: low, 1: high).

Parameters:
  • number – PIO number.
  • value – digital value (0: low, 1: high)
Raises:

ValueError

set_pio_dir(number, output)[source]

Configure PIO direction. Set the direction of a specific PIO terminal (D1-D6).

Parameters:
  • number – PIO number.
  • output – PIO direction (0 input, 1 output).
Raises:

ValueError

set_port(value)[source]

Write all PIO values. Set the value of all Dx terminals.

Parameters:value – Port output byte (bits: 0:low, 1:high).
Raises:ValueError
set_port_dir(output)[source]

Configure all PIOs directions. Set the direction of all D1-D6 terminals.

Parameters:output – Port directions byte (bits: 0:input, 1:output).
Raises:ValueError
spi_config(cpol, cpha)[source]

Bit-Bang SPI configure (clock properties).

Parameters:
  • cpol – Clock polarity (clock pin state when inactive).
  • cpha – Clock phase (leading 0, or trailing 1 edges read).
Raises:

ValueError

spi_setup(nbytes, sck=1, mosi=2, miso=3)[source]

Bit-Bang SPI setup (PIO numbers to use).

Parameters:
  • nbytes – Number of bytes.
  • sck – Clock pin.
  • mosi – MOSI pin (master out / slave in).
  • miso – MISO pin (master in / slave out).
Raises:

ValueError

spi_write(value, word=False)[source]

Bit-bang SPI transfer (send+receive) a byte or a word.

Parameters:
  • value – Data to send (byte/word to transmit).
  • word – send a 2-byte word, instead of a byte.
Raises:

ValueError

start()[source]

Start all available experiments.

stop(clear=False)[source]

Stop all running experiments and exit threads.

Parameters:clear – If True, the experiment list will be cleared. The

experiments will no longer be available.

stop_capture()[source]

Stop Capture mode.

stop_encoder()[source]

Stop encoder

stop_pwm()[source]

Stop PWM

trigger_mode(number)[source]

Get the trigger mode of the DataChannel.

Parameters:number – Number of the DataChannel.
Raises:ValueError
write_eeprom(pos, val)[source]

Write a byte in the EEPROM.

Parameters:id – id number of the device [000:999].
Raises:ValueError
class opendaq.daq.LedColor[source]

Bases: enum.IntEnum

Valid LED colors.

GREEN = 1
OFF = 0
ORANGE = 3
RED = 2

Experiment classes

class opendaq.experiment.DAQBurst(mode, period, npoints=10, continuous=False, buffersize=4000)[source]

Bases: opendaq.experiment.DAQExperiment

Burst experiment.

Parameters:
  • mode – Define data source or destination (use ExpMode).
  • period – Period of the stream experiment (microseconds) [1:65536]
  • npoints – Total number of points for the experiment [0:65536]
  • continuous – Indicates if the experiment is continuous (False: run once, True: continuous).
  • buffersize – Buffer size
Raises:

LengthError (too many experiments at the same time), ValueError (values out of range)

class opendaq.experiment.DAQExperiment[source]

Bases: object

add_points(points)[source]

Write a single point into the ring buffer.

analog_setup(pinput=1, ninput=0, gain=1, nsamples=20)[source]

Configure a channel for a generic stream experiment.

get_mode()[source]

Return mode.

get_params()[source]

Return gain, pinput and ninput.

get_preload_data()[source]

Return preload_data and preload_offset.

load_signal(data, offset=0)[source]
read()[source]

Return all available points from the ring buffer.

trigger_setup(mode=<Trigger.SW: 0>, value=0)[source]

Channge the trigger mode of datachannel.

Parameters:
  • mode – Trigger mode (use Trigger).
  • value – Value of the trigger mode.
Raises:

ValueError

class opendaq.experiment.DAQExternal(mode, clock_input, edge=1, npoints=10, continuous=False, buffersize=1000)[source]

Bases: opendaq.experiment.DAQExperiment

External experiment.

Parameters:
  • mode – Define data source or destination (use ExpMode).
  • clock_input – Digital input used as external clock
  • edge – New data on rising (1) or falling (0) edges [0:1]
  • npoints – Total number of points for the experiment [0:65536]
  • continuous – Indicates if the experiment is continuous (False: run once, True: continuous).
  • buffersize – Buffer size
Raises:

LengthError (too many experiments at the same time, ValueError (values out of range)

class opendaq.experiment.DAQStream(mode, number, period, npoints=10, continuous=False, buffersize=1000)[source]

Bases: opendaq.experiment.DAQExperiment

Stream experiment.

Parameters:
  • mode – Define data source or destination (use ExpMode).
  • period – Period of the stream experiment (milliseconds) [1:65536]
  • npoints – Total number of points for the experiment [0:65536] (0 indicates continuous acquisition).
  • continuous – Indicates if experiment is continuous (True) or one-shot (False).
  • buffersize – Buffer size.
Raises:

LengthError (too many experiments at the same time), ValueError (values out of range)

class opendaq.experiment.ExpMode[source]

Bases: enum.IntEnum

Valid experiment modes.

ANALOG_IN = 0
ANALOG_OUT = 1
CAPTURE_IN = 5
COUNTER_IN = 4
DIGITAL_IN = 2
DIGITAL_OUT = 3
class opendaq.experiment.Trigger[source]

Bases: enum.IntEnum

Valid trigger modes.

ABIG = 10
ASML = 20
DIN1 = 1
DIN2 = 2
DIN3 = 3
DIN4 = 4
DIN5 = 5
DIN6 = 6
SW = 0