02-05-2010 03:31 PM
Hello,
I'm working on a data logger at 200 Hz frequency. I wanted to log the data to a file after eace sample received. When I used (fopen,fprintf,....) on Mathscript, the Labview started to log the data at a slower rate. I then used the Labview file VIs and it is working fine up till now.
My questions are as follows:
1- Are the file functions in the Mathscript slower than the Labview VIs ?
2- Is saving the data to a file after each sample is received a good idea or is there a better idea ? I just don't want to keep the data in the memory and after all the data is logged, I flush them to a file ... because, it seems that the PC will run out of memory.
Thank you,
Walid
02-05-2010 04:43 PM
Walid,
I think saving the data to file after each sample at 200 samples per second rate is an overkill. You don't wanna do that. Waiting until all data points are collected isn't too good either, so you need to define some block size let's say one or two seconds worth of data and then save it to the file periodically until all data is acquired.
hope this makes sense to you.
Serge
02-05-2010
05:15 PM
- last edited on
10-24-2025
03:34 PM
by
Content Cleaner
wfarid wrote:
Hello,
I'm working on a data logger at 200 Hz frequency. I wanted to log the data to a file after eace sample received. When I used (fopen,fprintf,....) on Mathscript, the Labview started to log the data at a slower rate. I then used the Labview file VIs and it is working fine up till now.
My questions are as follows:
1- Are the file functions in the Mathscript slower than the Labview VIs ?
Yes. That's because you're going through another layer of software. Why were you trying to use MathScript to log data to file in the first place? Are you a Matlab "aficionado"? ![]()
2- Is saving the data to a file after each sample is received a good idea or is there a better idea ? I just don't want to keep the data in the memory and after all the data is logged, I flush them to a file ... because, it seems that the PC will run out of memory.
It doesn't make sense to save data after each sample. File I/O is an expensive operation in terms of time, and you have the operating system to deal with, so while you may be able to keep up the rate for some time, eventually it will be thrown off. You can do as suggested which is to wait until you have a certain amount and then write that to file, or you can set up a producer-consumer or master-slave architecture. Let one process/loop collect the data and put into a buffer, like a queue, and the other process/loop can stream it to disk at a more reasonable rate. You just have to make sure the buffer is large enough so that if the file I/O gets hung up you won't reach the buffer's limit.
02-08-2010 03:09 PM
02-08-2010 05:09 PM
By the way,
For the Producer/Consumer or Master/Slave approaches, I want to ask
- Will I still need to specify when the slave should take the data from the buffer ? I mean do I need to specify that the slave takes 1 sec. worth of data every time, so slave need to be running in a timed loop, or can I just make the slave loop a continuously running loop with the Labview controlling when to read the data from the Queue ?
- In the articles "smercurio_fc" mentioned, they always keep talk about using occurencences to make sure that the slave loop will not start before the master loop, but if the slave loop only waits for Queue data, why do I need occurences ?
Thank you,
Walid