当前位置: 首页>>代码示例>>Python>>正文


Python PyDAQmx类代码示例

本文整理汇总了Python中PyDAQmx的典型用法代码示例。如果您正苦于以下问题:Python PyDAQmx类的具体用法?Python PyDAQmx怎么用?Python PyDAQmx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PyDAQmx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_internal_chan_old

    def get_internal_chan_old(self, chan):      
        """
        Modifies example of PyDAQmx from https://pythonhosted.org/PyDAQmx/usage.html#task-object . There was a simpler version that I didn't notice before, now that one is implemented above.
        """
        print('start get chan %s' %chan)
        # Declaration of variable passed by reference
        taskHandle = mx.TaskHandle()
        read = mx.int32()
        data = numpy.zeros((1,), dtype=numpy.float64)

        try:
            # DAQmx Configure Code
            mx.DAQmxCreateTask("",mx.byref(taskHandle))
            mx.DAQmxCreateAIVoltageChan(taskHandle,"Dev1/_%s_vs_aognd" %chan,"",mx.DAQmx_Val_Cfg_Default,-10.0,10.0,mx.DAQmx_Val_Volts,None)
            mx.DAQmxCfgSampClkTiming(taskHandle,"",10000.0,mx.DAQmx_Val_Rising,mx.DAQmx_Val_FiniteSamps,2)

            # DAQmx Start Code
            mx.DAQmxStartTask(taskHandle)

            # DAQmx Read Code
            mx.DAQmxReadAnalogF64(taskHandle,1000,10.0,mx.DAQmx_Val_GroupByChannel,data,1000,mx.byref(read),None)

        except mx.DAQError as err:
            print ("DAQmx Error: %s"%err)
        finally:
            if taskHandle:
                # DAQmx Stop Code
                mx.DAQmxStopTask(taskHandle)
                mx.DAQmxClearTask(taskHandle)
        print('end get chan %s' %chan)

        return float(data[0])
开发者ID:gmf57,项目名称:Nowack_Lab,代码行数:32,代码来源:nidaq.py

示例2: read

    def read(self, name=None, timeout=0.01, num_samples=None):
        """
        Reads data from a given physical channel
        :param name: The name of the channel from which we are going to read the data
        :param timeout: The amount of time, in seconds, to wait for the function to read the sample(s)
                        (-1 for infinite)
        :param num_samples: The number of samples to acquire
        :return: Returns an array with the data read
        """
        if name is None:
            name = self.physical_channels[0]
        if num_samples is None:
            index = self.physical_channels.index(name)
            num_samps_channel = self.n_samples[index]
        else:
            num_samps_channel = num_samples

        # Get task handle
        task = self.tasks[name]
        # Prepare the data to be read
        data = numpy.zeros((num_samps_channel,), dtype=numpy.float64)
        read = PyDAQmx.int32()
        # Start the task
        task.StartTask()
        # Read the data and return it!
        task.ReadAnalogF64(
            num_samps_channel, timeout, GROUP_BY_CHANNEL, data, num_samps_channel, PyDAQmx.byref(read), None
        )
        # Stop the task
        task.StopTask()
        # Return in a list instead of numpy.array
        return data.tolist()
开发者ID:FCLStation,项目名称:PyDAQmx-Interface,代码行数:32,代码来源:daqmxlib.py

