Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

DAGmx functions make bug a programme in C\C++

Hello,

 

I'm using a 6602 DAQ device. I want to make an edge counter in C\C++ (compilate with gcc on windows) but I've got strange behavior :

 

Here is a part of test source code:

 

// DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI38",3e7,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);

i=0;

// DAQmxErrChk (DAQmxReadCounterU32(taskHandle,-1,-1,data,1000,&num,NULL));

while(i<=3)

{

cout <<
"i value is " << i << endl;

i++;

}

 

 

gives

 

Data acquisition ready to start

i value is 0

i value is 1

i value is 2

i value is 3

End of program, press enter to quit

 

If I uncomment line // DAQmxErrChk (DAQmxReadCounterU32(taskHandle,-1,-1,data,1000,&num,NULL)); or

// DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI38",3e7,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000); or both I get errors.

 

 

 

With only one uncommented :

 

Data acquisition ready to start

i value is 0

End of program, press enter to quit

 

and with both uncommented :

 

Data acquisition ready to start

i value is 2147332096

End of program, press enter to quit

 

I don't know what to do.

Maybe use python to use C functions ?

 

Regards,

Thibaut

 

PS : I'm net sure to be in the right section.

 

0 Kudos
Message 1 of 7
(5,014 Views)

Hi Thibaut,

Which version of DAQmx do you use?

Is it specific to DAQmx counter task?

Regards

Yann C.

France

0 Kudos
Message 2 of 7
(4,980 Views)

Hi Yann,

 

I'm Thibaut and post from another account.

 

DAQmx version is 8.7.1

 

I haven't test other features than counter.

 

The matter is a buffer overflow. Could he came from :

 

DAQmxErrChk00 (DAQmxReadCounterU32(taskHandle00,-1,-1,data00,N,&num00,NULL));

while(i<=num00)

{

 cout << data00[i] <<endl;

 i++;

}

 

Regards,

Thibaut

0 Kudos
Message 3 of 7
(4,967 Views)

Hi Thibaut,

See this KB to avoid overflow in acquisition.

How do you know it's a buffer overflow.

Regards

Yann C.

France

0 Kudos
Message 4 of 7
(4,946 Views)

Hi,

 

I explain in the first post that a for loop is affected by some DAQmx functions whereas the loop is totaly independant from those functions.

So we tried to put the variable that control the loop in the middle of a large array (it's not a joke :))

It works for some things but we can't use multiple threads or write data on the disk.

 

Thibaut

Message Edité par Tobix le 06-19-2009 10:27 AM
0 Kudos
Message 5 of 7
(4,940 Views)

Hi,

Gcc is not supported, how did you do to use the the DAQmx library with gcc?

Regards

Yann C.

France

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

Hi Thibaut,

 

If the variables "data" and "i" are allocated on the stack, then I agree that this sounds like a buffer overflow. Could you please post more of your code, such as the DAQmx task/channel creation code and the declarations of all of the stack variables?

 

Also, since you're using an unsupported compiler, you should check that you are using the correct calling conventions.

 

Brad

Message Edited by Brad K on 07-10-2009 02:56 PM
---
Brad Keryan
NI R&D
0 Kudos
Message 7 of 7
(4,835 Views)