Discussion:
Problem using case structure inside while loops
(too old to reply)
drfunkphd
2008-08-14 18:40:07 UTC
Permalink
Hi all, I am currently building a VI (using 8.5.1) to monitor and control a pressure tank system.  It mainly uses a while loops to retrieve the pressure data and export commands and signals using a DAQ.  I am running into a problem when trying to record the data.  Recording is done at a much slower rate than the sampling, so I used a timer to trigger a case structure.  This then retrieves all of the readings and writes them to an excel spreadsheet.  The problem is that while the recording is taking place, all other sampling has to wait for the recording to finish.  Is there any way to make the while loop continue to run simulataneously with the case structure?  Or am I approaching the entire recording process in the wrong manner?  I'm new to Labview, and this seemed to be the simplest way to accomplish the task.  Any feedback would be much appreciated.  Thanks - Dan


The BeastMaster Final.vi:
http://forums.ni.com/ni/attachments/ni/170/349391/1/The BeastMaster Final.vi
smercurio_fc
2008-08-14 19:10:06 UTC
Permalink
Can't look at your code right now, but it sounds like you need 2 loops. One loop collects the data. The other loop does the writing to file. This way when you write the data it will no interrupt the data collection. Look at the <a href="http://zone.ni.com/devzone/cda/tut/p/id/3023" target="_blank">producer-consumer</a> architecture.
jmcbee
2008-08-14 19:10:07 UTC
Permalink
Hello Dan,&nbsp;You should look into a Producer Consumer architecture.&nbsp; You can find a template for how to set this up under File&gt;&gt;New&gt;&gt;VI&gt;&gt;From Template&gt;&gt;Frameworks&gt;&gt;Design Patterns&gt;&gt;Producer/Consumer...&nbsp;Feel free to ask any questions!
drfunkphd
2008-08-14 19:10:08 UTC
Permalink
I think the producer-consumer architecture may help.&nbsp; However, I will be taking pressure readings at a high rate (around 600hz).&nbsp; I need to also record some optical power readings via a serial port.&nbsp; But the serial port process takes around 3 seconds to write and read all of the data (I can't continously sample this data).&nbsp; So I'm looking for a way to constanly monitor and control the pressure, but retrieve the optical power after a certain interval (say 1 minute).&nbsp; The problem is anytime I use the event structure to sample the optical power, it makes the other loop wait until it is complete.&nbsp; I will definitely look into the producer-consumer topics.&nbsp; In the meantime, any other ideas?
GerdW
2008-08-14 20:10:10 UTC
Permalink
Hi DrPhunk,&nbsp;other ideas:- using a subvi for parts of code used more than once? See attachment...- cleaning up your logics for the boolean part in the upper right corner of the big loop? Look at my comments (from simple replacements to wel-known Rube-Goldberg!)&nbsp;For your problem:Put independent DAQ parts into seperate loops. Use consumer-producer pattern <a href="http://forums.ni.com/t5/util/emoticonspopuppage" class="emoticon-link" target="_blank"><img src="Loading Image..." border="0" alt=":smileywink:" title="Smiley Wink"></a>


beast.zip:
http://forums.ni.com/ni/attachments/ni/170/349436/1/beast.zip
GerdW
2008-08-15 06:10:07 UTC
Permalink
Hi DrFunk,&nbsp;forgot to say:after removing this huge sequence structure you can further mnimize the block diagram by putting all those Visa-R/W into a for loop using autoindexing over an array of device commands... Message Edited by GerdW on 08-15-2008 08:03 AM
drfunkphd
2008-08-15 18:40:04 UTC
Permalink
Thanks again guys.&nbsp; I'm going to try to implement all of the suggestions you mentioned.&nbsp; I'm sure I'll be checking back as I run into problems.
Continue reading on narkive:
Loading...