Adapters

DAQmx is a python wrapper to the National Instruments DAQmx driver.

Adapters are abstract helper classes to simply use the National Instruments hardware.

You need the io feature in your license to unlock the DAQmx features.

Digital Input Single Line

Simple usage:

from htf.daqmx import DigitalInputSingleLine

di = DigitalInputSingleLine("cDaq1Mod1/line0")
print(di.get())

Usage in delegation context:

from htf.daqmx import DigitalInputSingleLine

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.di = DigitalInputSingleLine("cDaq1Mod1/line0")

ha = HardwareAbstraction()
# get current value
print(ha.di)
class htf.daqmx.DigitalInputSingleLine(descriptor)

DigitalInputSingleLine is used to access a single digital input line on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters

descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0.

close()

Close the abstractor by clearing the task.

get()

Return the current pin state.

set(state=True)

The setter for a delegate.

Parameters

value – the value to be set.

Note

This method is abstract.

Digital Input Port

Simple usage:

from htf.daqmx import DigitalInputPort

di = DigitalInputPort("cDaq1Mod1/port0")
print(di.get())

Usage in delegation context:

from htf.daqmx import DigitalInputPort

class HardwareAbstraction(DelegatorMixin):
   def __init__(self):
      self.di = DigitalInputPort("cDaq1Mod1/port0")

ha = HardwareAbstraction()
# get current value
print(ha.di)
class htf.daqmx.DigitalInputPort(descriptor)

DigitalInputPort is used to access a digital input port on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters

descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/port0.

close()

Close the abstractor by clearing the task.

get()

Return the current port state.

Digital Output Single Line

Simple usage:

from htf.daqmx import DigitalOutputSingleLine

do = DigitalOutputSingleLine("cDaq1Mod1/line0")
print(do.set(1))

Usage in delegation context:

from htf.daqmx import DigitalOutputSingleLine

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.do = DigitalOutputSingleLine("cDaq1Mod1/line0")

ha = HardwareAbstraction()
# set current value to 1
ha.do = 1
class htf.daqmx.DigitalOutputSingleLine(descriptor)

DigitalOutputSingleLine is used to access a single digital output line on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters

descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0.

close()

Close the abstractor by clearing the task.

get()

Read the current pin state.

reset()

Reset the pin state.

set(state=True)

Set the pin state to state.

Parameters

state=True (bool) – new state for output pin.

Digital Output Port

Simple usage:

from htf.daqmx import DigitalOutputPort

do = DigitalOutputPort("cDaq1Mod1/port0")
do.set(0x12345678)

Usage in delegation context:

from htf.daqmx import DigitalOutputPort

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.do = DigitalOutputPort("cDaq1Mod1/port0")

ha = HardwareAbstraction()
# set current value to 0x12345678
ha.do = 0x12345678
class htf.daqmx.DigitalOutputPort(descriptor)

DigitalOutputPort is used to access a digital output port on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters

descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/port0.

close()

Close the abstractor by clearing the task.

get()

Return the current port state.

set(value)

Set the port to value.

Parameters

value (float) – new value for output port

Analog Voltage Input Single Line

Simple usage:

from htf.daqmx import AnalogVoltageInputSingleLine

ai = AnalogVoltageInputSingleLine("cDaq1Mod1/line0")
print(ai.get())

Usage in delegation context:

from htf.daqmx import AnalogVoltageInputSingleLine

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.ai = AnalogVoltageInputSingleLine("cDaq1Mod1/line0")

ha = HardwareAbstraction()
# get current value
print(ha.ai)
class htf.daqmx.AnalogVoltageInputSingleLine(descriptor, minimumVoltage=-10.0, maximumVoltage=10.0, terminalConfig=-1)

AnalogVoltageInputSingleLine is used to access a single analog output line on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0

  • minimumVoltage=-10.0 (float) – the minimum voltage.

  • maximumVoltage=10.0 (float) – the maximum voltage.

  • terminalConfig=DAQmx_Val_Cfg_Default – the terminal configuration for DAQmxCreateAIVoltageChan(). Possible values: DAQmx_Val_RSE, DAQmx_Val_NRSE, DAQmx_Val_Diff, DAQmx_Val_PseudoDiff.

