fixate.drivers.daq package¶
- fixate.drivers.daq.open()¶
Submodules¶
fixate.drivers.daq.daqmx module¶
NI IO Trace can be used to troubleshoot & debug the setup. It should be installed when the NI-DAQmx driver is installed.
PyDAQmx parses the NIDAQmx.h header to build ctypes wrappers for all function, constants, etc. It also wraps the functions which return errors codes to raise exceptions (and warnings) based on the return value.
https://www.ni.com/en-au/support/downloads/drivers/download.ni-daqmx.html#409845
API Reference manual: https://zone.ni.com/reference/en-XX/help/370471AM-01/
C:Program Files (x86)National InstrumentsNI-DAQDAQmx ANSI C DevincludeNIDAQmx.h C:Program FilesNational InstrumentsNI-DAQDAQmx ANSI C DevincludeNIDAQmx.h
- class fixate.drivers.daq.daqmx.BufferedWrite(task_string, io_length, frequency)¶
Bases:
DaqTask- init()¶
This method should be overridden to create the task :return:
- write(data)¶
The task should be in stopped state when calling write, it automatically starts the task through the DAQmxWriteDigitalLines call. When write is finished it is back in a stopped state :param data: :return:
- class fixate.drivers.daq.daqmx.DaqMx¶
Bases:
objectImplements the digital input and output functions of the National Instruments DAQ usage: daq = DaqMx()
# Create a digital output from port 0 line 2 to line 4 named ‘P0.2:4’ daq.create_digital_output(‘P0.2:4’, port=0, range_start=2, length=3)
# Create a digital output with default port 0, at line 7 named ‘reset’ daq.create_digital_output(‘reset’, 7)
# Create a digital input at port 0 line 1 daq.create_digital_input(‘P0.1’, range_start=1)
# This example assumes that port 0 line 1 is shorted to port 0 line 7 named reset
daq.start() print(“Port 7:”, daq[“reset”], “Echo Port:”, daq[“P0.1”]) >>>’Port 7: [0] Echo Port: [0]’ daq[“P0.7”] = 1 # or True or ‘1’ or [1] print(“Port 7:”, daq[“reset”], “Echo Port:”, daq[“P0.1”]) >>>’Port 7: [1] Echo Port: [1]’ print(daq[“P0.2:4”]) >>>’[0 0 0]’ daq[“P0.2:4”] = [0, 1, 0] # Need to assign all values if initialised as multiple print(daq[“P0.2:4”]) >>>’[0 1 0]’ daq.stop()
- clear_task(ident)¶
Stops a task and clear up the resources allocated to the :param ident: :return:
- create_buffered_write(ident, frequency, *dio_ranges)¶
Sets up the ranges to synchronize when writing to output at a specified frequency. This will force each write to the output for this ident to contain the amount of samples specified. eg. >>>daq = DaqMx() # Setup output @ 100Hz, 3 samples on port0 line 7 and 9 >>>daq.create_buffered_write(“MyOutput”, 100, (0, 7, 7), (0, 9, 9)) 3 samples over 2 lines is 6 data values. >>>daq[“MyOutput”] = [0 ,0, 1, 1, 0, 1] it is interleaved so it is written [line7, line9, line7, line9, line7, line9] Requires ports that enable buffered writes. In the X-Series daq this is port 0 This disables reading from the output port for these pins.
:param ident The identification used to access this message :param frequency The sample frequency for writing :type frequency integer or float :param io_ranges :type (port, line_start, line_end) :param samples The amount of samples that are required for each digital output write
- create_digital_input(ident, *dio_ranges)¶
:param dio_ranges each dio_range is a tuple of (‘port’, ‘range_start’, ‘range_end’) or an IORange instance. A digital output is created in the order of the dio_ranges and can be accessed by the ident key. >>>daq = DaqMx() >>>rng_1 = IORange(0, 7, 9) # Port 0 line 7 to line 9 >>>rng_2 = IORange(0, 11,11) # Port 0 line 11 >>>daq.create_digital_input(“MyOut”, rng_1, rng_2) >>>print(daq[“MyOut”]) # Tie Port 0 line 8 and line 11 high >>>[0, 1, 0, 1]
- create_digital_output(ident, *dio_ranges)¶
:param dio_ranges each dio_range is a tuple of (‘port’, ‘range_start’, ‘range_end’) or an IORange instance. A digital output is created in the order of the dio_ranges and can be accessed by the ident key. >>>daq = DaqMx() >>>rng_1 = IORange(0, 7, 9) # Port 0 line 7 to line 9 >>>rng_2 = IORange(0, 11,11) # Port 0 line 11 >>>daq.create_digital_output(“MyOut”, rng_1, rng_2) >>>daq[“MyOut”] = [0, 1, 0, 1] # Port 0 Line 8 and 11 high >>>print(daq[“MyOut”]) # Read back the value >>>[0, 1, 0, 1]
- create_two_edge_separation(ident, counter_chan, min_val, max_val, first_edge_type, second_edge_type, source_terminal=None, destination_terminal=None)¶
Returns the two edge separation of two signals :param ident: Identification string used for reading the data via daq = DaqMx() daq.create_two_edge_separation(ident, **params) daq.trigger_measurement(ident) # Do stuff # Read the edge separation after causing the event edge_sep = daq[ident] :param counter_chan: For X-Series DAQs PCI ‘ctr0’, ‘ctr1’, ‘ctr2’, ‘ctr3’ where the connected terminals are: Start = “AUX”, Stop = “GATE” ctr0 ctr1 ctr2 ctr3 Start: PFI 10 Pin45 Start: PFI 11 Pin46 Start: PFI 2 Pin43 Start: PFI 7 Pin38 Stop: PFI 9 Pin3 Stop: PFI 4 Pin41 Stop: PFI 1 Pin10 Stop: PFI 6 Pin5 :param min_val: The minimum value, in units, that you expect to measure. eg. 0.0001 :param max_val: The maximum value, in units, that you expect to measure. eg. 0.83 :param first_edge_type: The start trigger on the first edge “rising” or “falling” :param second_edge_type: The stop trigger on the second edge “rising” or “falling” :param source_terminal :param destination_terminal Override the default counter terminals. eg. ctr0 eg. source_terminal = “PFI14” will make the Start pin as PFI 14 in stead of 10
- read(ident)¶
- reset()¶
- signal_route(source_terminal, destination_terminal, disconnect=False, tri_state=False, invert=False)¶
Immediately routes a signal between two terminals Set destination_terminal to ‘’ if tri_state output is required on the source_terminal terminals are PFI X as they are the programmable terminals. See NI-MAX Device Routes for available terminal names. Leave out the device name eg. /Dev 1/PFI0 would be PFI0
- start_task(ident)¶
- Parameters:
ident
- Returns:
- stop_task(ident)¶
Stops a task to be :param ident: :return:
- trigger_measurement(ident)¶
- write(ident, value)¶
- class fixate.drivers.daq.daqmx.DaqTask¶
Bases:
object- clear()¶
- init()¶
This method should be overridden to create the task :return:
- read()¶
- start()¶
- stop()¶
- task = None¶
- task_state = ''¶
- trigger()¶
- write(data)¶
- class fixate.drivers.daq.daqmx.DigitalIn(task_string, io_length)¶
Bases:
DaqTask- init()¶
This method should be overridden to create the task :return:
- read()¶
- class fixate.drivers.daq.daqmx.DigitalOut(task_string, io_length)¶
Bases:
DaqTask- init()¶
This method should be overridden to create the task :return:
- read()¶
- write(data)¶
Data must be an iterable like a list of 1s and 0s Data is grouped by scan number. Each element in the array will write to each line in the digital output until exhausted and then will start from the beginning for the next sample. Sample rate is as set in creating the IO task.
- class fixate.drivers.daq.daqmx.IOLine(port, line)¶
Bases:
tuple- line¶
Alias for field number 1
- port¶
Alias for field number 0
- class fixate.drivers.daq.daqmx.IORange(port, range_start, range_end)¶
Bases:
tuple- port¶
Alias for field number 0
- range_end¶
Alias for field number 2
- range_start¶
Alias for field number 1
- exception fixate.drivers.daq.daqmx.ThreadError¶
Bases:
Exceptiongive a name to an error that came from a thread