示例3: get_voltage_ai

    def get_voltage_ai(self, **kwargs):
        """
        get_voltage_ai(self, **kwargs)
        Usage example:
        get_voltage_ai(self, channel='Dev1/ai6', voltage_limit=10, clock_freq=1e4, sampling_pts=1000, input_mode='diff')
        """

        # Set the default values below
        channel = 'Dev1/ai6'
        voltage_limit = 10
        clock_freq = 1e4
        sampling_pts = 1000
        input_mode = daq.DAQmx_Val_Diff

        # Read input args
        for key, value in kwargs.items():
            if key == 'channel':
                channel = value
            elif key == 'voltage_limit':
                voltage_limit = value
            elif key == 'clock_freq':
                clock_freq = value
            elif key == 'sampling_pts':
                sampling_pts = value
            elif key == 'input_mode':
                if value.lower() == 'diff':
                    input_mode = daq.DAQmx_Val_Diff
                elif value.lower() == 'nrse':
                    input_mode = daq.DAQmx_Val_NRSE
                elif value.lower() == 'rse':
                    input_mode = daq.DAQmx_Val_RSE
                else:
                    raise ValueError('Unrecognized input mode!')

        # The code below is adopted from http://pythonhosted.org/PyDAQmx/usage.html
        sampling_pts = int(sampling_pts)   # force int type for sampling_pts, otherwise will be type error
        analog_input = daq.Task()
        read = daq.int32()
        data = numpy.zeros((sampling_pts,), dtype=numpy.float64)

        recording_time = float(sampling_pts) / clock_freq
        if recording_time <= 5:
            fill_mode = 5
        else:
            fill_mode = recording_time * 1.01
        # The fill_mode here determines the max recording time USB6211 can go

        # DAQmx Configure Code
        #analog_input.CreateAIVoltageChan("Dev1/ai6","",DAQmx_Val_Cfg_Default,-voltage_range,voltage_range,DAQmx_Val_Volts,None)
        analog_input.CreateAIVoltageChan(channel,"",input_mode,-voltage_limit,voltage_limit,daq.DAQmx_Val_Volts,None)
        analog_input.CfgSampClkTiming("",clock_freq,daq.DAQmx_Val_Rising,daq.DAQmx_Val_FiniteSamps, sampling_pts)

        # DAQmx Start Code
        analog_input.StartTask()
        # DAQmx Read Code
        analog_input.ReadAnalogF64(sampling_pts, fill_mode, daq.DAQmx_Val_GroupByChannel,data,sampling_pts, daq.byref(read), None)
        
        print "Acquired %d points" % read.value
        return data
开发者ID:lijunhw,项目名称:instruments,代码行数:59,代码来源:ni.py

示例4: writeValues

 def writeValues(self, chanNames, data):
     DebugLog.log("DAQhardware.writeValue(): chanNames= %s val= %s" % (repr(chanNames), repr(data)))
     
     self.analog_output = None   # ensure the output task is closed
     samplesWritten = daqmx.int32()
     analog_output = daqmx.Task()
     data = np.vstack((data, data))
     data = data.transpose()
     data = np.require(data, np.double, ['C', 'W'])
     numSamples = 2
     outputRate = 1000
     
     for chanName in chanNames:
         analog_output.CreateAOVoltageChan(chanName,"",-10.0,10.0, daqmx.DAQmx_Val_Volts, None)
     analog_output.CfgSampClkTiming("",outputRate, daqmx.DAQmx_Val_Rising, daqmx.DAQmx_Val_FiniteSamps, numSamples)
     analog_output.WriteAnalogF64(numSampsPerChan=numSamples, autoStart=True,timeout=1.0, dataLayout=daqmx.DAQmx_Val_GroupByChannel, writeArray=data, reserved=None, sampsPerChanWritten=byref(samplesWritten))
     DebugLog.log("DAQhardware.setupAnalogOutput(): Wrote %d samples" % samplesWritten.value)
     
     # wait until write is completeled
     isDone = False
     isDoneP = daqmx.c_ulong()
     while not isDone:
         err = analog_output.IsTaskDone(byref(isDoneP))
         isDone = isDoneP.value != 0
             
     analog_output = None
开发者ID:skymini00,项目名称:PyVib,代码行数:26,代码来源:DAQHardware.py

示例5: read_and_clean

    def read_and_clean(self):
        """
        This should be called after start().

        Collects data from the running task, cleans up, then returns the data.
        """

        # Fetch the data
        debug("fetch data")
        array_size = self["ai_samples"]*len(self["ai_channels"])

        # create the array in which to store the data
        data       = _n.zeros(array_size, dtype=_n.float64)
        bytes_read = _mx.int32()

        # read the data
        debug("_handle", self._handle)
        _mx.DAQmxReadAnalogF64(
            self._handle,                    # handle to the task
            self["ai_samples"],              # number of samples per channel (-1 => Read ALL in Buffer)
            self["ai_timeout"],              # timeout (sec)
            _mx.DAQmx_Val_GroupByChannel,    # how to fill the data array
            data,                            # array to fill
            array_size,                      # array size (samples)
            _mx.byref(bytes_read),           # samples per channel actually read
            None)                            # "reserved"

        # clean up the task
        self.clean()

        #Organize the data
        data =  _n.split(data, len(self["ai_channels"]))
        return data