close()

Close the abstractor by clearing the task.

get()

Return the current pin value.

set(state=True)

The setter for a delegate.

Parameters

value – the value to be set.

Note

This method is abstract.

Analog Voltage Input Single Line Accurate (averaging analog input)

Simple usage:

from htf.daqmx import AnalogVoltageInputSingleLineAccurate

ai = AnalogVoltageInputSingleLineAccurate("cDaq1Mod3/ai0", numberOfSamples=100, timeout=3.0, sampleFrequency=100)
print(ai.get())

Usage in delegation context:

from htf.daqmx import AnalogVoltageInputSingleLineAccurate

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.ai = AnalogVoltageInputSingleLineAccurate("cDaq1Mod3/ai0", numberOfSamples=100, timeout=3.0, sampleFrequency=100)

ha = HardwareAbstraction()
# get current value
print(ha.ai)
class htf.daqmx.AnalogVoltageInputSingleLineAccurate(descriptor, minimumVoltage=-10.0, maximumVoltage=10.0, numberOfSamples=2, sampleFrequency=1000.0, timeout=1.0, terminalConfig=-1)

AnalogVoltageInputSingleLineAccurate is used to access a single analog input line on a DAQmx device. It acquires some samples and builds the average value of them.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0

  • minimumVoltage=-10.0 (float) – the minimum voltage.

  • maximumVoltage=10.0 (float) – the maximum voltage.

  • numberOfSamples=2 (int) – the number of samples to acquire for one average value.

  • sampleFrequency=1000.0 (float) – the sample frequency in Hertz.

  • timeout=1.0 (float) – the timeout when acquiring a new value in seconds.

  • terminalConfig=DAQmx_Val_Cfg_Default – the terminal configuration for DAQmxCreateAIVoltageChan(). Possible values: DAQmx_Val_RSE, DAQmx_Val_NRSE, DAQmx_Val_Diff, DAQmx_Val_PseudoDiff.

close()

Close the abstractor by clearing the task.

get()

Return the current pin value.

set(value=True)

The setter for a delegate.

Parameters

value – the value to be set.

Note

This method is abstract.

Analog Voltage Input Port

Simple usage:

from htf.daqmx import AnalogVoltageInputPort

aport = AnalogVoltageInputPort("cDaq1Mod3/ai0:2", numberOfLines=3, numberOfSamples=2, timeout=3.0, sampleFrequency=1000)
print(aport.get())
# [
#     [line0_sample0, line0_sample1],
#     [line1_sample0, line1_sample1],
#     [line2_sample0, line2_sample1]
# ]

Usage in delegation context:

from htf.daqmx import AnalogVoltageInputPort

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.aport = AnalogVoltageInputPort("cDaq1Mod3/ai0:2", numberOfLines=3, numberOfSamples=2, timeout=3.0, sampleFrequency=1000)


ha = HardwareAbstraction()
# get current values
print(ha.aport)
# [
#     [line0_sample0, line0_sample1],
#     [line1_sample0, line1_sample1],
#     [line2_sample0, line2_sample1]
# ]
class htf.daqmx.AnalogVoltageInputPort(descriptor, minimumVoltage=-10.0, maximumVoltage=10.0, numberOfLines=32, numberOfSamples=2, sampleFrequency=1000.0, timeout=1.0, terminalConfig=-1, continuousMode=False)

AnalogVoltageInputPort is used to access a single analog input port on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0.

  • minimumVoltage=-10.0 (float) – the minimum voltage.

  • maximumVoltage=10.0 (float) – the maximum voltage.

  • numberOfLines=32 (int) – the number of lines defined in the descriptor. For example the descriptor “cDaq1Mod3/ai0:31” defines 32 lines.

  • numberOfSamples=2 (int) – the number of samples to acquire for one average value.

  • sampleFrequency=1000.0 (float) – the sample frequency in Hertz.

  • timeout=1.0 (float) – the timeout when acquiring a new value in seconds.

  • terminalConfig=DAQmx_Val_Cfg_Default – the terminal configuration for DAQmxCreateAIVoltageChan(). Possible values: DAQmx_Val_RSE, DAQmx_Val_NRSE, DAQmx_Val_Diff, DAQmx_Val_PseudoDiff.

  • continuousMode=False – if set to True continuous sampling is done and get() becomes blocking. Simply read samples in a loop.

