본문 바로가기
IT-개발,DB

[개발/NI] NI DAQ 에서 Digital 신호 전송시 Timing 설정

by SB리치퍼슨 2012. 12. 3.

NI DAQ 에서 Digital 신호 전송시 Timing 설정



아래의 예제는 NI DAQ에서 제공하는 C 예제이다.

Digital Output 신호를 전송하기 위한 예제인데

여기에서 

DAQmxCreateDOChan()

//...

DAQmxWriteDigitalLines() 


의 두 함수를 사용하는데 있어서. 

DAQ 디바이스에서 DO신호처리시에는 sample에 대한 timeout clock을 필요로 하지 않고

on demand 형식으로 전송하고 있다.


만약 DAQmxCreateDOChan()함수를 사용하여 아래와 같은 에러가 발생하였다면


DAQmx Error: Requested value is not a supported value for this property. The property value may be invalide because it conflicts with another property.

Property: DAQmx_SampTimingType

Requested Valeu: DAQmx_Val_SampClk

You Can Select: DAQmx_Val_OnDemand

 

Task Name: _unnamedTask<0>

 

Status Code: -200077



WriteDigChan.c 소스를 참조하자.

아, 그리고 한가지더... starttask는 autostart로 옵션을 줘야한다는 것을 잊지 말자.





/*********************************************************************

*

* ANSI C Example program:

*    WriteDigChan.c

*

* Example Category:

*    DO

*

* Description:

*    This example demonstrates how to write values to a digital

*    output channel.

*

* Instructions for Running:

*    1. Select the digital lines on the DAQ device to be written.

*    2. Select a value to write.

*    Note: The array is sized for 8 lines, if using a different

*          amount of lines, change the number of elements in the

*          array to equal the number of lines chosen.

*

* Steps:

*    1. Create a task.

*    2. Create a Digital Output channel. Use one channel for all

*       lines.

*    3. Call the Start function to start the task.

*    4. Write the digital Boolean array data. This write function

*       writes a single sample of digital data on demand, so no

*       timeout is necessary.

*    5. Call the Clear Task function to clear the Task.

*    6. Display an error if any.

*

* I/O Connections Overview:

*    Make sure your signal output terminals match the Lines I/O

*    Control. In this case wire the item to receive the signal to the

*    first eight digital lines on your DAQ Device.

*

*********************************************************************/


#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;

}


반응형

댓글