开发者ID:julian-wolf,项目名称:spinmob,代码行数:33,代码来源:__init__.py

示例6: analog_task

def analog_task(settings):
    """

    """
    try:
        samples_per_channel = settings['samples_per_channel']
        number_of_channels = settings['number_of_channels_ai']

        # Analog dev
        print("\nCreating analog task %s." % settings['name'])
        sys.stdout.flush()

        # settings
        task = pydaq.Task()
        task.CreateAIVoltageChan(
            settings['analog_input'].encode('utf-8'),
            **settings['parameters_create_ai']
        )
        task.CfgSampClkTiming(
            **settings['parameters_sample_clock_time_ai'])

        if 'parameters_export_signal' in settings:
            for sig in settings['parameters_export_signal']:
                task.ExportSignal(**sig)

        if 'parameters_start_trigger' in settings:
            task.CfgDigEdgeStartTrig(**settings['parameters_start_trigger'])

        total_samples = pydaq.int32()
        data_size = samples_per_channel * number_of_channels

        print("\nStarting analog task %s." % settings['name'])

        task.StartTask()

        total_samples.value = 0

        run = True

        while run:
            run = yield

            data = np.zeros((data_size,), dtype=np.float64)

            task.ReadAnalogF64(
                samples_per_channel,
                10.0,
                pydaq.DAQmx_Val_GroupByChannel,
                data,
                data_size,
                pydaq.byref(total_samples),
                None
            )
            yield data

    except:
        pass

    task.StopTask()
    task.ClearTask()
开发者ID:gitter-badger,项目名称:pywim,代码行数:60,代码来源:ni.py

示例7: digital_task

def digital_task(semaphore, semaphore_dev, counter, samples_queue, settings):
    """
    Digital
    Need to start the dio task first!

    """
    try:
        print("\nCreating digital task %s." % settings['name'])
        sys.stdout.flush()

        # settings
        samples_per_channel = settings['samples_per_channel']
        number_of_channels = settings['number_of_channels_di']

        total_samps = pydaq.int32()
        total_bytes = pydaq.int32()

        data_size = samples_per_channel * number_of_channels

        task = pydaq.Task()
        task.CreateDIChan(
            settings['digital_input'].encode('utf-8'),
            b'', pydaq.DAQmx_Val_ChanPerLine
        )
        task.CfgSampClkTiming(
            **settings['parameters_sample_clock_time_di']
        )

        print("\nStarting digital task %s." % settings['name'])
        sys.stdout.flush()

        task.StartTask()

        total_samps.value = 0
        total_bytes.value = 0

        run = True

        while run:
            run = yield

            data = np.zeros((data_size,), dtype=np.uint8 )

            task.ReadDigitalLines(
                samples_per_channel,  # numSampsPerChan
                10.0,  # timeout
                pydaq.DAQmx_Val_GroupByChannel,  # fillMode
                data,  # readArray
                data_size,  # arraySizeInBytes
                pydaq.byref(total_samps),  # sampsPerChanRead
                pydaq.byref(total_bytes),  # numBytesPerChan
                None  # reserved
            )
            yield data
    except:
        pass

    task.StopTask()
    task.ClearTask()
开发者ID:gitter-badger,项目名称:pywim,代码行数:59,代码来源:ni.py

示例8: send_signal

 def send_signal(self):
     read = Daq.int32()
     self.StartTask()
     self.WriteDigitalU32(1, 0, 10.0, Daq.DAQmx_Val_GroupByChannel,
                          self.strobeOn, Daq.byref(read), None)
     self.WriteDigitalU32(1, 0, 10.0, Daq.DAQmx_Val_GroupByChannel,
                          self.strobeOff, Daq.byref(read), None)
     self.StopTask()
开发者ID:codedragon,项目名称:pydaq,代码行数:8,代码来源:pydaq.py

示例9: send_signal

 def send_signal(self, event):
     #print event
     read = Daq.int32()
     self.encode[0] = event
     #print self.encode
     self.StartTask()
     self.WriteDigitalU32(10000, 0, 5.0, Daq.DAQmx_Val_GroupByChannel,
                          self.encode, Daq.byref(read), None)
     self.StopTask()
开发者ID:XavierDR,项目名称:OCT,代码行数:9,代码来源:digital_output_OOP.py

