Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

how to input data array in WriteDigChan example

I am trying to modify the WriteDigChan.c example provided under

 

 C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Generate Values\Write Dig Chan

 

In that example the data array is defined in the program.  How can I change the code such that the data array is an input, so I could call

 

WriteDigChan( data ),  as opposed to what it is now, I just call the compiled program WriteDigChan

 

Ultimately, what I want is the input array, data, to not be 8 by 1,  but rather 8 by 1x10^6, load it to buffer, and output it.  (Using PCI-6534) 

 

the code is below: 

 
#include <stdio.h>
#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int main(void)
{
    int32       error=0;
    TaskHandle  taskHandle=0;
    uInt8       data[8]={0,1,0,1,1,1,1,1};
    char        errBuff[2048]={'\0'};

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/port0/line0:7","",DAQmx_Val_ChanForAllLines));

    /*********************************************/
    // DAQmx Start Code
    /*********************************************/
    DAQmxErrChk (DAQmxStartTask(taskHandle));

    /*********************************************/
    // DAQmx Write Code
    /*********************************************/
    DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

Error:
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmx Error: %s\n",errBuff);
    printf("End of program, press Enter key to quit\n");
    getchar();
    return 0;
}

0 Kudos
Message 1 of 2
(3,103 Views)
Hello ljohn100,

For what you want to do this is not the example to start with. You should be looking at the Cont Write Dig Port-Ext Clk example found by going to Start»All Programs»National Instruments»NI-DAQ»Text-based code»ANSI C Examples. This will get you to all of the ANSI C shipping examples provided by National Instruments. From here you need to go to Digital\Generate Values\Cont Write Dig Port-Ext Clk.

From here you only need to modify the example so that it can take in whatever kind of input, be it a command line argument/text file or a reference to an array from another function.

Regards,
Dan King

0 Kudos
Message 2 of 2
(3,087 Views)