close()

Close the abstractor by clearing the task.

get()

Return the current analog value.

Returned data layout:

[
    [line0 sample0, line0 sample1, ..., line0 sampleN-1],
    [line1 sample0, line1 sample1, ..., line1 sampleN-1],
    ...
    [lineM-1 sample0, lineM-1 sample1, ..., lineM-1 sampleN-1]
]
set(state=True)

The setter for a delegate.

Parameters

value – the value to be set.

Note

This method is abstract.

Analog Voltage Output Single Line

Simple usage:

from htf.daqmx import AnalogVoltageOutputSingleLine

ao = AnalogVoltageOutputSingleLine("cDaq1Mod1/line0")
print(ao.set(3.0))

Usage in delegation context:

from htf.daqmx import AnalogVoltageOutputSingleLine

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.ao = AnalogVoltageOutputSingleLine("cDaq1Mod1/line0")

ha = HardwareAbstraction()
# set value
ha.ao = 1.337
class htf.daqmx.AnalogVoltageOutputSingleLine(descriptor, minimumVoltage=-10.0, maximumVoltage=10.0)

AnalogVoltageOutputSingleLine is used to access a single analog output line on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0

  • minimumVoltage=-10.0 (float) – the minimum voltage.

  • maximumVoltage=10.0 (float) – the maximum voltage.

close()

Close the abstractor by clearing the task.

get()

Return the last written analog value.

set(value)

Set the pin value to value.

Parameters

value (float) – new state for output pin.

Analog Voltage Output Port

Simple usage:

from htf.daqmx import AnalogVoltageOutputPort

aport = AnalogVoltageOutputPort("cDaq1Mod3/ao0:2", numberOfLines=3, numberOfSamples=2, timeout=3.0, sampleFrequency=1000)
# write data
data = [
        [line0_sample0, line0_sample1],
        [line1_sample0, line1_sample1],
        [line2_sample0, line2_sample1]
]

aport.set(data)

Usage in delegation context:

from htf.daqmx import AnalogVoltageOutputPort

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.aport = AnalogVoltageOutputPort("cDaq1Mod3/ao0:2", numberOfLines=3, numberOfSamples=2, timeout=3.0, sampleFrequency=1000)

ha = HardwareAbstraction()
# write data
data = [
        [line0_sample0, line0_sample1],
        [line1_sample0, line1_sample1],
        [line2_sample0, line2_sample1]
]
ha.aport = data
class htf.daqmx.AnalogVoltageOutputPort(descriptor, minimumVoltage=-10.0, maximumVoltage=10.0, numberOfLines=32, numberOfSamples=2, sampleFrequency=1000.0, timeout=1.0, continuousMode=False)

AnalogVoltageOutputPort is used to access a single analog output port on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/line0

  • minimumVoltage=-10.0 (float) – the minimum voltage.

  • maximumVoltage=10.0 (float) – the maximum voltage.

  • numberOfLines=32 (int) – the number of lines defined in the descriptor. For example the descriptor “cDaq1Mod3/ai0:31” defines 32 lines.

  • numberOfSamples=2 (int) – the number of samples to write for every line.

  • sampleFrequency=1000.0 (float) – the sample frequency in Hertz.

  • timeout=1.0 (float) – the timeout when acquiring a new value in seconds.

  • continuousMode=False – if set to True continuous sampling is done and get() becomes blocking. Simply read samples in a loop.

close()

Close the abstractor by clearing the task.

get()

Return the last written analog values.

Returned data layout:

[
    [line0 sample0, line0 sample1, ..., line0 sampleN-1],
    [line1 sample0, line1 sample1, ..., line1 sampleN-1],
    ...
    [lineM-1 sample0, lineM-1 sample1, ..., lineM-1 sampleN-1]
]
set(values)

