LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic LabVIEW question - getting new data into a while loop

I put together a RT VI that reads a file into an array, graphs the file data, then sends the array data into a while loop to do realtime stuff based on user input.  I want to add the ability to read in a new file without re-starting the program, but when I added a loop to check for having a new filename to read, it made the program hang...  So I wanted to ask, what's the usual approach to occasionally change the data wired into a while loop?

 

thanx

JEB 

0 Kudos
Message 1 of 15
(4,551 Views)

Hi Jeb,

 

to read new data when a condition is met you usually use a case structure: "IF condition THEN read file"…

To have us check your VI you need to attach it!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 15
(4,531 Views)

@JesseBuck wrote:

I put together a RT VI that reads a file into an array, graphs the file data, [...]

thanx

JEB 


File IO and graphical display are non-deterministic, so they are not RT.

As Gerd pointed out: post your VI so we can see what you actually do. If that VI is targetting a realtime target, you should use RT FIFO for data transfer.

Also make sure that your non-deterministic code (e.g. File IO, graphical display) is clearly separated from the RT stuff. Only then, it is save to use a real RT target.

What kind of RT target do you have?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 15
(4,514 Views)

Hi Guys,

Thanks for the feedback.  I posted the code this time.  The idea is when the program starts it does non-realtime stuff like reading a file and graphing it, then drops the array data into a while loop that does realtime stuff.  As it is I have to restart the program with a different filename if I want to change the data.  My question is, how can I switch to a new file while the program is running?

 

Thanks,

JEB

0 Kudos
Message 4 of 15
(4,492 Views)

Please refer to state machine architecture: http://www.ni.com/white-paper/3024/en/

Thanks
uday
Message 5 of 15
(4,475 Views)

I am a sucker for event based programming. It lets you add a lot to the program, without slowing it down with Polling.

 

To do it inside a while loop, you could create a shift register of the file name, and feed it to an"equal to" of the actual file control if they do not match, run your file read and array functions there, and feed it all the new information through the loop with a shift register or local variable.

 

It would use less resources if you used event based, and had a change of value trigger all this. Everything that is in your while loop now would be under the "time out" case.

 

You would also have to add a STOP button case, and have it kick out the main While loop.

Finally, if you use a bad file path and do not have any error handling wired in you'll hang your program! As a suggestion if a change of value causes an error, revert to value before the change occured, and let the user know.

Hope this helps!

 

Scott

0 Kudos
Message 6 of 15
(4,470 Views)

Hi Scott,

Your advice sounds like what I am trying to do but I don't see how to implement it.  I attached a snippet that shows my incorrect attempt which hangs the program.  Due to my lack of LabVIEW experience, I don't see what I am supposed to do, and I don't follow the specific details of your explanation "To do it inside a while loop...".  A diagram example might be helpful to my comprehension.

 

Thanks for any clarifications!

 

JEB

0 Kudos
Message 7 of 15
(4,456 Views)

-Please go through http://www.ni.com/white-paper/3023/en/

-In producer loop keep your offline stuff with specific button(Load data maybe).

-In queue enqueue your data and do your processing in consumer loop.

Thanks
uday
0 Kudos
Message 8 of 15
(4,450 Views)

Hi Uday,

Thank you for the documentation suggestions.  Unfortunately I don't understand how to apply this to my existing program.  My real time loop uses a fairly large array over and over.  I don't see how that would work reading the data off a queue, isn't the data gone after being read once in that case?

 

Thanks

 

Jesse

 

0 Kudos
Message 9 of 15
(4,439 Views)

The only way to thank in forum is by giving kudoes.

-Go to File->New->From template->Frameworks->Design Patterns->Producer/Consumer design patterns(Events).

-To Obtain queue, connect 2d array of type as required.

-Inside Enqueue element event, you keep your load file and enqueue data. This completes your whenever you need data you can load data.

-Now in consumer loop, Dequeue element has timeout means it will check if there are any elements in the queue till that time(default -1, meaning wait infinite time).

-So now inside True case strucuture, keep one more case structure and connect timeout output as case selector.

-Connect your 2d array like the same in your code except that, you have to pass new data inside false time out case.

-In true case it has to be from the shift register. And your entire code remains same after this case structure, you can keep all your processing here.

Thanks
uday
0 Kudos
Message 10 of 15
(4,430 Views)