Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ program to read temperatures from NI cDAQmx-9191

I am trying to write a simple program in C++ that will be able to read temperatures in temperatures from the DAQ, (We are using NI 9213 24-bit Thermocouple Input modules). I have the NIDAQmx.h header file but it will take me a while to read through it just to understand how to simply get the temperature readings to the computer. If there's anyone who has already done this or knows an easy way to go about doing this, any help would be appreciated.

 

Thank you,

 

Tim

0 Kudos
Message 1 of 12
(4,931 Views)
0 Kudos
Message 2 of 12
(4,926 Views)

I don't know if there are specific examples for C++ unless you are referring to Visual Studio C++

I don't have VS C++, but I do have Visual Basic 2010 Express, and NI-DAQmx examples are installed in

C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.0   for Windows 7

 

 

 

0 Kudos
Message 3 of 12
(4,910 Views)

The examples are helpful and I should be able to make the program with the help of them. However, I can't seem to compile these since I am trying to use cygwin g++ compiler. I've tried for hours going through other threads trying to get it to work and I haven't had any luck. Are there any other free IDEs/Compilers I can use to run the code that are supported by NI?

0 Kudos
Message 4 of 12
(4,897 Views)

@TimCast wrote:

The examples are helpful and I should be able to make the program with the help of them. However, I can't seem to compile these since I am trying to use cygwin g++ compiler. I've tried for hours going through other threads trying to get it to work and I haven't had any luck. Are there any other free IDEs/Compilers I can use to run the code that are supported by NI?


Apparently you are unaware of the Microsoft's free version of Visual Studio.

0 Kudos
Message 5 of 12
(4,886 Views)

Alright, I am now in Visual Studio trying to run an example for measuring temperature from a thermocouple (The example is named: Cont Thrmcpl Samples-Int Clk). I tried running it and it returns an error for the unnamed physical channel. I realized that there are a lot of empty strings that need to be filled in and I'm unsure what all of them are and how specific these string have to be.

 

From the main function:
    int32       error=0;
    TaskHandle  taskHandle=0;
    char        errBuff[2048]={'\0'};


    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateAIThrmcplChan(taskHandle,"","",0.0,100.0,DAQmx_Val_DegC,DAQmx_Val_J_Type_TC,DAQmx_Val_BuiltIn,25.0,""));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));

 

What do I need to fill in here? Can you give me examples so I can figure out what to input for my personal case? Is there anything else in this example that I'll need to fill in or know about?

0 Kudos
Message 6 of 12
(4,853 Views)

Hello TimCast,

I would like to show you this link in which you can visualize all the DAQmx useful functions.

http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/daqapimapping/

 

In there, you can find explanation of the syntax and of the parameters. You can probably find this helpful.

Here is another link that can help you further.

http://www.ni.com/tutorial/5409/en/

 

Luis C.

National Instruments

 

 

 

 

0 Kudos
Message 7 of 12
(4,829 Views)

Thank you for your help, I finally was able to get the example running. However, I am not sure where the temperature readings will output to. I figured they would show up on the terminal where it says "Acquiring samples continuiously", but it doesn't seem to be printed there. Where does the temperature readings get saved or printed to?

0 Kudos
Message 8 of 12
(4,810 Views)

Hello TimCast,

I am not sure if I understand what you mean. You need to read the data on the task (using the read function) and that will display the value on the indicator.

If you can, please be a little more specific.

 

Luis C.

National Instruments

0 Kudos
Message 9 of 12
(4,789 Views)

I'll be more specific what I want. I have a many DAQs and several thermocouples on them. I want a program that will print or save to a text file the temperature readings from all the thermocouples on the DAQs. I think I understand how reading from one DAQ and one thermocouple works, but I'm not sure how to add more. Here's a snippet of code from the main function in the example:

 

    int32       error=0;
    TaskHandle  taskHandle=0;
    char        errBuff[2048]={'\0'};

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateAIThrmcplChan(taskHandle,"","",0.0,100.0,DAQmx_Val_DegC,DAQmx_Val_J_Type_TC,DAQmx_Val_BuiltIn,25.0,""));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));

    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
    DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

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

    printf("Acquiring samples continuously. Press Enter to interrupt\n");
    getchar();

 

EveryNCallback is the function that prints out the samples. However I just want to print out the temperature once and then move on to another thermocouple. Any suggestions on how to take this example and make it do this instead? I'm not very comfortable with these functions.

0 Kudos
Message 10 of 12
(4,690 Views)