示例10: wait_and_clean

    def wait_and_clean(self):
        """
        This should be called after start().

        Waits for the task to finish and then cleans up.
        """

        #Wait for the task to finish
        complete = _mx.bool32()
        while not (complete): _mx.DAQmxGetTaskComplete(self._handle, _mx.byref(complete))
        self.clean()
开发者ID:julian-wolf,项目名称:spinmob,代码行数:11,代码来源:__init__.py

示例11: get_sample_rate

    def get_sample_rate(self):
        """ Get the sample rate of the pulse generator hardware

        @return float: The current sample rate of the device (in Hz)

        Do not return a saved sample rate from an attribute, but instead retrieve the current
        sample rate directly from the device.
        """
        rate = daq.float64()
        daq.DAQmxGetSampClkRate(self.pulser_task, daq.byref(rate))
        return rate.value
开发者ID:a-stark,项目名称:qudi,代码行数:11,代码来源:national_instruments_pulser.py

示例12: ReadTask

def ReadTask(task, num):
    read = PDm.int32()
    data = (np.zeros((num,), dtype=np.float64))
    task.ReadAnalogF64(num,
                       1000.0,
                       PDm.DAQmx_Val_GroupByChannel,
                       data,
                       num,
                       PDm.byref(read),
                       None)
    return data[:read.value]
开发者ID:ijknabla,项目名称:PID,代码行数:11,代码来源:mytask.py

示例13: EveryNCallback

 def EveryNCallback(self):
     #print 'callback'
     read = Daq.int32()
     #print 'read', read
     self.ReadAnalogF64(1, 10.0, Daq.DAQmx_Val_GroupByScanNumber,
                        self.EOGData, 2, Daq.byref(read), None)
     if self.event:
         self.event(self.EOGData)
     #print 'x,y', self.EOGData[0], self.EOGData[1]
     #print 'okay'
     return 0  # the function should return an integer
开发者ID:codedragon,项目名称:pydaq,代码行数:11,代码来源:pydaq.py

示例14: __init__

    def __init__(self, device='Dev1', ports=['ao0'], read_buffer_size=10, timeout=5., sample_rate=400., AI_mode=pydaq.DAQmx_Val_Diff, save_buffer_size=8000, analog_minmax=(-10,10)):
        
        # DAQ properties
        pydaq.Task.__init__(self)
        self.device = device
        self.port_names = ports
        self.ports = ['/'.join([self.device,port]) for port in self.port_names]
        self.timeout = timeout
        self.minn,self.maxx = analog_minmax
        self.sample_rate = sample_rate
        self.AI_mode = AI_mode

        # params & data
        self.read_success = pydaq.int32()
        self.read_buffer_size = read_buffer_size
        self.effective_buffer_size = self.read_buffer_size * len(self.ports)
        self.read_data = np.zeros(self.effective_buffer_size) # memory for DAQmx to write into on read callbacks
        self.last_ts = None
        self.data_q = mp.Queue()

        # Setup task
        try:
            self.CreateAIVoltageChan(','.join(self.ports), '', self.AI_mode, self.minn, self.maxx, pydaq.DAQmx_Val_Volts, None)
            self.CfgSampClkTiming('', self.sample_rate, pydaq.DAQmx_Val_Rising, pydaq.DAQmx_Val_ContSamps, self.read_buffer_size)
            self.AutoRegisterEveryNSamplesEvent(pydaq.DAQmx_Val_Acquired_Into_Buffer, self.read_buffer_size, 0)
            self.AutoRegisterDoneEvent(0)
    
            self.StartTask()
        except:
            warnings.warn("DAQ task did not successfully initialize")
            raise
开发者ID:bensondaled,项目名称:eyeblink,代码行数:31,代码来源:daq.py

示例15: every_n

 def every_n(self, taskHandle, everyNsamplesEventType, nSamples, callbackData_ptr):
     callbackdata = get_callbackdata_from_id(callbackData_ptr)
     read = pydaq.int32()
     self.read_data[:] = 0
     pydaq.DAQmxReadAnalogF64(taskHandle,self.read_buffer_size,self.timeout,pydaq.DAQmx_Val_GroupByScanNumber,self.read_data,self.read_buffer_size,pydaq.byref(read),None)
     callbackdata.extend(self.read_data.tolist())
     self.new_data = True
     return 0
开发者ID:bensondaled,项目名称:puffs,代码行数:8,代码来源:daq.py


注:本文中的PyDAQmx类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。