ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

取消
显示结果 
搜索替代 
您的意思是: 

Clearing the buffer when reading a 'few' samples

Hello,
I am looking to develop a system that samples a number of data channels at ~50KS/s, reading the data into a buffer.  Every 10ms I want to read just a few samples to check if a condition threshold has been passed - eg the pressure has gone above 10kPa.
If the condition has occured, I want to read all the contents of the buffer so I then have the condition of the system for the last ~5seconds leading up to the event.
- I have set a Task up to read a finite number of samples at 50Ks/s into a buffer which works out to be 5s long.
- Every few milliseconds I use the Read command to just read the most recent bit of data, so I set the 'read number of samples'  to 100 or so.
If the process routine detects an error it creates an event which issues a Read command with teh 'read number of samples' set to -1, ie all.
The problem is though, will the Read All command then sit there for 5seconds gathering a buffer full of data when what I want it to do is give me the last 5 seconds of data?

I hope this makes sense, I would appreciate any thoughts.

Best regards,

Martin
0 项奖励
1 条消息(共 2 条)
2,363 次查看
Is all of this happeing in one loop? Sounds like you need (at least) two separate loops, in a producer/consumer structure. With queues, you can peek at data without stopping it or pausing. One queue could hold hold all the data while you skim off the top with your current method. When you want to see all the data, just read the queue. Look up Producer/Consumer and/or queues and notifiers.
Good luck with your project!
Richard






0 项奖励
2 条消息(共 2 条)
2,353 次查看