LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create a Static Copy Of An Array

Solved!
Go to solution

Hi,

 

I'm having problems reading data into my VI. I'm really new to doing this, and have been thrown in the deep end. I'm trying to have a pushbutton start an open dialog process which then the user can read in a csv file to an array. The problem is if I just use Read From Spreadsheet.vi and the user clicks cancel, an error occurs. So to get around this I've created a convoluted little pushbutton sequence thing you can see in picture I've attached.

 

So, to my actual questions. One, I believe there's a better way of doing this, but I can't think of it. Two, once I actually enter an appropriate file name into the VI it takes it, but because the push button is no longer held, all the case statements are false, and the array goes back to being empty. Is there a way to take a copy of the array at that point, before it clears, and use that for my data manipulation.

 

I'm using a 50ms cycle time because eventually I'm going to be sampling data at that rate.

 

Any help would be appreciated.

 

Thanks,

Chris

0 Kudos
Message 1 of 10
(3,542 Views)

I would replace your outer case statement with an event structure. The event structre will only execute when the button is pressed (you have to register for that event but the examples show how this is accomplished). Generally the event structure is placed inside a while loop and it would contain event cases for other things like Exit. It isn't clear how you are running your code but if you are using the Run continuous button, don't. This should only be used for debugging, not repeatedly running your code. That is why you have while and for loops.

 

You may also want to look at the examples for state machines. This is a basic application architecture which will help you build an application.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 10
(3,529 Views)

The Event Structure is a reasonable approach, but for a very basic application, it might be easier to place your code in a while loop (if it's not already in one) and make sure the boolean button's mechanical action is set to Latch When Released.  Put the array into a Shift Register (this is a key LabVIEW concept).  In the false case, pass the data from the shift register on the left side of the while loop through to the case structure's output tunnel, instead of outputting a default (empty) array.

 

You might want to open up the Read from Spreadsheet VI, maybe make a copy of it and modify that copy as needed so that it doesn't put up an error dialog when the file browser is cancelled.  Internally it's a very simple VI, intended for quick VIs, but does not provide many options for error handling.  It is easy to modify to handle errors differently.

 

Not sure why you mentioned the 50ms time, especially because it will probably take the user much longer than that to select a file.

Message 3 of 10
(3,517 Views)

agreeable on both your parts...again, this is just a simple VI that can be done in various architectual stylesSmiley Wink

 

READ-CANCEL.png

0 Kudos
Message 4 of 10
(3,510 Views)

i should of put the bool controls within the case statements to avoid "polling" it...Smiley Surprised

0 Kudos
Message 5 of 10
(3,499 Views)

@apok wrote:

i should of put the bool controls within the case statements to avoid "polling" it...Smiley Surprised


Still that will keep on polling as your case structure always runs through the "Initialize" case. The better option would be is to use an Event structure you don't have to unnecessarily keep on running the code.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 6 of 10
(3,478 Views)

P Anand wrote:
Still that will keep on polling as your case structure always runs through the "Initialize" case. The better option would be is to use an Event structure you don't have to unnecessarily keep on running the code.

its not good style practice to constantly poll your UI in this situation (performance wise),...like I said before, it can be done in many different architectual styles including your "event structure".

0 Kudos
Message 7 of 10
(3,469 Views)

The suggestions given are good, but the easiest solution to your immidiate problem it placing the array indicator inside the Case structure, thus it'll only be updated when the file is read, now it'll be cleared the next loop (as it looks like you're outputting Default (empty array) in the False case).

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 10
(3,441 Views)

Thanks to everyone for their help, there was some good pointers in there that I think will see me through some more of this program.

 

One quick question is, how do I easily edit an existing VI. I can't locate the file to make a copy of it through the wizard. Also I double clicked the Read from Spreadsheet VI to take a look at it and I didn't see any error handler in there. I've probably missed something.

 

Thanks.

0 Kudos
Message 9 of 10
(3,409 Views)
Solution
Accepted by topic author Chris Johnson

What wizard are you talking about?

 

You can drop the Read from Spreadsheet file onto your block diagram.  Double click and it will open up for editing and you can see it is a real subVI and not just a function.  Do a File >>  Save As and save it under a new name and location.  (not the vi.lib it is currently in).

 

The error dialog seems to be in the subVI called Read Lines from File that is within the Read from Spreadsheet File VI.

Message 10 of 10
(3,396 Views)