Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Interleave samples: Two analog output (arrays with different lengths)

Solved!
Go to solution
CHAN                   AOCHANNEL1       AOCHANNEL2       AOCHANNEL1           AOCHANNEL2       .............and so on

SAMP                   * * * * *           *              * * * * *              *           .............and so on

Hi Guys, how would I go about interleaving two arrays of different lenghts in a two channel analog output? 

 

In the above illustration, for instance, I would like to write 5 values in channel 1 followed by a single value channel 2 and so on.. 

 

I am using the DAQmx library commands to achieve this (not LabView). 

 

I am able to write single values each time a task is opened with no issues, I was wondering if I can interleave the arrays so that the values are buffered and the tasks are completed with greater haste.

 

warm regards,

 

Ravi

0 Kudos
Message 1 of 5
(4,048 Views)

after some thought it feels like the best approach wil be to repeat the values of channel 2, the same number of times as channel 1, so that the arrays are made equal. Is this the only viable approach?

 

thanks,

 

Ravi

0 Kudos
Message 2 of 5
(4,030 Views)

@Ravi_S wrote:

after some thought it feels like the best approach wil be to repeat the values of channel 2, the same number of times as channel 1, so that the arrays are made equal. Is this the only viable approach?


That is exactly what I was going to tell you to do.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 5
(4,010 Views)

Would you consider this a proper sequence of command execution? 

 

CREATING TASK 1
CREATING ANALOG_VO Channel 1
CONFIG. TIMING FOR ANALOG_VO Channel 1

CREATING TASK 2
CREATING ANALOG_VO Channel 2
CONFIG. TIMING FOR ANALOG_VO Channel 2

WRITE VALUES TO CHANNEL 1
WRITE VALUES TO CHANNEL 2

START TASK 1
START TASK 2

 

    DAQmxCreateTask("",byref(taskHandle1))
    DAQmxCreateAOVoltageChan(taskHandle1,"DAQ/ao0","",-9.0,9.0,DAQmx_Val_Volts,None)
    DAQmxCfgSampClkTiming(taskHandle1,"",SAMPLING_RATE,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,SAMPLE_SIZE_WX)
    

    DAQmxCreateTask("",byref(taskHandle2))
    DAQmxCreateAOVoltageChan(taskHandle2,"DAQ/ao1","",-9.0,9.0,DAQmx_Val_Volts,None)    
    DAQmxCfgSampClkTiming(taskHandle2,"",SAMPLING_RATE,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,SAMPLE_SIZE_WX)
        
    # DAQmx Write Voltage Values
    DAQmxWriteAnalogF64(taskHandle1,SAMPLE_SIZE_WX,0,2.0,DAQmx_Val_GroupByScanNumber,Voltage_X,None,None)
    #time.sleep(5)
    DAQmxWriteAnalogF64(taskHandle2,SAMPLE_SIZE_WY,0,2.0,DAQmx_Val_GroupByScanNumber,Voltage_Y_Ext,None,None)
    #time.sleep(5)
    
    # DAQmx Start Code
    DAQmxStartTask(taskHandle1)   
    DAQmxStartTask(taskHandle2)    

 At the execution of highlighted code (the Writing to the second channel) the following error is issued: 

PyDAQmx.DAQmxFunctions.DAQError: The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<1EB>

Do I have to increase the buffer size? 

 

 

0 Kudos
Message 4 of 5
(3,992 Views)
Solution
Accepted by topic author Ravi_S

objective achieved: I made the following changes:

 

 

 

 

CREATING TASK 1
CREATING ANALOG_VO Channel 1 & Channel 2 in TASK 1
CONFIG. TIMING FOR TASK 1

CREATED VOLTAGE ARRAY with Pre-interleaved SAMPLES

WROTE VALUES TO TASK 1

STARTED TASK 1
DAQmxCreateTask("",byref(taskHandle1)) 
DAQmxCreateAOVoltageChan(taskHandle1,"DAQ/ao0:ao1","",-9.0,9.0,DAQmx_Val_Volts,None)
DAQmxCfgSampClkTiming(taskHandle1,"",SAMPLING_RATE,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,2*SAMPLE_SIZE_WX)

DAQmxWriteAnalogF64(taskHandle1,2*SAMPLE_SIZE_WX,0,2.0,DAQmx_Val_GroupByScanNumber,Voltage_Interleaved,None,None)
DAQmxStartTask(taskHandle1)

 

0 Kudos
Message 5 of 5
(3,983 Views)