Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the scanf function in c++ and DAQmx fucntions

I just start using NIDAQmx with C functions.
I have a problem using scanf function and after the NIDAQmx functions.
Whithout the scanf function the program runs well but inserting this function is not running??
 
The program is like that:
 

#include

<stdio.h>

#include

<NIDAQmx.h>

#define

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

 

int

main(void)

{

int32 error=0,k=0;

TaskHandle taskHandle=0;

TaskHandle taskHandleCtr=0;

uInt64 sampsPerChanToAcquire=50;

int32 numSampsPerChan=50;

int j;

float64 rate=100;

uInt32 data[8]={1,0,1,0,1,0,1,0};

char errBuff[2048]={'\0'};

/*********************************************/

// DAQmx Configure Code

/*********************************************/

DAQmxErrChk (DAQmxCreateTask(

"",&taskHandle));

DAQmxErrChk (DAQmxCreateTask(

"",&taskHandleCtr));

rate=40;

numSampsPerChan=60;

printf(

"digueu:\n");

scanf (

"%d",&j);

k=j;

DAQmxErrChk (DAQmxCreateDOChan(taskHandle,

"Dev1/port0","",DAQmx_Val_ChanForAllLines));

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,

"/Dev1/Ctr0InternalOutput",1,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000));

DAQmxErrChk (DAQmxCreateCOPulseChanFreq(taskHandleCtr,

"Dev1/ctr0","",DAQmx_Val_Hz,DAQmx_Val_Low,0,rate,0.5));

DAQmxErrChk (DAQmxCfgImplicitTiming (taskHandleCtr,DAQmx_Val_FiniteSamps,500));

/*********************************************/

// DAQmx Write Code

/*********************************************/

DAQmxErrChk (DAQmxWriteDigitalU32(taskHandle,k,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

/*********************************************/

// DAQmx Start Code

/*********************************************/

DAQmxErrChk (DAQmxStartTask(taskHandle));

DAQmxErrChk (DAQmxStartTask(taskHandleCtr));

 

}

0 Kudos
Message 1 of 3
(2,784 Views)

Hi Novice 22

what is exactly the problem that you have when you run the program with scanf? does the function not work properly? What is the error code?



What is the environment where you are programming? And what is the type of C that you are using? ANSI C, C, C++, Visual C...

The code is right so I suppose that you forgot link the library or the path is wrong.

0 Kudos
Message 2 of 3
(2,746 Views)

the problem is with the function scanf. When i used it, i can not write digital lines.

I have no signal on port when i use scanf

Environment: VC++ 2005, programming in ansi c.

Thank you,

 

Novice

0 Kudos
Message 3 of 3
(2,728 Views)