11-12-2012 04:33 AM
Hi everyone,
I am doing simple task in Visual C++ and I am using PCI-6221(37 pin).
Basically, I want to send same signal from 'analog input' to 'analog output'
at the same time (almost), to make it real-time application.
Can someone please provide me sample program.
I would appreciate if you could provide me with the good tutorial which explains
step by step everything about programing NI-DAQmx for C/C++.
Best Regards,
Khassan
Solved! Go to Solution.
11-13-2012 11:37 AM
Hi Khassan,
In terms of using NI-DAQmx with text based programming I'd recommend reading through this tutorial, http://www.ni.com/white-paper/5409/en . On the other hand, could you define what you mean by a "Real-Time application"? If you're just talking about having accurate timing on your analog ins and outs this can be accomplished through hardware timing of your DAQmx tasks. If you're talking about programming in LabVIEW Real-Time then that will require hardware with the Real-Time OS. Could you let us know which one you're referring to?
11-13-2012 11:07 PM
To add to Kilometer's post, NI does not offer a solution for C++ with the LabVIEW Real-Time Module. If you prefer text-based programming and need non-Windows real-time functionality, your best bet is to work with LabWindows/CVI , our ANSI C (not C++) IDE, and use the Real-Time Module for that.
Regards,
11-19-2012 05:10 AM
Thank you guys for the fast reply. I just wanted to read signal and output that signal immediately, without changing incoming signal.
By connecting them(input signal from func. generator and output signal from PCI card) to oscilloscope I wanted to see delay.
Regards,
Khassan
11-19-2012 05:11 AM
BTW, I figured out everythink already.
THanks...
11-19-2012 08:18 AM
Hi Khassan,
Thanks for the update. If you could, please post your solution to the thread and mark it as such so people can benefit from this thread in the future.
Regards,
11-20-2012 10:02 PM
This is my code in C++, you can optimize it if it looks too messy. This code reads signal from analog input and outputs it through analog output.
To make this code work additional include directories and library directories must be added from NI.
I hope it helps someone.
#include <stdio.h>
#include <conio.h>
#include "NIDAQmx.h"
#include <math.h>
#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
int main(int argc, char *argv[])
{
int32 error=0;
TaskHandle taskHandleRead=0,taskHandleWrite=0;
int32 read=0;
float64 dataRead[1000];
char errBuffRead[2048]={'\0'};
char errBuffWrite[2048]={'\0'};
bool32 done=0;
int32 written;
DAQmxErrChk (DAQmxCreateTask("",&taskHandleRead));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandleRead,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandleRead,"",100.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,0));
DAQmxErrChk (DAQmxCreateTask("",&taskHandleWrite));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandleWrite,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandleWrite,"ai/SampleClock",100.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (DAQmxStartTask(taskHandleRead));
DAQmxErrChk (DAQmxStartTask(taskHandleWrite));
while( !done && !_kbhit() )
{
DAQmxErrChk (DAQmxReadAnalogF64(taskHandleRead,1,10,DAQmx_Val_GroupByScanNumber,dataRead,1000,&read,NULL));
DAQmxErrChk (DAQmxWriteAnalogF64(taskHandleWrite,read,0,10.0,DAQmx_Val_GroupByChannel,dataRead,&written,NULL));
}
_getch();
Error:
if( DAQmxFailed(error) )
{
DAQmxGetExtendedErrorInfo(errBuffRead,2048);
DAQmxGetExtendedErrorInfo(errBuffWrite,2048);
}
if( taskHandleRead!=0 )
{
DAQmxStopTask(taskHandleRead);
DAQmxClearTask(taskHandleRead);
}
if( taskHandleWrite!=0 )
{
DAQmxStopTask(taskHandleWrite);
DAQmxClearTask(taskHandleWrite);
}
if( DAQmxFailed(error) ){
printf("DAQmx Error: %s\n",errBuffRead);
printf("DAQmx Error: %s\n",errBuffWrite);
}
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}