API documentation — openDAQ 0.2.0 documentation

# API documentation

## opendaq.daq module

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

class `opendaq.daq.` `CMD`

  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)

  Bases: `object`

  This class represents an OpenDAQ device.

  `clear_experiments`()

    Delete the whole experiment list.

  `close`()

    Close the serial port.

  `conf_adc`(pinput=8, ninput=0, gain=0, nsamples=20)

    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)

    Create Burst experiment.

    See the `DAQBurst` class constructor for more info.

  `create_external`(mode, clock_input, *args, **kwargs)

    Create External experiment.

    See the `DAQExternal` class constructor for more info.

  `create_stream`(mode, *args, **kwargs)

    Create Stream experiment.

    See the `DAQStream` class constructor for more info.

  `enable_crc`(on)

    Enable/Disable the cyclic redundancy check.

    Parameters: | on – Enable/disable CRC checking (bool).

  `flush`()

    Flush internal buffers.

  `flush_channel`(number)

    Flush the channel.

    Parameters: | number – Number of DataChannel to flush.
    Returns: | ValueError

  `get_adc_calib`()

    Get the ADC calibration.

    Returns: | List of ADC calibration registers

  `get_capture`(mode)

    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)

    Get the counter value.

    Parameters: | reset – reset the counter after perform reading (boolean).

  `get_dac_calib`()

    Get the DAC calibration.

    Returns: | List of DAC calibration registers

  `get_encoder`()

    Get current encoder relative position.

    Returns: | Position: The actual encoder value.

  `get_info`()

    Read device information.

    Returns: | [hardware_version, firmware_version, device_id]

  `get_state_ch`(number)

    Get state of the DataChannel.

    Parameters: | number – Number of the DataChannel.
    Raises: | ValueError

  `init_capture`(period)

    Start Capture Mode around a given period.

    Parameters: | period – Estimated period of the wave (in microseconds).
    Raises: | ValueError

  `init_counter`(edge)

    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)

    Start Encoder function.

    Parameters: | resolution – Maximum number of ticks per round [0:65535].
    Raises: | ValueError

  `init_pwm`(duty, period)

    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`()

    Open the serial port.

  `read_adc`()

    Read data from ADC and return the raw value.

    Returns: | Raw ADC value.

  `read_all`(nsamples=20, gain=0)

    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`()

    Read data from ADC in volts.

    Returns: | Voltage value.

  `read_eeprom`(pos)

    Read a byte from the EEPROM.

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

  `read_pio`(number)

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

    Parameters: | number – PIO number.
    Returns: | Read value.
    Raises: | ValueError

  `read_port`()

    Read all PIO values.

    Returns: | Binary value of the port.

  `remove_experiment`(experiment)

    Delete a single experiment.

    Parameters: | experiment – reference of the experiment to remove.
    Raises: | ValueError

  `send_command`(command, ret_fmt=None)

    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)

    Set the ADC calibration.

    Parameters: | regs – A list of CalibReg objects.
    Raises: | ValueError, IndexError

  `set_analog`(volts, number=1)

    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)

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

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

  `set_dac_calib`(regs)

    Set the DAC calibration.

    Parameters: | regs – A list of CalibReg objects.
    Raises: | ValueError, IndexError

  `set_id`(id)

    Identify openDAQ device.

    Parameters: | id – id number of the device [000:999]
    Raises: | ValueError

  `set_led`(color, number=1)

    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)

    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)

    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)

    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)

    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)

    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)

    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)

    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`()

    Start all available experiments.

  `stop`(clear=False)

    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`()

    Stop Capture mode.

  `stop_encoder`()

    Stop encoder

  `stop_pwm`()

    Stop PWM

  `trigger_mode`(number)

    Get the trigger mode of the DataChannel.

    Parameters: | number – Number of the DataChannel.
    Raises: | ValueError

  `write_eeprom`(pos, val)

    Write a byte in the EEPROM.

    Parameters: | id – id number of the device [000:999].
    Raises: | ValueError

class `opendaq.daq.` `LedColor`

  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)

  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`

  Bases: `object`

  `add_points`(points)

    Write a single point into the ring buffer.

  `analog_setup`(pinput=1, ninput=0, gain=1, nsamples=20)

    Configure a channel for a generic stream experiment.

  `get_mode`()

    Return mode.

  `get_params`()

    Return gain, pinput and ninput.

  `get_preload_data`()

    Return preload_data and preload_offset.

  `load_signal`(data, offset=0)
  `read`()

    Return all available points from the ring buffer.

  `trigger_setup`(mode=<Trigger.SW: 0>, value=0)

    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)

  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)

  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`

  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`

  Bases: `enum.IntEnum`

  Valid trigger modes.

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