LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read/display from multiple sequential files

Solved!
Go to solution

Hi – I have a problem that I have been struggling with for weeks now, and am hoping someone can help with this. I created a profile specifically because I am at a loss. Please forgive any ignorance I may have about Labview since the first time I even used this program was a few weeks ago when I started this little project. My code is attached below.

 

Background) I am able to read input from a text file (with read from spreadsheet function). The text file input is exactly 5 columns, but n number of rows (the 5 columns correspond to positions x,y,z,azimuth and elevation). As I manually cycle through to a certain row I want, I have 5 displays that show me my specific 5 columns of data (associated with that same row) inside the text file. I hit a button and move a motor system to those exact coordinates displayed. I do not know if it matters, but this VI is part of a larger home VI. My home VI has a button for “read data”, and when clicked, it opens my attached VI inside of a subpanel on my home screen.

 

Problem) While my program is running, I need the option to be able to choose and open a different text file, and update my array of data from the input file accordingly. And once I have my displayed array of data, I need to be able to manually cycle through the rows to any row I want, and hit my button to move my motors to those 5 coordinates.

 

Methods) I have tried every way I can think of to do this. The idea which I was stuck with the longest was me putting my read from spreadsheet function inside an event structure inside my while loop. This works in the fact that it allows me to choose any text file I want to read from while updating my displayed array of data, but I lose functionality. I lose the ability to cycle through rows and display the current data associated with said row. I feel I am somewhat on the right track with this method, but I do not know how to address my problem. Any help would be greatly appreciated.

0 Kudos
Message 1 of 7
(4,049 Views)

And sorry - I realize my original posted VI had some stuff that wasn't necessary to display. Reattached is a cleaned up bare VI.

0 Kudos
Message 2 of 7
(4,025 Views)

Neither of those attached VIs have the event structure you described as "your best attempt".  I think seeing that would help us see the problem with it.

 

I should also note that you should avoid using flat or stacked sequence structures whenever possible.  On both VIs the only place they actually do anything is in the "Exit" event you have, and that can be resolved by using the error cluster wire.

0 Kudos
Message 3 of 7
(4,003 Views)

I didn't use the word "best attempt". And I also didn't include the VI with the event structure just in case I am incorrect in my thinking that this is the correct approach to take. I wanted to be open to any different suggestions anyone might have that could solve my problem.

 

My original VI that I attached is the baseline from which I am attempting to figure out the solution. However, if you want to see my VI with the event structure that may or may not even be a correct approach to take, then it is attached also.

 

And noted about the sequence struct.

0 Kudos
Message 4 of 7
(3,983 Views)
Solution
Accepted by AOTA1

Ah, I see the problem.  Problems, really.

 

When your file path changes, it will indeed load a new spreadsheet file.  However, that new file is almost immediately discarded.  You've wired a zero to your timeout case, meaning that every time your main "while" loop runs, the "Timeout" case runs immediately.  The timeout case is empty, so nothing occurs there, but the output wire (of the read spreadsheet function) has to output something.  So it outputs the default value.  The default value of any array is an empty array. This overwrites whatever you just loaded in a millisecond or so.

 

This isn't the best way to do it, but the easiest way to keep your code almost the same is to use a shift register on the while loop and wire it through the timeout case:

 

shift register.png

0 Kudos
Message 5 of 7
(3,965 Views)

I see. Your explanation is something that makes perfect sense. Thank you for that. Your solution does exactly what I need.

 

But that being said, you said “This isn't the best way to do it”. For my understanding, can you explain why exactly it isn’t good. And if so, would you happen to know of a better way to go about accomplishing the task?

 

-Once again, thank you

0 Kudos
Message 6 of 7
(3,952 Views)

It's a bit hard to tell but it appears that you want to have part of your program constantly running while another part checks for user events (i.e. pressing buttons etc).  The best way to do something like that is usually to have two separate "While" loops, one that handles the things that always run and the other which handles the user events and sends messages to the constantly running loop.  

 

It's generally referred to as producer/consumer architecture and there's already a lot of how-tos, tutorials, videos, and built-in LabVIEW examples explaining how it works..  It may be more complex than you need at the moment, for this VI, but it's a good design pattern to follow when your code gets more complex.  

0 Kudos
Message 7 of 7
(3,937 Views)