Write analog data.

Parameters

values – samples to be written on the output port.

values are expected to have the following layout:

[
    [line0 sample0, line0 sample1, ..., line0 sampleN-1],
    [line1 sample0, line1 sample1, ..., line1 sampleN-1],
    ...
    [lineM-1 sample0, lineM-1 sample1, ..., lineM-1 sampleN-1]
]

Edge Counter Input

Simple usage:

from htf.daqmx import EdgeCounterInput

ctr0 = EdgeCounterInput(descriptor="cDaq1Mod4/ctr0", initialCount=0, risingEdge=True, countUp=True)
# get current value
print(ctr0.get())
# reset counter
ctr0.set(0)
# or
ctr0.reset()
# set counter to 10
ctr0.set(10)

Usage in delegation context:

from htf.daqmx import EdgeCounterInput

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.edges = EdgeCounterInput(descriptor="cDaq1Mod4/ctr0", initialCount=0, risingEdge=True, countUp=True)

ha = HardwareAbstraction()
# get current value
print(ha.edges)
# reset counter
ha.edges = 0
# set counter to 10
ha.edges = 10
class htf.daqmx.EdgeCounterInput(descriptor, initialCount=0, risingEdge=True, countUp=True)

EdgeCounterInput is used to access a counter input on a DAQmx device. The counter is 32 bit wide.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/ctr0.

  • initialCount=0 (int) – The initial count.

  • risingEdge=True (bool) – If set to True rising edges are counted else falling edges are counted.

  • countUp=True (bool) – If set to True the counter direction is up else it is down.

close()

Close the abstractor by clearing the task.

get()

Return the current edge count.

reset()

Reset the counter to 0.

set(count)

Set the count to the desired value.

Parameters

count (int) – the new counter value

Frequency Input

Simple usage:

from htf.daqmx import FrequencyInput

f0 = FrequencyInput(descriptor="cDaq1Mod4/ctr0", fMin=1000.0, fMax=10000.0, measurementTime=0.001, risingEdge=True)
print(f0.get())

Usage in delegation context:

from htf.daqmx import FrequencyInput

class HardwareAbstraction(DelegatorMixin):
    def __init__(self):
        self.f0 = FrequencyInput(descriptor="cDaq1Mod4/ctr0", fMin=1000.0, fMax=10000.0, measurementTime=0.001, risingEdge=True)

ha = HardwareAbstraction()
# get current value
print(ha.f0)
class htf.daqmx.FrequencyInput(descriptor, fMin, fMax, measurementTime, risingEdge=True)

FrequencyInput is used to measure a low frequency in hertz on a DAQmx device.

A DAQmx task is automatically created and deleted in the constructor and destructor.

Parameters
  • descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/ctr0

  • fMin (float) – The minimum frequency in the input signal in Hertz.

  • fMin – The maximum frequency in the input signal in Hertz.

  • risingEdge=True (bool) – If set to True rising edges are counted else falling edges are counted.

  • measurementTime (float) – The measurement time in seconds.

close()

Close the abstractor by clearing the task.

get()

Return the current frequency.

Frequency Input Inaccurate

Usage:

from htf.daqmx import FrequencyInputInaccurate

fi = FrequencyInputInaccurate(descriptor="cDaq1Mod4/ctr0")
# measure 10 seconds with a sample rate of 10 Hz.
frequencies = fi.sample(period=0.1, samples=100)
# output the frequency list
print("frequencies:", frequencies)
class htf.daqmx.FrequencyInputInaccurate(descriptor)

FrequencyInputInaccurate is used to measure a frequency using an EdgeCounterInput.

In comparison to FrequencyInput frequencies below 100 Hz can be measured, too.

Parameters

descriptor (str) – The DAQmx device and line descriptor, eg. cDaq1Mod1/ctr0.

sample(period=1.0, samples=1)

For samples times measure the count of edges within one period and convert it to Hz.

Returns an array containing the measured frequencies.

Parameters
  • period (float) – the time in seconds between two samples.

  • samples (int) – the amount of samples.

Returns

the list of samples.

Return type

list of float