def _config_read_analog(self, channel, min_val=-10.0, max_val=10.0, **kwargs): """ Configure a channel or group of channels as an analog input Parameters ---------- channel: string a channel or group of channels that will all be read at the same time min_val: float the minimum voltage that can be read max_val: float the maximum voltage that can be read Returns ------- True if configuration succeeded """ logger.debug("Configuring analog input on channel(s) %s" % str(channel)) task = nidaqmx.AnalogInputTask() task.create_voltage_channel(channel, min_val=min_val, max_val=max_val) task.configure_timing_sample_clock(source=selsf.clock_channel, rate=self.samplerate, sample_mode="finite") self.tasks[channel] = task return True
def __init__(self, ni_input_line='Dev1/ai0', ni_trigger_line=None, sampling_duration=3, sampling_rate=2000, ni_task_name='AnalogInput'): """ Parameters ---------- ni_input_line : str, optional The analog input line to acquire the data from. Defaults to `Dev1/ai0`. ni_trigger_line : str, optional If specified, start the acquisition only after a start trigger (high voltage) on this line has been received. If `None`, no external trigger is required. sampling_duration : float, optional How long to sample, specified in seconds. Defaults to 3 seconds. sampling_rate : int, optional At which rate (in Hz) to sample the analog input signal. Defaults to 2000 Hz. ni_task_name : str, optional The name of the NIDAQmx task to create. Defaults to `AnalogInput`. """ self._sampling_duration = sampling_duration self._sampling_rate = sampling_rate self._samples_to_acquire = int(np.floor(self._sampling_rate * \ self._sampling_duration)) self._ni_task = nidaqmx.AnalogInputTask(name=ni_task_name) if not self._ni_task.create_voltage_channel( ni_input_line, min_val=-10, max_val=10): raise IOError('Could not create analog input channel.') if not self._ni_task.configure_timing_sample_clock( rate=self._sampling_rate, sample_mode='finite', samples_per_channel=self._samples_to_acquire): raise IOError('Could not configure analog input sample clock.') self._ni_task_number_of_channels = \ self._ni_task.get_number_of_channels() if ni_trigger_line is None: self._ni_task_number_of_trigger_channels = 0 else: if not self._ni_task.configure_trigger_digital_edge_start( ni_trigger_line): raise IOError('Could not configure trigger channel.') self._ni_task_number_of_trigger_channels = 1 # Data acquisition is set to be triggered by an external # trigger. Thus we can start the task immediately. if not self._ni_task.start(): raise IOError('Could not start analog input task.')
def __createChanAITaskLegacy(self, name, channels, acquisitionType, source, min_val=-0.5, max_val=10.0, sampsInScan=1000, reference_trigger='PFI12'): """ Simplified function to create an analog input task """ aitask = nidaqmx.AnalogInputTask(name) for channel in channels: aitask.create_voltage_channel(channel, min_val, max_val) aitask.configure_timing_sample_clock(source=source, sample_mode=acquisitionType, samps_per_chan=sampsInScan) aitask.configure_trigger_digital_edge_start(reference_trigger) return aitask
def __init__(self, nr=1, vrange1=10, vrange2=10, sf=2000.0, taver=1, check=True, parent=None): super(fluxgate, self).__init__(parent) self.volt_range1 = vrange1 #minimum voltage self.volt_range2 = vrange2 #maximum voltage self.average_time = taver self.sf = sf #sample frequency / data per second self.nr = nr #number of sensor self.task = nidaqmx.AnalogInputTask() #Creating a task self.t = [] self.xar = [] self.yar = [] self.zar = [] self.check = check self.samples = int(self.sf * self.average_time) #Number of full samples
# need to start the dio task first! import time import numpy as np import nidaqmx # some useful parameters nsamples = 5000 # about 5 sec samplerate = 1000 TERMINALEND = 'nrse' # consider 'rse' (referenced single-ended),'nrse' (non-referenced single ended) # 'diff', or 'pseudodiff' as other options, can look at panel for hints analog_input = r'Dev1/ai15' # connect analog input to this terminal, customize as you wish ndigital = 2 # number of digital channels digital_output_str = r'Dev1/port0/line6:7' itask = nidaqmx.AnalogInputTask() itask.create_voltage_channel(analog_input, min_val=0.0, max_val=10.0, terminal=TERMINALEND) itask.configure_timing_sample_clock(rate=samplerate, sample_mode='finite', samples_per_channel=nsamples) # ok that's tee'd up # assume that these are uint8 ddata = np.zeros(nsamples * ndigital, dtype=np.uint8) onarr = np.ones(ndigital, dtype=np.uint8) offarr = np.zeros(ndigital, dtype=np.uint8) ## for interleaved layout
def __init__(self, pulse_duration=0.1, pause_duration=0.2, gusto_ip='192.168.0.1', gusto_port=40175, ni_trigger_in_line='PFI14', ni_trigger_in_task_name='GustometerIn', use_threads=False, test_mode=False): """ Parameters ---------- pulse_duration : float, optional The duration of one stimulation pulse, in seconds. Defaults to 0.1. pause_duration : float, optional The duration of the spray pause between two pulses in seconds. Defaults to 0.2 gusto_ip : string, optional The IP address of the gustometer control computer. Defaults to ``192.168.0.1``. gusto_port : int, optional The port on which the control software on the gustometer control computer is listening for a connection. This should usually not need to be changed. Defaults to ``40175``. ni_trigger_in_line : string, optional The counter input line on the NI board which shall be used to receive the trigger pulse emitted by the gustometer as soon presentation of the requested stimulus has actually started. Defaults to ``Dev1/ctr0``. ni_trigger_in_task_name : string, optional The name to assign to the trigger input task. Defaults to ``GustometerIn``. use_threads : bool, optional Whether a Python thread should be created when `select_stimulus` is called. This thread would then allow non-blocking stimulation. Defaults to ``False``. test_mode : bool, optional If ``True``, the NI board will not actually be initialized or used in any manner. This allows for testing the program logic on a computer without a DAQ card. Defaults to ``False``. """ super(Gustometer, self).__init__(test_mode=test_mode) self._pulse_duration = pulse_duration self._pause_duration = pause_duration self._classfile = None self._gusto_ip = gusto_ip self._gusto_port = gusto_port self._use_threads = use_threads self._thread = None # FIXME add parameter to docs. if not self.test_mode: # Initialize IN trigger (FROM gusto TO computer). # The gustometer will send this trigger as soon as the stimulus # presentation has started. # self._ni_trigger_in_task = nidaqmx.DigitalInputTask( # name=ni_trigger_in_task_name # ) # # self._ni_trigger_in_task.create_channel( # ni_trigger_in_line # ) # # self._ni_trigger_in_task.configure_timing_change_detection( # rising_edge_channel=ni_trigger_in_line, # sample_mode='finite', # samples_per_channel=1 # ) # self._ni_ai_task = nidaqmx.AnalogInputTask( name=ni_trigger_in_task_name) if not self._ni_ai_task.create_voltage_channel( 'Dev1/ai0', min_val=-10, max_val=10): raise IOError('Could not create analog input channel.') if not self._ni_ai_task.configure_timing_sample_clock( rate=192000, sample_mode='finite', samples_per_channel=2): raise IOError('Could not configure analog input sample clock.') if not self._ni_ai_task.configure_trigger_digital_edge_start( ni_trigger_in_line): raise IOError('Could not configure trigger channel.') # self._ni_trigger_in_task.create_channel_count_edges( # ni_trigger_in_line, # edge='rising', # direction='up', # init=0 # ) # Initialize the network connection. self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.settimeout(1) try: self._socket.connect((self._gusto_ip, self._gusto_port)) except socket.error: if not self._test_mode: msg = ('Could not connect to Gustometer computer at %s:%s!' % (self._gusto_ip, self._gusto_port)) raise RuntimeError(msg) else: pass self._mode = 'edit'