LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Datalog file as buffer

Solved!
Go to solution

Can anyone tell me why I can't use the "Set Datalog Position" back to overwrite existing records in a circular buffer?

 

Thanks

Matt

0 Kudos
Message 1 of 12
(2,929 Views)

That would be problematic if your records don't have uniform sizes. For instance, if you set the position back to a previous record of size 10 bytes and overwrote it with a record of the same type, but size 16 bytes, then you would have accidentally overwritten the first 6 bytes of the next record.

 

What version of LabVIEW are you using? More recent versions have more powerful functions for reading and writing binary files that have made the old-style datalog files less useful. These functions do support setting a position in the file that would allow you to use the file like a circular buffer. However, here you would still need to be very careful that your records are always a uniform size.

Jarrod S.
National Instruments
0 Kudos
Message 2 of 12
(2,912 Views)

I'm using Labview 2010.  My buffer size should stay the same size.  As one value comes in, one should get removed.

0 Kudos
Message 3 of 12
(2,898 Views)

Matty,

 

I'm curious why you're using a log file for this kind of buffer as opposed to an array. You may have a reason for this but it seems like uneccessary overhead if you don't. I have included an example of a fixed circular array buffer. 

 

If you're doing this with a log file for whatever reason, the principle would be the same. You need to maintain a count of how many records have been written and reset the file position and the count when the count is equal to the maximum size for your buffer. To output the record at the "end" of the buffer, you output the line that is about to be overwritten, then overwrite it.

 

 

 

Download All
0 Kudos
Message 4 of 12
(2,886 Views)

In the case that the program ever stops executing, I need to save the circular buffer.  Say, someone unplugs the PC.  The circular buffer should contain the last saved value plus all others in the buffer.  The value will be stored with a time stamp so I can use this to determine first to last entered.

 

Regards

Matt

0 Kudos
Message 5 of 12
(2,883 Views)

Ok. I hope this get's you started then:

 

1. If the "count" is below the maximum for the buffer, read and output the current record, then overwrite it.

2. If the count is equal to the the max, reset the count and read and output the record at the begginning, then overwrite it.

 

Does that make sense?

0 Kudos
Message 6 of 12
(2,874 Views)

Unzip my program and run the "File Buffer.vi".  I am not worried about deleting after reading.  I actually don't care if data in the circular buffer gets overwritten without reading.  I just want a file buffer of the most recent data collected.  I tried to do exactly what you are saying with the "set datalog position" but it is not working.  I am getting unpredicted results.

 

Thanks

Matt

0 Kudos
Message 7 of 12
(2,869 Views)

I see part of the issue now. The "write data log" vi you use after setting the position sets the position to the end of the file always:

 

 

  • Writes record(s) to an open datalog file specified by refnum. Sets the current datalog position to the end of the file before writing

 

 

The "set position vi" also mentions this in its help doc though the wording is questionable:

 

 

  • The Write Datalog function changes the current datalog position to the end of the file. You cannot use this function to write to a different position in the file.

 

 

This at least explains why your file keeps growing and does not act like a buffer as you want. Looking through the datalog vis, I can't see a way to work around this issue. You may have to start from scratch using the more basic file vis which don't automatically set the file position. 

0 Kudos
Message 8 of 12
(2,861 Views)

Do you have any suggestions?  Or maybe someone else who has done this before.

 

Thanks
Matt

0 Kudos
Message 9 of 12
(2,857 Views)

You could use the regular text file VIs unbundling the records before you write them in, each on their own line. You'd then have to write a parser for your app to turn them back into records again. I think your positioning scheme would work with regular text files because the "write to text file" vi does not try to set the position and relies completely on "set file position" before it is run. You would also want to wire to file position as opposed to offset.

0 Kudos
Message 10 of 12
(2,852 Views)