0

I am trying to drive 4 independent channels using the python nidaqmx module and the NI X-series 6341 (PN: 781438-01). I have 2 analogue outputs and two digital outputs and I would like all these streams independent of each other. For some reason when I execute the code only my 2 analogue outs and digital out on line 0 fire. I do not see the digital stream on line 1. Does anyone know what may be going on here? I've tried it with another box and get the same behaviour so I don't think its hardware related. Here is the code:

import nidaqmx
from numpy import array
from nidaqmx import stream_writers
import numpy as np
from tkinter import filedialog
from numpy import genfromtxt
import pandas as pd
from nidaqmx.constants import LineGrouping


Devs = []
system = nidaqmx.system.System.local()
print(system.driver_version)
for device in system.devices:
    dev = str(device).split('=')[1].split(')')[0]
    Devs.append(dev)
    print(device)
    print(dev)


def detectDelimiter(csvFile):
    with open(csvFile, 'r') as myCsvfile:
        header=myCsvfile.readline()
        if header.find(";")!=-1:
            return ";"
        if header.find(",")!=-1:
            return ","
        if header.find("\t")!=-1:
            return "\t"

My_Data = []
My_Data_unscaled = []

def load_data():
   
    file_path = filedialog.askopenfilename()
    delim = detectDelimiter(file_path)
    my_data = genfromtxt(file_path, delimiter=delim)
    if len (My_Data) > 0 :
        print('Deleting Data in the buffer...')
        My_Data.clear()
        My_Data.append(my_data)
        My_Data_unscaled.append(my_data)
    else:
        #original_data = my_data
        #My_Data = []
        My_Data.append(my_data)
        My_Data_unscaled.append(my_data)

        
load_data()
look = My_Data[0]
e_dataframe = pd.DataFrame(look)
v_step = 20/2**16

e_dataframe[0] = e_dataframe[0]*v_step
e_dataframe[1] = e_dataframe[1]*v_step

samples_new = [e_dataframe[1].T,e_dataframe[0].T]
samples_new = array(samples_new)



dig_samples_new = [e_dataframe[2].T,e_dataframe[2].T]
dig_samples_new = array(dig_samples_new)
dig_samples_new[0,0] = 1
dig_samples_new[0,0] = 1
dig_samples_new[1,0] = 1

def fire_galvos(dev,rate,dig_las):
    #define channels
    channel1 = dev +'/' + 'ao0' # laser trigger
    channel2 = dev + '/' + 'ao1'  # this is the auxillary trigger signal   
    channel3 = dev + '/line0'
    channel4 = dev + '/line1'
    
    #define clock
    sample_clock = '/'+dev+'/ao/SampleClock'
    
    with nidaqmx.Task() as analog_output, nidaqmx.Task() as digital_output:
       
        dig_las = np.uint32(dig_las)
        
        #add channels
        analog_output.ao_channels.add_ao_voltage_chan(channel1,'mychannel1',-10,10)
        analog_output.ao_channels.add_ao_voltage_chan(channel2,'mychannel2',-10,10)
        digital_output.do_channels.add_do_chan(channel3, 'mychannel3')
        digital_output.do_channels.add_do_chan(channel4, 'mychannel4')
        #digital_output.do_channels.add_do_chan(channel4, 'mychannel4',line_grouping=LineGrouping.CHAN_PER_LINE)
        #digital_output.ao_load_impedance = 50
        
        #define clock timings
        analog_output.timing.cfg_samp_clk_timing(rate=rate, sample_mode=nidaqmx.constants.AcquisitionType.FINITE, samps_per_chan = len(samples_new[0]))
        digital_output.timing.cfg_samp_clk_timing(rate=rate, source = sample_clock, sample_mode=nidaqmx.constants.AcquisitionType.FINITE, samps_per_chan=len(dig_samples_new[0])) #source=sample_clock,
        
        #writing commands
        writer_ana = stream_writers.AnalogMultiChannelWriter(analog_output.out_stream, auto_start=False)
        writer_dig = stream_writers.DigitalMultiChannelWriter(digital_output.out_stream,auto_start=False)
        #writer_dig = stream_writers.DigitalSingleChannelWriter(digital_output.out_stream,auto_start=False)
        writer_ana.write_many_sample(samples_new)
        writer_dig.write_many_sample_port_uint32(dig_las)
        
        
        digital_output.start()
        analog_output.start()
        
        digital_output.wait_until_done(timeout=60)
        analog_output.wait_until_done(timeout=60)
        

fire_galvos(dev,3000,dig_samples_new)```

0 Answers0