2013-08-14 4 views
0

C 프로그램을 통해 NI USB-6211에 전압 입력을 읽으려고합니다. 이를 위해 설치된 프로그램과 함께 제공되는 예제 프로그램을 사용해 보았습니다. 아무 소용이 없었습니다. 나는 문서를 보았지만 솔직히 말해서 전혀 도움이되지 않습니다.NI USB 6211 아날로그 전압 입력 읽기

내가 수정 한 코드입니다.

/********************************************************************* 
* 
* ANSI C Example program: 
* Acq-IntClk.c 
* 
* Example Category: 
* AI 
* 
* Description: 
* This example demonstrates how to acquire a finite amount of data 
* using the DAQ device's internal clock. 
* 
* Instructions for Running: 
* 1. Select the physical channel to correspond to where your 
*  signal is input on the DAQ device. 
* 2. Enter the minimum and maximum voltages. 
* Note: For better accuracy try to match the input range to the 
*   expected voltage level of the measured signal. 
* 3. Select the number of samples to acquire. 
* 4. Set the rate of the acquisition. 
* Note: The rate should be AT LEAST twice as fast as the maximum 
*   frequency component of the signal being acquired. 
* 
* Steps: 
* 1. Create a task. 
* 2. Create an analog input voltage channel. 
* 3. Set the rate for the sample clock. Additionally, define the 
*  sample mode to be finite and set the number of samples to be 
*  acquired per channel. 
* 4. Call the Start function to start the acquisition. 
* 5. Read all of the waveform data. 
* 6. Call the Clear Task function to clear the task. 
* 7. Display an error if any. 
* 
* I/O Connections Overview: 
* Make sure your signal input terminal matches the Physical 
* Channel I/O Control. For further connection information, refer 
* to your hardware reference manual. 
* 
*********************************************************************/ 

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

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

int main(void) 
{ 
    int32  error=0; 
    int32  amount; 
    int32  i; 
    TaskHandle taskHandle=0; 
    int32  read; 
    float64  data[1000]; 
    char  errBuff[2048]={'\0'}; 
    char  c = 64; 

    /*********************************************/ 
    // DAQmx Configure Code 
    /*********************************************/ 

    printf("Please enter the amount of voltage checks you wish to run.\n"); 
    //scanf("%d", &amount); 

    while(scanf("%d%c", &amount, &c) !=2) 
    { 
     getchar(); 
     puts("Please enter a number."); 
    } 
    for (i = 0; i < amount; i++) 
    { 
     DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); 
     DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,1.0,10.0,DAQmx_Val_Volts,NULL)); 
     DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000)); 

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

     /*********************************************/ 
     // DAQmx Read Code 
     /*********************************************/ 

     DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL)); 

     printf("Acquired %d points\n",read); 


Error: 
     if(DAQmxFailed(error)) 
      DAQmxGetExtendedErrorInfo(errBuff,2048); 
     if(taskHandle!=0) 
     { 
      /*********************************************/ 
      // DAQmx Stop Code 
      /*********************************************/ 
      DAQmxStopTask(taskHandle); 
      DAQmxClearTask(taskHandle); 
      printf("Updating... "); 
     } 
    } 

    if(i=amount) 
    { 
     printf("End of Program, press the Enter key to quit\n"); 
     getchar();  
     if(DAQmxFailed(error))     
      printf("DAQmx Error: %s\n",errBuff); 
    }  
    return 0; 
} 

모든 코드는이 순간에하고있다 (그것은 ... 입력을 요청 또한 체크인 약간의 오류가와) 나도 그에게 몇 번 번호 1000을 인쇄한다. 나는이 코드에서 올 수 있다고 확신한다 : float64 data[1000];. 누구든지 직접 전압을 읽는 방법에 대한 지식이 있습니까? 그것이 형식화되지 않은 숫자의 긴 문자열 일지라도 (나는 그것을 이해할 수있다). 표시

감사

답변

1

1000DAQmxReadAnalogF64()에 전화에서 두 번째와 일곱 번째 매개 변수에서 비롯됩니다. 두 번째 매개 변수는 각 채널의 샘플 수를 나타냅니다. sevent 매개 변수 (&read)는 실제로 채널당 얼마나 많은 샘플을 가져 왔는지 결과를 저장하는 위치를 알려줍니다. 그래서 당신은 1000을 요구했고 1000을 얻었다.

프로그램이 읽은 데이터를 출력하지 않았다. DAQmxReadAnalogF64()에 대한 호출은 데이터 수집을 수행하고 다섯 번째 매개 변수에 지정된 배열에 저장한다. 귀하의 경우 data).

그건 당신이 같은 것을 사용하여 전압을 출력 할 수 있습니다 전화 후

:

for (int i = 0; i < read; i++) 
{ 
    printf("Data point %d has value %f\n",i, data[i]); 
} 

이 분명히 당신이 원하는 아마 모든 1000 개 값을 출력 것이지만.

NI 라이브러리를 코딩하려는 경우 NI-DAQmx C 참조 도움말에서 기능 및 해당 매개 변수에 대한 설명을 찾아야합니다. 그들은 많은 매뉴얼을 가지고 있으며, 쉽게 찾을 수 있습니다. 예제는 일반적으로 적응하기 쉽습니다.

+0

아, 고맙습니다! 나는 그 참조를 google 할 것이다! 도와 주셔서 감사합니다 tinman :) –

+0

또한 사용자가 지정한 횟수만큼만 인쇄하도록 수정했습니다. 다시 한번 감사드립니다 :) –