Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get signal from analog input and send it to analog output (real-time)

Solved!
Go to solution

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

 

0 Kudos
Message 1 of 7
(6,323 Views)

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? 

Miles G.
National Instruments
Staff Applications Engineering Specialist
Message 2 of 7
(6,297 Views)

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,

Regards,
Chris Elliott
x36772
Message 3 of 7
(6,289 Views)

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

 

0 Kudos
Message 4 of 7
(6,256 Views)

BTW, I figured out everythink already. 

 

THanks...

0 Kudos
Message 5 of 7
(6,255 Views)

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,

Regards,
Chris Elliott
x36772
0 Kudos
Message 6 of 7
(6,248 Views)
Solution
Accepted by topic author Khassan

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

 

Message 7 of 7
(6,224 Views)