Discussion:
Call DAQmxBaseReadAnalogF64() in a subfunction return stale data
(too old to reply)
scstop
2008-07-30 07:40:07 UTC
Permalink
Hi Everyone,   I am current using NI-USB 6218 on Mandriva 2007.  The ai acquisition works fine if I call DAQmxBaseReadAnalogF64() in the main() function, like this:int main(int argc, char *argv[]){ ...  while(1)  {    DAQmxBaseReadAnalogF64();  }...}   However, if I call the DAQmxBaseReadAnalogF64() in a subfunction, I always get the stale analogue data!void get(){   DAQmxBaseReadAnalogF64();  //  print the acquired data} int main(int argc, char *argv[])
{
..
  while(1)
  {
     get();
  }
..
}  The attached file is the one which cannot work properly.  Would anyone please tell me how to solve it, or is it a bug?


acquire.c:
http://forums.ni.com/attachments/ni/250/41963/1/acquire.c
Steve_B
2008-07-31 13:40:27 UTC
Permalink
Hi scstop,
 
It seems like you could be getting an error on your DAQmx Read when it is called in the get() function. It does not look like you handled the error in that case. In the event of an error, future DAQmx Reads would not work and because your data array is defined for your entire program, not just your function, you would display the same data. See if implementing the error handling rpovides any additional insight into the problem.
scstop
2008-08-01 01:40:18 UTC
Permalink
Dear Steve,   Thank you for your reply. Now I met a more strange problem.  The OS is Mandriva 2007, I installed DAQm base 3.1. I meet a problem calling DAQmxBaseReadAnalogF64().  I attached two files.(1) good_simple_acquire.c  This file works very well.  In this file, I just read analogue data repeatedly.  While(1)  {    DAQmxBaseReadAnalogF64();  }(2) fail_tcp_acquire.c  This file does not work well.    In this file, I just implemented a TCP client, wait for the server request, read analogue data, and sent the data to the TCP server.  While(1)  {    Recv? 
    DAQmxErrChk
(DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*NUM_CHANNEL,&pointsRead,NULL));



      for
(i=0;i<6;i++)

      printf("%f
",data[i]);  // here,  print the
acquired data immediately. But in this file, the data, though change a little bit do not follow the input analogue voltage. But in good_simple_acquire.c, the
previous lines are the same and work well, i.e. the printed value follows the
voltage adjustment.    Send?  }  After calling DAQmxBaseReadAnalogF64(), I will print the first 6 data I got.  After that I plan to send the data out to the TCP server. However, the data is stale.  By ?stale data?, I mean that the data printed dose not follow the voltage change. However it dose change a little bit and keeps the value around the initial value (that value is correct).  I compared the two file, and I am sure that the configuration related to the NI DAQ card is the same.  I am very confused about this. Because I need to send these data out to another server.    Thank you!


0731.zip:
http://forums.ni.com/attachments/ni/250/42023/1/0731.zip
Steve_B
2008-08-01 22:10:08 UTC
Permalink
Hi scstop,
 
I would recommend that you try removing your TCP sections from the while loop to be sure that it behaves as you would expect. If this is the case, your timing may be the issue. The amount of time taken between reads may be too high. Also you mention that you do receive new data and it is close to the right value but it does not move with the voltage, but I am curious to see what you read and what you expect in both scenarios.
scstop
2008-08-02 05:10:08 UTC
Permalink
Dear Steve,
I post another message. I hope this message will describe this problem more clearly.
<a href="http://forums.ni.com/ni/board/message?board.id=250&amp;thread.id=42027" target="_blank">http://forums.ni.com/ni/board/message?board.id=250&amp;thread.id=42027</a>
Thank you for your help!
&nbsp;
Steve_B
2008-08-04 19:10:09 UTC
Permalink
The thread will continue at the link above. It is best to keep your issue to a single thread but the other thread is more concise and informative.
scstop
2008-08-05 05:40:08 UTC
Permalink
I am sorry for the inconvenience that I brought. This thread can be deleted. Thank you!
Loading...