Search code examples
pythonnidaqmx

NI 9207 with nidaqmx with Python, how do I configure sample rates and achieve continuous sampling?


I have worked with nidaqmx in the past. I worked with an NI 9229 (using a usb cDAQ-9171 single slot chassis) which is capable of simultaneous sampling. I could set the sample rate and also continuously sample the buffer with my tkinter application.

I am now working with a NI 9207 (using a usb cDAQ-9171 single slot chassis). I now have 16 channels to sample, and I now have a CONVERT CLOCK to work with as well which I have learned is different from the normal clocks that I am used to adjusting the sample rates on. The usual command I use is

self.task.timing.cfg_samp_clk_timing(sampleRate,source = '/'+self.daqName+'/ai/SampleClock', sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,samps_per_chan=self.numberOfSamples)

I get an error as follows:

DaqReadError: Specified route cannot be satisfied, because the hardware does not support it.
Property: DAQmx_SampClk_Src
Property: DAQmx_SampClk_ActiveEdge
Source Device: cDAQ6Mod1
Source Terminal: ai/ConvertClock

Task Name: _unnamedTask<3B>

Status Code: -89136

I have scrounged for examples and referred also the NI-DAQmx Python Documentation

I have had success in using basic task.read() commands but this frankly doesn't offer the flexibility that I need.

TLDR; I don't know how to change the sample rate and to setup continuous acquisition with an NI card that has a CONVERT CLOCK.


Solution

  • I didn't receive any error on the convert clock when running the following code with NI-9207. Can you post your full code?

    import numpy
    from datetime import datetime, timedelta
    
    import nidaqmx
    from nidaqmx.constants import AcquisitionType
    from nidaqmx.stream_readers import AnalogMultiChannelReader
    
    with nidaqmx.Task() as task:
        # Timing Settings
        sample_rate = 10
        dt = 1/sample_rate
        number_of_samples_per_channel = 10
    
    chan = task.ai_channels.add_ai_voltage_chan("Dev1/ai0:3")
    channels_name = task.channel_names
    number_of_channels = task.number_of_channels
    task.timing.cfg_samp_clk_timing(
    sample_rate, sample_mode=AcquisitionType.CONTINUOUS)
    
    stream = AnalogMultiChannelReader(task.in_stream)
    dataStream = numpy.zeros((number_of_channels, number_of_samples_per_channel), dtype=numpy.float64)
    dataPrint = numpy.zeros((number_of_samples_per_channel, number_of_channels), dtype=numpy.float64)
    
    task.start()
    # Python does not support t0 from the first sample of waveform, use current start time as t0 instead
    t0 = datetime.now()
    
    try:
        print("Press Ctrl+C to stop")
        print(f'Voltage Data:')
        header = 'Time\t\t\t\t'+'\t'.join([x for x in channels_name])
        print(header)
        while True:
            stream.read_many_sample(dataStream, number_of_samples_per_channel)
            dataPrint = numpy.transpose(dataStream)
            
            output = ''
            for i in range(0,dataPrint.shape[0]):
                output += str(t0)+'\t'+'\t\t'.join(['%0.3f' %x for x in dataPrint[i,:]])+'\n'
                t0 += timedelta(seconds=dt)
            print(output)
    
    except KeyboardInterrupt:
        pass
    
    task.stop()