0

I would like to write nidaqmx provided by ni in language c. However, there is a problem with quoting the header file. I wonder if this is the right way to write in the contents after #include. And when it is executed in this way, there are no other errors, but there are several errors called "link2019. I want to know if the header file citation failed or if the header file and source file configuration are wrong. I may have lacked foundation because I just started learning C language.

#include <stdio.h>

#include "C:\Program Files (x86)\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h"



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



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

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
    DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.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));
[enter image description here](https://i.stack.imgur.com/DhsFo.png)
    /*********************************************/
    // DAQmx Read Code
    /*********************************************/
    DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 1000, &read, NULL));

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

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;
}
  • A header file usually only contains structures, macros, function declarations and similar. It typically doesn't contain the actual definition (implementation) of the functions you use. You need to *link* with the actual library file. – Some programmer dude Jul 28 '23 at 08:00

0 Answers0