def __init__(self, dev, channels): self.dev = dev self.nrchans = int(channels.split(":")[1]) - int(channels.split(":")[0]) + 1 self.output_str = dev+"/port0/line" + str(channels) self.dotask = nidaqmx.DigitalOutputTask() self.dotask.create_channel(self.output_str, name = "line" +str(channels))
def _config_write(self, channel, **kwargs): """ Configure a channel or group of channels as a boolean output Parameters ---------- channel: string a channel or group of channels that will all be written to at the same time Returns ------- True on successful configuration """ # TODO: test multiple channels. What format should channels be in? logger.debug("Configuring digital output on channel(s) %s" % str(channel)) task = nidaqmx.DigitalOutputTask() task.create_channel(channel) task.configure_timing_sample_clock(source=self.clock_channel, rate=self.samplerate) task.set_buffer_size(0) self.tasks[channel] = task
import numpy as np import nidaqmx nsamples = 1000 samplerate = 1000 adata = 9.95*np.sin(np.arange(nsamples,dtype=np.float64)*2*np.pi/nsamples) atask = nidaqmx.AnalogOutputTask() atask.create_voltage_channel('Dev1/ao0', min_val=-10.0,max_val=10.0) atask.configure_timing_sample_clock(rate=samplerate,sample_mode='finite', samples_per_channel=1000) atask.write(adata, auto_start=False) # ok that's tee'd up ddata = np.zeros(nsamples, dtype=np.uint8) ddata[0:nsamples:5]=1 dotask = nidaqmx.DigitalOutputTask() dotask.create_channel('Dev1/port0/line0', name='line0') #print("dotask info:", dotask.get_info_str(True)) print("atask info:", atask.get_info_str()) # note must use r'ao/SampleClock' (can't prefix with /Dev1/ dotask.configure_timing_sample_clock(source=r'ao/SampleClock',rate=1000,sample_mode='finite',samples_per_channel=1000) dotask.write(ddata, auto_start=False) dotask.start() atask.start() print("press return to end") c =input()
def __init__(self, ni_lines='Dev1/PFI2:9', ni_start_trigger_line=None, ni_task_name='Triggers', use_threads=False, test_mode=False): """ Parameters ---------- ni_lines : string, optional The lines of the NI board to use as output channel. Defaults to ``Dev1/PFI2:9``. ni_start_trigger_line : str or None, optional If specified, start the generation only after a start trigger (high voltage) on this digital line has been received. If `None`, no external trigger is required. ni_task_name : string, optional The name of the NI DAQ task to create. Defaults to ``Triggers``. 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(Trigger, self).__init__(test_mode=test_mode) if not self.test_mode: self._ni_task = nidaqmx.DigitalOutputTask(name=ni_task_name) # Add the trigger channels. if not self._ni_task.create_channel(ni_lines): raise IOError('Could not create digital output task.') self._ni_task_number_of_channels = \ self._ni_task.get_number_of_channels() # 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.') if ni_start_trigger_line is not None: if not self._ni_task.configure_trigger_digital_edge_start( ni_start_trigger_line): raise IOError('Could not configure trigger channel.') # Data generation 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 digital output task.') else: self._ni_task_number_of_channels = 8 self._use_threads = use_threads self._thread = None
def __init__(self, ni_lines='Dev1/port0/line0:7', ni_trigger_line=None, ni_task_name='Olfactometer', use_threads=True, test_mode=False): """ Parameters ---------- ni_lines : string, optional The lines of the NI board to use as output channel. Defaults to ``Dev1/line0:7``. ni_trigger_line : string, optional A line on which to generate an additional trigger pulse as the olfactometer stimulation is initiated. This can be used to start the acquisition of PID data, for example. ni_task_name : string, optional The name of the NI DAQ task to create. Defaults to ``Olfactometer``. 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 ``True``. 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(Olfactometer, self).__init__(test_mode=test_mode) if not self.test_mode: self._ni_task = nidaqmx.DigitalOutputTask(name=ni_task_name) # Add the stimulation channels. if not self._ni_task.create_channel(ni_lines): raise IOError('Could not create digital output task.') self._ni_task_number_of_channels = \ self._ni_task.get_number_of_channels() # Add the trigger channel, if any. if ni_trigger_line is None: self._ni_task_number_of_trigger_channels = 0 else: if not self._ni_task.create_channel(ni_trigger_line): raise IOError('Could not create digital output task.') # To get the total number of trigger channels, we subtract # the number of channels BEFORE adding the trigger channels # from the number of channels AFTER adding the trigger # channels. self._ni_task_number_of_trigger_channels = \ self._ni_task.get_number_of_channels() - \ self._ni_task_number_of_channels if not self._ni_task.start(): raise IOError('Could not start digital output task.') else: self._ni_task_number_of_channels = 8 self._ni_task_number_of_trigger_channels = 1 self._use_threads = use_threads self._thread = None
def __init__(self, dev): self.dev = dev self.output_str = dev+"/port0/line5:7" self.dotask = nidaqmx.DigitalOutputTask() self.dotask.create_channel(self.output_str)