08-03-2016 12:08 AM
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
08-03-2016 02:11 AM
08-03-2016 03:03 AM
@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
08-03-2016 08:57 AM
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
08-03-2016 09:57 AM
Please refer to state machine architecture: http://www.ni.com/white-paper/3024/en/
08-03-2016 10:04 AM
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
08-03-2016 11:29 AM
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
08-03-2016 11:44 AM
-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.
08-03-2016 12:21 PM
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
08-03-2016 01:22 PM
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.