From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to spreadsheet file not saving

I have a .csv file that I have 6 computers trying to save to.  Unless the file is open up completely, I am not getting an error if one of the computers can't save to the file because one of the other computers is saving at that time.  I have a loop to try again but this has not been successful.  Attached is what I am currently trying.  The data saves well except occasionally.  Any suggestions on getting all 6 computers to save to the file and how to properly get an error code if it does not save (although I would prefer a solution that would try again if the file didn't save properly).  Thanks in advance!!!!

-ncm
0 Kudos
Message 1 of 8
(3,276 Views)

I would probably just write a server application that does the actual writing of the file.  The server can just be listening for a TCP connection, go through a few handshakes to get the data, save the file, and then close the connection.  This way, the TCP connection acts as a lock so that only one client can save to the file at a time.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 8
(3,268 Views)

This sounds like a great solution, could you go into a little more detail, in particular, writing to a server application?  I am not familiar with this and would like a little guidance or possible example.  Much appreciated!!!

-ncm
0 Kudos
Message 3 of 8
(3,263 Views)
Message 4 of 8
(3,259 Views)

In accord with that, does this mean that you are repeatedly overwriting the file, and thus have no idea which of the 6 PCs saved its data?  This seems very strange to me.  Are you appending to a certain file (say, a log file that says "Computer 2 did this at this time, Computer 4 did something else a minute later")?

 

There are a number of "tricks" you can try to get exclusive access.  First, Computer N can start by renaming the file "Locked by N", then checking (after waiting a second) to be sure the lock "took".  If the lock fails (because some other computer has locked it), it waits 15 seconds and tries again.  Otherwise, it updates the file (using its "locked" name), then unlocks it by renaming it to the original name.

 

This is certainly more clumsy than Crossrulz's suggestion of a Server architecture, but perhaps easier for you to implement if you don't have TCP/server expertise.  Look up "Database locking" on the Web -- you might get other ideas.

 

Bob Schor

Message 5 of 8
(3,257 Views)

Thanks for all the new ideas!  I will get working on these and see what I am able to use, thanks again!!

-ncm
0 Kudos
Message 6 of 8
(3,246 Views)

@ncm wrote:

This sounds like a great solution, could you go into a little more detail, in particular, writing to a server application?  I am not familiar with this and would like a little guidance or possible example.  Much appreciated!!!


The application does not exactly have to run on a server.  It just has to be in a place that the other computers can connect to.  But start by going into the Example Finder (Help->Find Examples).  There should be a couple of examples along the lines of TCP/IP Client and TCP/IP Server.  Those will get you started.  I also recommend having a good look at the STM library (seperate install via VIPM) as it makes setting up a communications scheme a lot easier.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(3,226 Views)

@ncm wrote:

I have a .csv file that I have 6 computers trying to save to.  Unless the file is open up completely, I am not getting an error if one of the computers can't save to the file because one of the other computers is saving at that time.  I have a loop to try again but this has not been successful.  Attached is what I am currently trying.  The data saves well except occasionally.  Any suggestions on getting all 6 computers to save to the file and how to properly get an error code if it does not save (although I would prefer a solution that would try again if the file didn't save properly).  Thanks in advance!!!!


Hmm... My first question is. Why do you have or would you even want, six different computers writing to the same file? Specially if this is just aggregate pass/fail count as in your example.

 

Seems to me if you are after pass/fail data from six test stations it would be better to have each station store its data locally (or in separate files on the network) then have another computer poll and aggregate the data at regular intervals.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 8
(3,223 Views)