LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Locking the spreadsheet file when LabVIEW is running.

Solved!
Go to solution

I did not say to open it in read only, but to allow other applications read only access, of course. Read it again!

0 Kudos
Message 11 of 15
(425 Views)

@Happy96 wrote:

I have been working to add the "Close File VI", but not getting success. This is the logic I applied on my last try. Not able to determine why it is not working. All I know is that the VI is not entering the 3rd Case. 

Here are the snips and the attached VI

 


You attached the same VI as before (only two cases). However, you don't need that extra case.

 

You need to close the file in two locations:

 

  • Before you start a new file
  • outside, after the main loop

 

Also:

  • You don't need to build into an array of one elements for a chart. Just wire the scalar.
  • You don't need the extra scalar indicators, just show the digital display of the chart. They also don't have the correct representation.
  • Please don't maximize the diagram and front panel to the screen.
  • Don't do the "array to cluster...unbundle" dance. Just use index array resized to two outputs.
  • there is no reason to build your string into an array with one element before writing to disk
  • If you would combine your data using "array to spreadsheet string", you can set the comma delimiter and get the newline for free.
  • If you want the current time, there is no need to wire it.
  • The entire write operation could look as follows:

 

altenbach_0-1687558971024.png

 

0 Kudos
Message 12 of 15
(414 Views)

I was literally laughing while reading all your feedback thinking there is so much more I need to understand to make my code more efficient. Thank you for all the knowledge you share. 

 

I absorbed all your pointers and I think I understood it (yet to be implemented).

The only thing I am unable to do is to find a way of "closing a file before making a new one" in my "New File Creation" case. 

 

Close File VI needs refnum as input and when I loop back the refnum through the shift register in the "New File Creation" case it gives me an error.

 

0 Kudos
Message 13 of 15
(406 Views)

Here's how you handle "automatic file updating":

  1. Start by opening the file before entering the While Loop, and bring the File Reference in on a Shift Register.
  2. When you start saving to data, you know that the File Reference is correct (you just created it).  Do whatever you need to do inside the While Loop.  But before you exit, decide if it is time for a new File (however you decide to do this, after writing N records (and this is the Nth) or after a fixed time has elapsed (and "Time is up").
  3. When you do decide "Time is up", use the File Reference to close the existing file and then open the next one, saving the new File Reference in the output Shift Register.
  4. Note that closing a file and reopening a new file should not take a lot of time (a fraction of a second), but if you are worried about "missing writing some data", you can always use a Producer/Consumer Design Pattern with the File Writing being the Consumer, which lets the Queue or Stream Channel "buffer" any incoming data.
  5. This method always "closes the old" before "opening the new", and uses only a single (reusable) File Reference.  Should work (Famous Last Words) ...

Bob Schor

Message 14 of 15
(388 Views)

@Bob_Schor wrote:
  1. This method always "closes the old" before "opening the new", and uses only a single (reusable) File Reference.  Should work (Famous Last Words) ...

The order should not really matter as long as both happen inside the same case and the new reference is output to the shift register.

 

  • You can close the old and open the new
  • You can open the new and close the old
  • You can do both at the same time.

 

altenbach_0-1687625680475.png

 

Message 15 of 15
(384 Views)