LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to a text file.

Hello,

I am writing to a text file temperature and humidity from a Vaisala device, with file being saved on network to a share drive, everything is working fine with the exception when I loose network connection. Is there any way to overcome that issue? I am using VISA function to send commands and receive answer from the device into a while loop with reading from device every 60 sec and writing to file every 600 sec.

Thank You !!!

0 Kudos
Message 1 of 13
(2,529 Views)

Write the file locally and back it up to the network. Have your program check to see if the network is available and back things up. If the network is not there you are still recording the data. When the network comes back you update to the latest text file.

Tim
GHSP
Message 2 of 13
(2,522 Views)

If you want to write to a file on the network, and the network is not there, the only solution is to not write to the network... Not much you can do about that!

 

You can store locally and to the network. If the network fails, keep logging locally and sync when it's back.

 

Or keep the data in memory if the network is not available. There should be a limit, you don't want to crash your application because it's out of memory.

 

Another option is to write logs locally, and make a separate thread that uploads the files to the network (if it's there). There will be a latency. There are even tools that do this, so you won't have to program it at all.

 

Or simply ignore the error...

 

It's really up to you. Decide what you want, and then make it (optionally with some help).

Message 3 of 13
(2,519 Views)

Thank you, sounds like a good plan. Do you know or have any examples in how to check if network is available and transfer the local file over the network.

0 Kudos
Message 4 of 13
(2,503 Views)

Well, you try to do what you want to do such as a file copy.  If it fails with an error, then you know it didn't work!

Message 5 of 13
(2,498 Views)

Thank you,

I used copy function to a new path every 600 sec. and now will deploy see how it behaves.

0 Kudos
Message 6 of 13
(2,481 Views)

Make sure you handle the error case with the local write or storage in memory, e.g. shift register or similar.

Some file formats are more amenable to later stitching together or appending multiple files - that might be an option if your network is unavailable.

Otherwise, you might need to read back locally stored data when you can next append to your network file.

How long are typical outages?


GCentral
Message 7 of 13
(2,466 Views)

@MariusS wrote:

Thank you,

I used copy function to a new path every 600 sec. and now will deploy see how it behaves.


I'd use a move function. If it fails, the original is still there. If it succeeds, you're done. It's a copy and delete in one function.

 

I usually create those files with a .something.tmp extension. Then, when it's done (every hour? every day?) I change the extension. The "move to network" only looks for the .something files, and leaves the .something.tmp alone.

 

Of course, the logging function can also move the file when it's done, along with older files if they are there (and if it successfully moved the first file).

Message 8 of 13
(2,448 Views)

wiebe@CARYA wrote:

@MariusS wrote:

Thank you,

I used copy function to a new path every 600 sec. and now will deploy see how it behaves.


I'd use a move function. If it fails, the original is still there. If it succeeds, you're done. It's a copy and delete in one function.

 

I usually create those files with a .something.tmp extension. Then, when it's done (every hour? every day?) I change the extension. The "move to network" only looks for the .something files, and leaves the .something.tmp alone.

 

Of course, the logging function can also move the file when it's done, along with older files if they are there (and if it successfully moved the first file).


I disagree with this.  While I don't recall any specific instances with a move function, I feel like there have been rare cases where a move has failed and left me short.  When I want to move a file manually and I am suspicious about the connection that it might definitely succeed, I'll always do a copy.  Only when I'm 100% sure that the copy succeeded, then I'll manually go back and delete the original.  This is probably more so when I want to move multiple folders/multiple files so that I don't wind up with only a partial move done when a network error kills the process.

Message 9 of 13
(2,433 Views)

Thank you for all responses. This little app I created is monitoring and recording data 24/7. Every 3 days I stop the app for couple seconds to create and load a new .txt file because is getting too big. Now isn't the case with open files that you cannot copy or move them?

0 Kudos
Message 10 of 13
(2,426 Views)