LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error 1 at Write to Text File within For Loop

Solved!
Go to solution

Hello all,

I am trying to get this VI to collect write data to a file as the VI runs, instead of creating the file only at the end which it used to do. I took the code which creates the file and adds a header before the inner for loop where data acquisition occurs, and fed the refnum from this write to text file into the for loop where the data acquisition is, and then write the data to the file using another using the same type of function. Can someone help me understand why this refnum is being lost once going through the loop, and what I need to do to remedy this issue? Thanks in advance!

 

P.S. the create file code is to the left of the inner for loop about half way down, the other write to file function can be found following that refnum output

0 Kudos
Message 1 of 27
(2,966 Views)

My laptop has a 1920 x 1080 pixel size.  I estimate your Block Diagram is 5 "screens" wide by 4 "screens" deep (so far, I'd need 20 laptops to see it) and you have a Stacked Frame Sequence in the middle that is 7 layers deep!

 

I see nowhere (at first glance, and there's too much territory to do much more) that File I/O is taking place.  There also doesn't seem to be a Path Control on the Front Panel.

 

Based on your symptom, I wonder if you brought a Path name into a Loop and used "ordinary Tunnels" when you needed to use a Shift Register.  However, if it's in that 7-layer Stacked Frame, all bets are off ...

 

Learn to use sub-VIs (several layers deep, if necessary) to keep all Block Diagrams to "Laptop Screen" size.  It will aid your ability to code and find/fix/eliminate bugs.

 

Bob Schor

0 Kudos
Message 2 of 27
(2,962 Views)

..and this is the SIMPLIFIED version!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 27
(2,959 Views)

Sorry about the VI formatting, I did not write it, I am just trying to change some functionality. Also, I didn't realize the indicators got removed on the front panel, I re-uploaded the VI and the path and information for "Data Storage" so you can now use the filename out path on the front panel to find the terminal in the block diagram if you'd like to take a look now. Thanks!

0 Kudos
Message 4 of 27
(2,952 Views)

Yeah, maybe not the best name for this VI; however, I was referring to the save functionality, as it used to look like this. 

0 Kudos
Message 5 of 27
(2,949 Views)

Great, you attached a picture, so while we know that you used an Express VI (which hides all kinds of settings inside it), we can't see how you configured it (but since it's not working as you would want, you probably didn't do it right).  There's also no "loop" indicated.

 

The usual thing to do is to have a loop.  Before entering the loop, you do a Open/Create File (which takes a Path in, and returns a File Refnum), the Refnum is brought in through a Shift Register (not a Tunnel), inside the loop you do a Read or a Write, carrying the Refnum to the "output" Shift Register, and outside the loop you do a Close File (which turns the Refnum back into a PathName).

 

Bob Schor

Message 6 of 27
(2,943 Views)

So what you had described is exactly what I had, minus the shift registers (I had replaced the expressVI for being too complicated to edit). I replaced the tunnels with shift registers and still have the same error though? I'll attach pictures of both parts of the code as well as the error. Thanks again.

Download All
0 Kudos
Message 7 of 27
(2,930 Views)

I'm not sure we'll get anywhere by making changes without understanding them.  The unfortunate task falls to you to use probes to follow the data around and figure out where that ref becomes invalid.

 

If the original developer had broken the code into subVIs, the error message would be more meaningful.  e.g., instead of the error code telling you it happened somewhere in the super-huge VI, you could drill down to the exact subVI where the error was happening, dramatically simplifying the troubleshooting process by zeroing in on the code where it is actually happening.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 27
(2,917 Views)

The virtue of you attaching the entire VI (instead of a picture of a tiny, tiny piece, by my estimate < 0.01%, of the Block Diagram, is that we can search for such things as File I/O functions and at least find the code and then start following the wires.  Of course, you could also help us by saying "Look about 20% over from the left edge, down about 30% from the top, in the 5th Stacked Sequence diagram, where you'll find ...".

 

In the absence of data, the best most of us can do (some of my colleagues have secret powers that lets them accurately "see" other's unposted Block Diagrams!) is to make "guesses".  This has limited utility for us and for you, and largely wastes both of our time(s).

 

Bob Schor

 

P.S. -- I promise, no more remarks from me until you post the VI ...

0 Kudos
Message 9 of 27
(2,901 Views)

Is the entire VI not attached to the original post? I thought I had replaced the old one there with the a newer version that had the filename out under "Data Storage" on the front panel which is a quick way to find where the file is created using the "find terminal" option. I was just attaching the pictures for exactly what I was talking about. I'm pretty sure it is an issue of being inside the case structure and sequence structure, but still unsure how to go about fixing it as I've tried creating the file outside of those structures as well. I'll attach the VI to this response as well just in case. Thanks!

0 Kudos
Message 10 of 27
(2,898 Views)