LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insuring a file is finished writing before loading.

I am using a filesystemwatcher event to load a tdms file when it is saved from another process. Occasionally I get an error that seems like the file is being loaded before it is actually finished saving. It seems like the error that is happening is because of incomplete information in the file. If I wait and try the file again a minute later it seems fine.

 

Is there a way to insure that a file is finished saving before loading? I'd rather load the file right after it is completed being saved rather than set a timer.

0 Kudos
Message 1 of 11
(3,375 Views)

What's the other process? A different application? If so, is it one that you can modify to help accomplish this task?

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 2 of 11
(3,372 Views)

It is a different VI that is collecting data on a manufacturing process. I am using the standard TDMS Open, Write, Close pattern.

 

flycast_1-1630412626460.png

 

0 Kudos
Message 3 of 11
(3,367 Views)

If it's a different VI in the same application, then why not just have the collection VI tell the loading VI when it's done making the TDMS file? There are many ways to do this.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 4 of 11
(3,357 Views)

Hi flycast,

 


@flycast wrote:

Occasionally I get an error that seems like the file is being loaded before it is actually finished saving. 


Some pseudocode:

REPEAT
  error := OpenFile(file)
  IF error THEN wait(2s)
UNTIL not(error) 

Seems simple to implement!

 

When accessing files you will need to take into account processing time of the TDMS file creation (like creating the TDMS index file) or the time needed by the OS to finish file writes on the actual file storage device…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 11
(3,355 Views)

I've never really considered what it takes on a lower level to write a file. I would expect that a empty file is created and then a stream is used to actually write the data. If I am using a file watcher on file creation it's probably notifying on the initial creating but not when it is finished writing.

0 Kudos
Message 6 of 11
(3,348 Views)

Hi flycast,

 


@flycast wrote:

I've never really considered what it takes on a lower level to write a file. I would expect that a empty file is created and then a stream is used to actually write the data.


With TDMS you most often also get a separate index file, which will be created/written on closing the TDMS file. This part also will take its time…

 


@flycast wrote:

If I am using a file watcher on file creation it's probably notifying on the initial creating but not when it is finished writing.


That's my experience from watching Excel files: Excel creates a filewatcher event upon opening a XLS(X) file, but not on closing it. (Infact Excel will update the file creation/change timestamps already upon opening the file…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 11
(3,332 Views)

@FireFist-Redhawk - In general what would these ways be?

0 Kudos
Message 8 of 11
(3,322 Views)

@flycast wrote:

@FireFist-Redhawk - In general what would these ways be?


An FGV would be the simplest way. There are also queues, notifiers, and user events, any one of which could be used.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 9 of 11
(3,307 Views)

@FireFist-Redhawk wrote:

What's the other process? A different application? If so, is it one that you can modify to help accomplish this task?

 


 

@flycast wrote:

It is a different VI that is collecting data on a manufacturing process. I am using the standard TDMS Open, Write, Close pattern.

 

 

 


Hmm... If both if these are LabVIEW then why not just roll them into one program instead of using the filesystemwatcher?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(3,305 Views)